prometheusmetricshost-metricsmachine-metricsnode-metricsprocfsprometheus-exportersystem-informationsystem-metrics
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.4 KiB
77 lines
2.4 KiB
9 years ago
|
// Copyright 2015 The Prometheus Authors
|
||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License.
|
||
|
// You may obtain a copy of the License at
|
||
|
//
|
||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
|
||
10 years ago
|
// +build !nonetdev
|
||
8 years ago
|
// +build freebsd dragonfly
|
||
10 years ago
|
|
||
|
package collector
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
9 years ago
|
"regexp"
|
||
9 years ago
|
"strconv"
|
||
10 years ago
|
|
||
9 years ago
|
"github.com/prometheus/common/log"
|
||
10 years ago
|
)
|
||
|
|
||
|
/*
|
||
10 years ago
|
#cgo CFLAGS: -D_IFI_OQDROPS
|
||
10 years ago
|
#include <stdio.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <ifaddrs.h>
|
||
|
#include <net/if.h>
|
||
|
*/
|
||
|
import "C"
|
||
|
|
||
9 years ago
|
func getNetDevStats(ignore *regexp.Regexp) (map[string]map[string]string, error) {
|
||
9 years ago
|
netDev := map[string]map[string]string{}
|
||
10 years ago
|
|
||
|
var ifap, ifa *C.struct_ifaddrs
|
||
|
if C.getifaddrs(&ifap) == -1 {
|
||
9 years ago
|
return nil, errors.New("getifaddrs() failed")
|
||
10 years ago
|
}
|
||
10 years ago
|
defer C.freeifaddrs(ifap)
|
||
|
|
||
10 years ago
|
for ifa = ifap; ifa != nil; ifa = ifa.ifa_next {
|
||
|
if ifa.ifa_addr.sa_family == C.AF_LINK {
|
||
9 years ago
|
dev := C.GoString(ifa.ifa_name)
|
||
|
if ignore.MatchString(dev) {
|
||
|
log.Debugf("Ignoring device: %s", dev)
|
||
|
continue
|
||
|
}
|
||
|
|
||
9 years ago
|
devStats := map[string]string{}
|
||
10 years ago
|
data := (*C.struct_if_data)(ifa.ifa_data)
|
||
|
|
||
9 years ago
|
devStats["receive_packets"] = convertFreeBSDCPUTime(uint64(data.ifi_ipackets))
|
||
|
devStats["transmit_packets"] = convertFreeBSDCPUTime(uint64(data.ifi_opackets))
|
||
|
devStats["receive_errs"] = convertFreeBSDCPUTime(uint64(data.ifi_ierrors))
|
||
|
devStats["transmit_errs"] = convertFreeBSDCPUTime(uint64(data.ifi_oerrors))
|
||
|
devStats["receive_bytes"] = convertFreeBSDCPUTime(uint64(data.ifi_ibytes))
|
||
|
devStats["transmit_bytes"] = convertFreeBSDCPUTime(uint64(data.ifi_obytes))
|
||
|
devStats["receive_multicast"] = convertFreeBSDCPUTime(uint64(data.ifi_imcasts))
|
||
|
devStats["transmit_multicast"] = convertFreeBSDCPUTime(uint64(data.ifi_omcasts))
|
||
|
devStats["receive_drop"] = convertFreeBSDCPUTime(uint64(data.ifi_iqdrops))
|
||
|
devStats["transmit_drop"] = convertFreeBSDCPUTime(uint64(data.ifi_oqdrops))
|
||
9 years ago
|
netDev[dev] = devStats
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
return netDev, nil
|
||
|
}
|
||
9 years ago
|
|
||
|
func convertFreeBSDCPUTime(counter uint64) string {
|
||
|
return strconv.FormatUint(counter, 10)
|
||
|
}
|