diff options
author | Jan Klat <jenik@klatys.cz> | 2018-07-16 15:08:18 +0200 |
---|---|---|
committer | Johannes 'fish' Ziemke <github@freigeist.org> | 2018-07-16 15:08:18 +0200 |
commit | c4102f117584f92e18e9612d9a9eecd0815e89bd (patch) | |
tree | 06e8fbb27352e471bfece0c5a7e9543745f2c3cb /vendor | |
parent | 09b4305090a6af1e69c528539fba63fc5ff781c6 (diff) | |
download | prometheus_node_collector-c4102f117584f92e18e9612d9a9eecd0815e89bd.tar.bz2 prometheus_node_collector-c4102f117584f92e18e9612d9a9eecd0815e89bd.tar.xz prometheus_node_collector-c4102f117584f92e18e9612d9a9eecd0815e89bd.zip |
Add sys/class/net parsing from procfs and expose its metrics (#851)
* add sys/class/net parsing from procfs and expose its metrics
Signed-off-by: Jan Klat <jenik@klatys.cz>
* change code to use int pointers per procfs change, move netclass to separate collector, change metric naming
Signed-off-by: Jan Klat <jenik@klatys.cz>
* bump year in licence, remove redundant newline, correct fixtures
Signed-off-by: Jan Klat <jenik@klatys.cz>
* fix style
Signed-off-by: Jan Klat <jenik@klatys.cz>
* change carrier changes to counter type
Signed-off-by: Jan Klat <jenik@klatys.cz>
* fix e2e output
Signed-off-by: Jan Klat <jenik@klatys.cz>
* add fixtures
Signed-off-by: Jan Klat <jenik@klatys.cz>
* update vendor, use fixtures correctly
Signed-off-by: Jan Klat <jenik@klatys.cz>
* change fixtures (device in /sys/class/net should be symlinked)
Signed-off-by: Jan Klat <jenik@klatys.cz>
* correct fixtures for 64k page, updated readme
Signed-off-by: Jan Klat <jenik@klatys.cz>
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/prometheus/procfs/net_dev.go | 2 | ||||
-rw-r--r-- | vendor/github.com/prometheus/procfs/sysfs/net_class.go | 73 | ||||
-rw-r--r-- | vendor/vendor.json | 6 |
3 files changed, 45 insertions, 36 deletions
diff --git a/vendor/github.com/prometheus/procfs/net_dev.go b/vendor/github.com/prometheus/procfs/net_dev.go index 6c17aff..3f25233 100644 --- a/vendor/github.com/prometheus/procfs/net_dev.go +++ b/vendor/github.com/prometheus/procfs/net_dev.go | |||
@@ -184,7 +184,7 @@ func (nd NetDev) parseLine(rawLine string) (*NetDevLine, error) { | |||
184 | } | 184 | } |
185 | 185 | ||
186 | // Total aggregates the values across interfaces and returns a new NetDevLine. | 186 | // Total aggregates the values across interfaces and returns a new NetDevLine. |
187 | // The Name field will be a sorted comma seperated list of interface names. | 187 | // The Name field will be a sorted comma separated list of interface names. |
188 | func (nd NetDev) Total() NetDevLine { | 188 | func (nd NetDev) Total() NetDevLine { |
189 | total := NetDevLine{} | 189 | total := NetDevLine{} |
190 | 190 | ||
diff --git a/vendor/github.com/prometheus/procfs/sysfs/net_class.go b/vendor/github.com/prometheus/procfs/sysfs/net_class.go index 46affd7..562ce15 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/net_class.go +++ b/vendor/github.com/prometheus/procfs/sysfs/net_class.go | |||
@@ -27,32 +27,32 @@ import ( | |||
27 | // for single interface (iface). | 27 | // for single interface (iface). |
28 | type NetClassIface struct { | 28 | type NetClassIface struct { |
29 | Name string // Interface name | 29 | Name string // Interface name |
30 | AddrAssignType int64 `fileName:"addr_assign_type"` // /sys/class/net/<iface>/addr_assign_type | 30 | AddrAssignType *int64 `fileName:"addr_assign_type"` // /sys/class/net/<iface>/addr_assign_type |
31 | AddrLen int64 `fileName:"addr_len"` // /sys/class/net/<iface>/addr_len | 31 | AddrLen *int64 `fileName:"addr_len"` // /sys/class/net/<iface>/addr_len |
32 | Address string `fileName:"address"` // /sys/class/net/<iface>/address | 32 | Address string `fileName:"address"` // /sys/class/net/<iface>/address |
33 | Broadcast string `fileName:"broadcast"` // /sys/class/net/<iface>/broadcast | 33 | Broadcast string `fileName:"broadcast"` // /sys/class/net/<iface>/broadcast |
34 | Carrier int64 `fileName:"carrier"` // /sys/class/net/<iface>/carrier | 34 | Carrier *int64 `fileName:"carrier"` // /sys/class/net/<iface>/carrier |
35 | CarrierChanges int64 `fileName:"carrier_changes"` // /sys/class/net/<iface>/carrier_changes | 35 | CarrierChanges *int64 `fileName:"carrier_changes"` // /sys/class/net/<iface>/carrier_changes |
36 | CarrierUpCount int64 `fileName:"carrier_up_count"` // /sys/class/net/<iface>/carrier_up_count | 36 | CarrierUpCount *int64 `fileName:"carrier_up_count"` // /sys/class/net/<iface>/carrier_up_count |
37 | CarrierDownCount int64 `fileName:"carrier_down_count"` // /sys/class/net/<iface>/carrier_down_count | 37 | CarrierDownCount *int64 `fileName:"carrier_down_count"` // /sys/class/net/<iface>/carrier_down_count |
38 | DevID int64 `fileName:"dev_id"` // /sys/class/net/<iface>/dev_id | 38 | DevID *int64 `fileName:"dev_id"` // /sys/class/net/<iface>/dev_id |
39 | Dormant int64 `fileName:"dormant"` // /sys/class/net/<iface>/dormant | 39 | Dormant *int64 `fileName:"dormant"` // /sys/class/net/<iface>/dormant |
40 | Duplex string `fileName:"duplex"` // /sys/class/net/<iface>/duplex | 40 | Duplex string `fileName:"duplex"` // /sys/class/net/<iface>/duplex |
41 | Flags int64 `fileName:"flags"` // /sys/class/net/<iface>/flags | 41 | Flags *int64 `fileName:"flags"` // /sys/class/net/<iface>/flags |
42 | IfAlias string `fileName:"ifalias"` // /sys/class/net/<iface>/ifalias | 42 | IfAlias string `fileName:"ifalias"` // /sys/class/net/<iface>/ifalias |
43 | IfIndex int64 `fileName:"ifindex"` // /sys/class/net/<iface>/ifindex | 43 | IfIndex *int64 `fileName:"ifindex"` // /sys/class/net/<iface>/ifindex |
44 | IfLink int64 `fileName:"iflink"` // /sys/class/net/<iface>/iflink | 44 | IfLink *int64 `fileName:"iflink"` // /sys/class/net/<iface>/iflink |
45 | LinkMode int64 `fileName:"link_mode"` // /sys/class/net/<iface>/link_mode | 45 | LinkMode *int64 `fileName:"link_mode"` // /sys/class/net/<iface>/link_mode |
46 | MTU int64 `fileName:"mtu"` // /sys/class/net/<iface>/mtu | 46 | MTU *int64 `fileName:"mtu"` // /sys/class/net/<iface>/mtu |
47 | NameAssignType int64 `fileName:"name_assign_type"` // /sys/class/net/<iface>/name_assign_type | 47 | NameAssignType *int64 `fileName:"name_assign_type"` // /sys/class/net/<iface>/name_assign_type |
48 | NetDevGroup int64 `fileName:"netdev_group"` // /sys/class/net/<iface>/netdev_group | 48 | NetDevGroup *int64 `fileName:"netdev_group"` // /sys/class/net/<iface>/netdev_group |
49 | OperState string `fileName:"operstate"` // /sys/class/net/<iface>/operstate | 49 | OperState string `fileName:"operstate"` // /sys/class/net/<iface>/operstate |
50 | PhysPortID string `fileName:"phys_port_id"` // /sys/class/net/<iface>/phys_port_id | 50 | PhysPortID string `fileName:"phys_port_id"` // /sys/class/net/<iface>/phys_port_id |
51 | PhysPortName string `fileName:"phys_port_name"` // /sys/class/net/<iface>/phys_port_name | 51 | PhysPortName string `fileName:"phys_port_name"` // /sys/class/net/<iface>/phys_port_name |
52 | PhysSwitchID string `fileName:"phys_switch_id"` // /sys/class/net/<iface>/phys_switch_id | 52 | PhysSwitchID string `fileName:"phys_switch_id"` // /sys/class/net/<iface>/phys_switch_id |
53 | Speed int64 `fileName:"speed"` // /sys/class/net/<iface>/speed | 53 | Speed *int64 `fileName:"speed"` // /sys/class/net/<iface>/speed |
54 | TxQueueLen int64 `fileName:"tx_queue_len"` // /sys/class/net/<iface>/tx_queue_len | 54 | TxQueueLen *int64 `fileName:"tx_queue_len"` // /sys/class/net/<iface>/tx_queue_len |
55 | Type int64 `fileName:"type"` // /sys/class/net/<iface>/type | 55 | Type *int64 `fileName:"type"` // /sys/class/net/<iface>/type |
56 | } | 56 | } |
57 | 57 | ||
58 | // NetClass is collection of info for every interface (iface) in /sys/class/net. The map keys | 58 | // NetClass is collection of info for every interface (iface) in /sys/class/net. The map keys |
@@ -80,6 +80,9 @@ func (fs FS) NewNetClass() (NetClass, error) { | |||
80 | 80 | ||
81 | netClass := NetClass{} | 81 | netClass := NetClass{} |
82 | for _, deviceDir := range devices { | 82 | for _, deviceDir := range devices { |
83 | if deviceDir.Mode().IsRegular() { | ||
84 | continue | ||
85 | } | ||
83 | interfaceClass, err := netClass.parseNetClassIface(path + "/" + deviceDir.Name()) | 86 | interfaceClass, err := netClass.parseNetClassIface(path + "/" + deviceDir.Name()) |
84 | if err != nil { | 87 | if err != nil { |
85 | return nil, err | 88 | return nil, err |
@@ -117,22 +120,28 @@ func (nc NetClass) parseNetClassIface(devicePath string) (*NetClassIface, error) | |||
117 | value := strings.TrimSpace(string(fileContents)) | 120 | value := strings.TrimSpace(string(fileContents)) |
118 | 121 | ||
119 | switch fieldValue.Kind() { | 122 | switch fieldValue.Kind() { |
120 | case reflect.Int64: | ||
121 | if strings.HasPrefix(value, "0x") { | ||
122 | intValue, err := strconv.ParseInt(value[2:], 16, 64) | ||
123 | if err != nil { | ||
124 | return nil, fmt.Errorf("expected hex value for %s, got: %s", fieldType.Name, value) | ||
125 | } | ||
126 | fieldValue.SetInt(intValue) | ||
127 | } else { | ||
128 | intValue, err := strconv.ParseInt(value, 10, 64) | ||
129 | if err != nil { | ||
130 | return nil, fmt.Errorf("expected Uint64 value for %s, got: %s", fieldType.Name, value) | ||
131 | } | ||
132 | fieldValue.SetInt(intValue) | ||
133 | } | ||
134 | case reflect.String: | 123 | case reflect.String: |
135 | fieldValue.SetString(value) | 124 | fieldValue.SetString(value) |
125 | case reflect.Ptr: | ||
126 | var int64ptr *int64 | ||
127 | switch fieldValue.Type() { | ||
128 | case reflect.TypeOf(int64ptr): | ||
129 | var intValue int64 | ||
130 | if strings.HasPrefix(value, "0x") { | ||
131 | intValue, err = strconv.ParseInt(value[2:], 16, 64) | ||
132 | if err != nil { | ||
133 | return nil, fmt.Errorf("expected hex value for %s, got: %s", fieldType.Name, value) | ||
134 | } | ||
135 | } else { | ||
136 | intValue, err = strconv.ParseInt(value, 10, 64) | ||
137 | if err != nil { | ||
138 | return nil, fmt.Errorf("expected Uint64 value for %s, got: %s", fieldType.Name, value) | ||
139 | } | ||
140 | } | ||
141 | fieldValue.Set(reflect.ValueOf(&intValue)) | ||
142 | default: | ||
143 | return nil, fmt.Errorf("unhandled pointer type %q", fieldValue.Type()) | ||
144 | } | ||
136 | default: | 145 | default: |
137 | return nil, fmt.Errorf("unhandled type %q", fieldValue.Kind()) | 146 | return nil, fmt.Errorf("unhandled type %q", fieldValue.Kind()) |
138 | } | 147 | } |
diff --git a/vendor/vendor.json b/vendor/vendor.json index 242f5c4..983a378 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json | |||
@@ -163,10 +163,10 @@ | |||
163 | "revisionTime": "2018-03-26T16:04:09Z" | 163 | "revisionTime": "2018-03-26T16:04:09Z" |
164 | }, | 164 | }, |
165 | { | 165 | { |
166 | "checksumSHA1": "Etvt6mgzvD7ARf4Ux03LHfgSlzU=", | 166 | "checksumSHA1": "qG0ClCTt2wuQnYLsFvtlQB8J5FQ=", |
167 | "path": "github.com/prometheus/procfs", | 167 | "path": "github.com/prometheus/procfs", |
168 | "revision": "780932d4fbbe0e69b84c34c20f5c8d0981e109ea", | 168 | "revision": "add1f1c0b8971a8cdb88ab8bb152878e5074780b", |
169 | "revisionTime": "2018-03-21T23:08:12Z" | 169 | "revisionTime": "2018-05-31T12:13:16Z" |
170 | }, | 170 | }, |
171 | { | 171 | { |
172 | "checksumSHA1": "O64FotgWPYIpl3m2gvTEPIem+xg=", | 172 | "checksumSHA1": "O64FotgWPYIpl3m2gvTEPIem+xg=", |