diff options
author | Nick Owens <mischief@offblast.org> | 2015-11-02 20:31:34 -0800 |
---|---|---|
committer | Nick Owens <mischief@offblast.org> | 2015-11-06 15:29:57 -0800 |
commit | 3eb2d6625ae6fb795816645e9e925311085772c2 (patch) | |
tree | caa423346a30fbd64d6e5968a7f41c1c91dc8922 /collector/netdev_openbsd.go | |
parent | 0a0babf3bea4c7dad860f7dc2433288b65eba7ff (diff) | |
download | prometheus_node_collector-3eb2d6625ae6fb795816645e9e925311085772c2.tar.bz2 prometheus_node_collector-3eb2d6625ae6fb795816645e9e925311085772c2.tar.xz prometheus_node_collector-3eb2d6625ae6fb795816645e9e925311085772c2.zip |
collector: add openbsd support for netdev
Diffstat (limited to 'collector/netdev_openbsd.go')
-rw-r--r-- | collector/netdev_openbsd.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/collector/netdev_openbsd.go b/collector/netdev_openbsd.go new file mode 100644 index 0000000..dc2f36f --- /dev/null +++ b/collector/netdev_openbsd.go | |||
@@ -0,0 +1,68 @@ | |||
1 | // Copyright 2015 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | // +build !nonetdev | ||
15 | |||
16 | package collector | ||
17 | |||
18 | import ( | ||
19 | "errors" | ||
20 | "strconv" | ||
21 | "regexp" | ||
22 | |||
23 | "github.com/prometheus/common/log" | ||
24 | ) | ||
25 | |||
26 | /* | ||
27 | #include <sys/types.h> | ||
28 | #include <sys/socket.h> | ||
29 | #include <ifaddrs.h> | ||
30 | #include <net/if.h> | ||
31 | */ | ||
32 | import "C" | ||
33 | |||
34 | func getNetDevStats(ignore *regexp.Regexp) (map[string]map[string]string, error) { | ||
35 | netDev := map[string]map[string]string{} | ||
36 | |||
37 | var ifap, ifa *C.struct_ifaddrs | ||
38 | if C.getifaddrs(&ifap) == -1 { | ||
39 | return nil, errors.New("getifaddrs() failed") | ||
40 | } | ||
41 | defer C.freeifaddrs(ifap) | ||
42 | |||
43 | for ifa = ifap; ifa != nil; ifa = ifa.ifa_next { | ||
44 | if ifa.ifa_addr.sa_family == C.AF_LINK { | ||
45 | dev := C.GoString(ifa.ifa_name) | ||
46 | if ignore.MatchString(dev) { | ||
47 | log.Debugf("Ignoring device: %s", dev) | ||
48 | continue | ||
49 | } | ||
50 | |||
51 | devStats := map[string]string{} | ||
52 | data := (*C.struct_if_data)(ifa.ifa_data) | ||
53 | |||
54 | devStats["receive_packets"] = strconv.Itoa(int(data.ifi_ipackets)) | ||
55 | devStats["transmit_packets"] = strconv.Itoa(int(data.ifi_opackets)) | ||
56 | devStats["receive_errs"] = strconv.Itoa(int(data.ifi_ierrors)) | ||
57 | devStats["transmit_errs"] = strconv.Itoa(int(data.ifi_oerrors)) | ||
58 | devStats["receive_bytes"] = strconv.Itoa(int(data.ifi_ibytes)) | ||
59 | devStats["transmit_bytes"] = strconv.Itoa(int(data.ifi_obytes)) | ||
60 | devStats["receive_multicast"] = strconv.Itoa(int(data.ifi_imcasts)) | ||
61 | devStats["transmit_multicast"] = strconv.Itoa(int(data.ifi_omcasts)) | ||
62 | devStats["receive_drop"] = strconv.Itoa(int(data.ifi_iqdrops)) | ||
63 | netDev[dev] = devStats | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return netDev, nil | ||
68 | } | ||