News features and improvements (#8)
* added config file implementation, refactoring * add gitignore * improved test * preperations for more metrics * added resource metrics * added first bgp metrics * added asn as label for bgp metrics * added prefix and message counts to bgp metrics * simplified * Update README.md * added yaml dependency * fixed go routine call * added timeout * clean up * added TLS support * set default api port for TLS * added routes metric * added missing log information
This commit is contained in:
committed by
Steve Brunton
parent
c37abb638f
commit
f2866a3a2f
1
vendor/github.com/prometheus/procfs/sysfs/.gitignore
generated
vendored
Normal file
1
vendor/github.com/prometheus/procfs/sysfs/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
fixtures/
|
||||
130
vendor/github.com/prometheus/procfs/sysfs/fixtures.ttar
generated
vendored
130
vendor/github.com/prometheus/procfs/sysfs/fixtures.ttar
generated
vendored
@@ -1,3 +1,4 @@
|
||||
# Archive created by ttar -c -f fixtures.ttar fixtures/
|
||||
Directory: fixtures
|
||||
Mode: 755
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -719,3 +720,132 @@ Lines: 1
|
||||
extent_alloc 2 0 0 0
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/class/net/eth0/
|
||||
Mode: 755
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/addr_assign_type
|
||||
Lines: 1
|
||||
3
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/addr_len
|
||||
Lines: 1
|
||||
6
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/address
|
||||
Lines: 1
|
||||
01:01:01:01:01:01
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/broadcast
|
||||
Lines: 1
|
||||
ff:ff:ff:ff:ff:ff
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/carrier
|
||||
Lines: 1
|
||||
1
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/carrier_changes
|
||||
Lines: 1
|
||||
2
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/carrier_down_count
|
||||
Lines: 1
|
||||
1
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/carrier_up_count
|
||||
Lines: 1
|
||||
1
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/dev_id
|
||||
Lines: 1
|
||||
0x20
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/dormant
|
||||
Lines: 1
|
||||
1
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/duplex
|
||||
Lines: 1
|
||||
full
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/flags
|
||||
Lines: 1
|
||||
0x1303
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/ifalias
|
||||
Lines: 0
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/ifindex
|
||||
Lines: 1
|
||||
2
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/iflink
|
||||
Lines: 1
|
||||
2
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/link_mode
|
||||
Lines: 1
|
||||
1
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/mtu
|
||||
Lines: 1
|
||||
1500
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/name_assign_type
|
||||
Lines: 1
|
||||
2
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/netdev_group
|
||||
Lines: 1
|
||||
0
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/operstate
|
||||
Lines: 1
|
||||
up
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/phys_port_id
|
||||
Lines: 0
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/phys_port_name
|
||||
Lines: 0
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/phys_switch_id
|
||||
Lines: 0
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/speed
|
||||
Lines: 1
|
||||
1000
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/tx_queue_len
|
||||
Lines: 1
|
||||
1000
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/class/net/eth0/type
|
||||
Lines: 1
|
||||
1
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
165
vendor/github.com/prometheus/procfs/sysfs/net_class.go
generated
vendored
Normal file
165
vendor/github.com/prometheus/procfs/sysfs/net_class.go
generated
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// NetClassIface contains info from files in /sys/class/net/<iface>
|
||||
// for single interface (iface).
|
||||
type NetClassIface struct {
|
||||
Name string // Interface name
|
||||
AddrAssignType int64 `fileName:"addr_assign_type"` // /sys/class/net/<iface>/addr_assign_type
|
||||
AddrLen int64 `fileName:"addr_len"` // /sys/class/net/<iface>/addr_len
|
||||
Address string `fileName:"address"` // /sys/class/net/<iface>/address
|
||||
Broadcast string `fileName:"broadcast"` // /sys/class/net/<iface>/broadcast
|
||||
Carrier int64 `fileName:"carrier"` // /sys/class/net/<iface>/carrier
|
||||
CarrierChanges int64 `fileName:"carrier_changes"` // /sys/class/net/<iface>/carrier_changes
|
||||
CarrierUpCount int64 `fileName:"carrier_up_count"` // /sys/class/net/<iface>/carrier_up_count
|
||||
CarrierDownCount int64 `fileName:"carrier_down_count"` // /sys/class/net/<iface>/carrier_down_count
|
||||
DevID int64 `fileName:"dev_id"` // /sys/class/net/<iface>/dev_id
|
||||
Dormant int64 `fileName:"dormant"` // /sys/class/net/<iface>/dormant
|
||||
Duplex string `fileName:"duplex"` // /sys/class/net/<iface>/duplex
|
||||
Flags int64 `fileName:"flags"` // /sys/class/net/<iface>/flags
|
||||
IfAlias string `fileName:"ifalias"` // /sys/class/net/<iface>/ifalias
|
||||
IfIndex int64 `fileName:"ifindex"` // /sys/class/net/<iface>/ifindex
|
||||
IfLink int64 `fileName:"iflink"` // /sys/class/net/<iface>/iflink
|
||||
LinkMode int64 `fileName:"link_mode"` // /sys/class/net/<iface>/link_mode
|
||||
MTU int64 `fileName:"mtu"` // /sys/class/net/<iface>/mtu
|
||||
NameAssignType int64 `fileName:"name_assign_type"` // /sys/class/net/<iface>/name_assign_type
|
||||
NetDevGroup int64 `fileName:"netdev_group"` // /sys/class/net/<iface>/netdev_group
|
||||
OperState string `fileName:"operstate"` // /sys/class/net/<iface>/operstate
|
||||
PhysPortID string `fileName:"phys_port_id"` // /sys/class/net/<iface>/phys_port_id
|
||||
PhysPortName string `fileName:"phys_port_name"` // /sys/class/net/<iface>/phys_port_name
|
||||
PhysSwitchID string `fileName:"phys_switch_id"` // /sys/class/net/<iface>/phys_switch_id
|
||||
Speed int64 `fileName:"speed"` // /sys/class/net/<iface>/speed
|
||||
TxQueueLen int64 `fileName:"tx_queue_len"` // /sys/class/net/<iface>/tx_queue_len
|
||||
Type int64 `fileName:"type"` // /sys/class/net/<iface>/type
|
||||
}
|
||||
|
||||
// NetClass is collection of info for every interface (iface) in /sys/class/net. The map keys
|
||||
// are interface (iface) names.
|
||||
type NetClass map[string]NetClassIface
|
||||
|
||||
// NewNetClass returns info for all net interfaces (iface) read from /sys/class/net/<iface>.
|
||||
func NewNetClass() (NetClass, error) {
|
||||
fs, err := NewFS(DefaultMountPoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fs.NewNetClass()
|
||||
}
|
||||
|
||||
// NewNetClass returns info for all net interfaces (iface) read from /sys/class/net/<iface>.
|
||||
func (fs FS) NewNetClass() (NetClass, error) {
|
||||
path := fs.Path("class/net")
|
||||
|
||||
devices, err := ioutil.ReadDir(path)
|
||||
if err != nil {
|
||||
return NetClass{}, fmt.Errorf("cannot access %s dir %s", path, err)
|
||||
}
|
||||
|
||||
netClass := NetClass{}
|
||||
for _, deviceDir := range devices {
|
||||
interfaceClass, err := netClass.parseNetClassIface(path + "/" + deviceDir.Name())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
interfaceClass.Name = deviceDir.Name()
|
||||
netClass[deviceDir.Name()] = *interfaceClass
|
||||
}
|
||||
return netClass, nil
|
||||
}
|
||||
|
||||
// parseNetClassIface scans predefined files in /sys/class/net/<iface>
|
||||
// directory and gets their contents.
|
||||
func (nc NetClass) parseNetClassIface(devicePath string) (*NetClassIface, error) {
|
||||
interfaceClass := NetClassIface{}
|
||||
interfaceElem := reflect.ValueOf(&interfaceClass).Elem()
|
||||
interfaceType := reflect.TypeOf(interfaceClass)
|
||||
|
||||
//start from 1 - skip the Name field
|
||||
for i := 1; i < interfaceElem.NumField(); i++ {
|
||||
fieldType := interfaceType.Field(i)
|
||||
fieldValue := interfaceElem.Field(i)
|
||||
|
||||
if fieldType.Tag.Get("fileName") == "" {
|
||||
panic(fmt.Errorf("field %s does not have a filename tag", fieldType.Name))
|
||||
}
|
||||
|
||||
fileContents, err := sysReadFile(devicePath + "/" + fieldType.Tag.Get("fileName"))
|
||||
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
|
||||
continue
|
||||
}
|
||||
return nil, fmt.Errorf("could not access file %s: %s", fieldType.Tag.Get("fileName"), err)
|
||||
}
|
||||
value := strings.TrimSpace(string(fileContents))
|
||||
|
||||
switch fieldValue.Kind() {
|
||||
case reflect.Int64:
|
||||
if strings.HasPrefix(value, "0x") {
|
||||
intValue, err := strconv.ParseInt(value[2:], 16, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expected hex value for %s, got: %s", fieldType.Name, value)
|
||||
}
|
||||
fieldValue.SetInt(intValue)
|
||||
} else {
|
||||
intValue, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expected Uint64 value for %s, got: %s", fieldType.Name, value)
|
||||
}
|
||||
fieldValue.SetInt(intValue)
|
||||
}
|
||||
case reflect.String:
|
||||
fieldValue.SetString(value)
|
||||
default:
|
||||
return nil, fmt.Errorf("unhandled type %q", fieldValue.Kind())
|
||||
}
|
||||
}
|
||||
|
||||
return &interfaceClass, nil
|
||||
}
|
||||
|
||||
// sysReadFile is a simplified ioutil.ReadFile that invokes syscall.Read directly.
|
||||
// https://github.com/prometheus/node_exporter/pull/728/files
|
||||
func sysReadFile(file string) ([]byte, error) {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// On some machines, hwmon drivers are broken and return EAGAIN. This causes
|
||||
// Go's ioutil.ReadFile implementation to poll forever.
|
||||
//
|
||||
// Since we either want to read data or bail immediately, do the simplest
|
||||
// possible read using syscall directly.
|
||||
b := make([]byte, 128)
|
||||
n, err := syscall.Read(int(f.Fd()), b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return b[:n], nil
|
||||
}
|
||||
67
vendor/github.com/prometheus/procfs/sysfs/net_class_test.go
generated
vendored
Normal file
67
vendor/github.com/prometheus/procfs/sysfs/net_class_test.go
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewNetClass(t *testing.T) {
|
||||
fs, err := NewFS("fixtures")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
nc, err := fs.NewNetClass()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
netClass := NetClass{
|
||||
"eth0": {
|
||||
Address: "01:01:01:01:01:01",
|
||||
AddrAssignType: 3,
|
||||
AddrLen: 6,
|
||||
Broadcast: "ff:ff:ff:ff:ff:ff",
|
||||
Carrier: 1,
|
||||
CarrierChanges: 2,
|
||||
CarrierDownCount: 1,
|
||||
CarrierUpCount: 1,
|
||||
DevID: 32,
|
||||
Dormant: 1,
|
||||
Duplex: "full",
|
||||
Flags: 4867,
|
||||
IfAlias: "",
|
||||
IfIndex: 2,
|
||||
IfLink: 2,
|
||||
LinkMode: 1,
|
||||
MTU: 1500,
|
||||
Name: "eth0",
|
||||
NameAssignType: 2,
|
||||
NetDevGroup: 0,
|
||||
OperState: "up",
|
||||
PhysPortID: "",
|
||||
PhysPortName: "",
|
||||
PhysSwitchID: "",
|
||||
Speed: 1000,
|
||||
TxQueueLen: 1000,
|
||||
Type: 1,
|
||||
},
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(netClass, nc) {
|
||||
t.Errorf("Result not correct: want %v, have %v", netClass, nc)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user