Skip to content

Commit

Permalink
Adds ifAlias label to all exported metrics. (#16)
Browse files Browse the repository at this point in the history
* Adds ifAlias label to all exported metrics.
  • Loading branch information
nkinkade authored Sep 21, 2020
1 parent 3286a68 commit f538650
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type oid struct {
name string
previousValue uint64
scope string
ifAlias string
ifDescr string
interval archive.Model
}
Expand All @@ -54,10 +55,12 @@ func mustGetIfaces(client snmp.Client, machine string) map[string]map[string]str
ifaces := map[string]map[string]string{
"machine": map[string]string{
"iface": "",
"ifAlias": "",
"ifDescr": "",
},
"uplink": map[string]string{
"iface": "",
"ifAlias": "",
"ifDescr": "",
},
}
Expand All @@ -71,13 +74,15 @@ func mustGetIfaces(client snmp.Client, machine string) map[string]map[string]str
ifDescrOid := createOID(ifDescrOidStub, iface)
oidMap, err := getOidsString(client, []string{ifDescrOid})
rtx.Must(err, "Failed to determine the machine interface ifDescr")
ifaces["machine"]["ifAlias"] = machine
ifaces["machine"]["ifDescr"] = oidMap[ifDescrOid]
ifaces["machine"]["iface"] = iface
}
if strings.HasPrefix(val, "uplink") {
ifDescrOid := createOID(ifDescrOidStub, iface)
oidMap, err := getOidsString(client, []string{ifDescrOid})
rtx.Must(err, "Failed to determine the uplink interface ifDescr")
ifaces["uplink"]["ifAlias"] = "uplink"
ifaces["uplink"]["ifDescr"] = oidMap[ifDescrOid]
ifaces["uplink"]["iface"] = iface
}
Expand Down Expand Up @@ -181,9 +186,10 @@ func (metrics *Metrics) Collect(client snmp.Client, config config.Config) error
}

increase := value - metrics.oids[oid].previousValue
ifAlias := metrics.oids[oid].ifAlias
ifDescr := metrics.oids[oid].ifDescr
metricName := metrics.oids[oid].name
metrics.prom[metricName].WithLabelValues(ifDescr).Add(float64(increase))
metrics.prom[metricName].WithLabelValues(ifAlias, ifDescr).Add(float64(increase))

metrics.oids[oid].interval.Samples = append(
metrics.oids[oid].interval.Samples,
Expand Down Expand Up @@ -294,6 +300,7 @@ func New(client snmp.Client, config config.Config, target string, hostname strin
o := &oid{
name: metric.Name,
scope: scope,
ifAlias: values["ifAlias"],
ifDescr: values["ifDescr"],
interval: archive.Model{
Experiment: target,
Expand All @@ -310,6 +317,7 @@ func New(client snmp.Client, config config.Config, target string, hostname strin
Help: metric.Description,
},
[]string{
"ifAlias",
"interface",
},
)
Expand Down
4 changes: 4 additions & 0 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func Test_New(t *testing.T) {
name: "ifOutDiscards",
previousValue: 0,
scope: "machine",
ifAlias: "mlab2",
ifDescr: "xe-0/0/12",
interval: archive.Model{
Experiment: "s1-abc0t.measurement-lab.org",
Expand All @@ -212,6 +213,7 @@ func Test_New(t *testing.T) {
name: "ifOutDiscards",
previousValue: 0,
scope: "uplink",
ifAlias: "uplink",
ifDescr: "xe-0/0/45",
interval: archive.Model{
Experiment: "s1-abc0t.measurement-lab.org",
Expand All @@ -224,6 +226,7 @@ func Test_New(t *testing.T) {
name: "ifHCInOctets",
previousValue: 0,
scope: "machine",
ifAlias: "mlab2",
ifDescr: "xe-0/0/12",
interval: archive.Model{
Experiment: "s1-abc0t.measurement-lab.org",
Expand All @@ -236,6 +239,7 @@ func Test_New(t *testing.T) {
name: "ifHCInOctets",
previousValue: 0,
scope: "uplink",
ifAlias: "uplink",
ifDescr: "xe-0/0/45",
interval: archive.Model{
Experiment: "s1-abc0t.measurement-lab.org",
Expand Down

0 comments on commit f538650

Please sign in to comment.