mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2025-02-08 23:41:20 +01:00
added running metric
This commit is contained in:
parent
525b8fc5f4
commit
05aaa41587
@ -21,11 +21,11 @@ func newInterfaceCollector() routerOSCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *interfaceCollector) init() {
|
func (c *interfaceCollector) init() {
|
||||||
c.props = []string{"name", "type", "disabled", "running", "comment", "rx-byte", "tx-byte", "rx-packet", "tx-packet", "rx-error", "tx-error", "rx-drop", "tx-drop"}
|
c.props = []string{"name", "type", "disabled", "comment", "running", "rx-byte", "tx-byte", "rx-packet", "tx-packet", "rx-error", "tx-error", "rx-drop", "tx-drop"}
|
||||||
|
|
||||||
labelNames := []string{"name", "address", "interface", "type", "disabled", "running", "comment"}
|
labelNames := []string{"name", "address", "interface", "type", "disabled", "comment", "running"}
|
||||||
c.descriptions = make(map[string]*prometheus.Desc)
|
c.descriptions = make(map[string]*prometheus.Desc)
|
||||||
for _, p := range c.props[5:] {
|
for _, p := range c.props[4:] {
|
||||||
c.descriptions[p] = descriptionForPropertyName("interface", p, labelNames)
|
c.descriptions[p] = descriptionForPropertyName("interface", p, labelNames)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func (c *interfaceCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *interfaceCollector) collectForStat(re *proto.Sentence, ctx *collectorContext) {
|
func (c *interfaceCollector) collectForStat(re *proto.Sentence, ctx *collectorContext) {
|
||||||
for _, p := range c.props[5:] {
|
for _, p := range c.props[4:] {
|
||||||
c.collectMetricForProperty(p, re, ctx)
|
c.collectMetricForProperty(p, re, ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,16 +71,27 @@ func (c *interfaceCollector) collectForStat(re *proto.Sentence, ctx *collectorCo
|
|||||||
func (c *interfaceCollector) collectMetricForProperty(property string, re *proto.Sentence, ctx *collectorContext) {
|
func (c *interfaceCollector) collectMetricForProperty(property string, re *proto.Sentence, ctx *collectorContext) {
|
||||||
desc := c.descriptions[property]
|
desc := c.descriptions[property]
|
||||||
if value := re.Map[property]; value != "" {
|
if value := re.Map[property]; value != "" {
|
||||||
v, err := strconv.ParseFloat(value, 64)
|
var v float64
|
||||||
if err != nil {
|
var err error
|
||||||
log.WithFields(log.Fields{
|
switch property {
|
||||||
"device": ctx.device.Name,
|
case "running":
|
||||||
"interface": re.Map["name"],
|
if value == "true" {
|
||||||
"property": property,
|
v = 1
|
||||||
"value": value,
|
} else {
|
||||||
"error": err,
|
v = 0
|
||||||
}).Error("error parsing interface metric value")
|
}
|
||||||
return
|
default:
|
||||||
|
v, err = strconv.ParseFloat(value, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"device": ctx.device.Name,
|
||||||
|
"interface": re.Map["name"],
|
||||||
|
"property": property,
|
||||||
|
"value": value,
|
||||||
|
"error": err,
|
||||||
|
}).Error("error parsing interface metric value")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address, re.Map["name"], re.Map["type"], re.Map["disabled"], re.Map["running"], re.Map["comment"])
|
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address, re.Map["name"], re.Map["type"], re.Map["disabled"], re.Map["running"], re.Map["comment"])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user