mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2024-11-18 10:45:12 +01:00
Merge pull request #125 from debugloop/master
fix #117 by distinquishing prometheus value types
This commit is contained in:
commit
5d7c795597
@ -71,16 +71,23 @@ func (c *interfaceCollector) collectMetricForProperty(property string, re *proto
|
||||
desc := c.descriptions[property]
|
||||
if value := re.Map[property]; value != "" {
|
||||
var (
|
||||
v float64
|
||||
err error
|
||||
v float64
|
||||
vtype prometheus.ValueType
|
||||
err error
|
||||
)
|
||||
vtype = prometheus.CounterValue
|
||||
|
||||
switch property {
|
||||
case "running":
|
||||
vtype = prometheus.GaugeValue
|
||||
if value == "true" {
|
||||
v = 1
|
||||
} else {
|
||||
v = 0
|
||||
}
|
||||
case "actual-mtu":
|
||||
vtype = prometheus.GaugeValue
|
||||
fallthrough
|
||||
default:
|
||||
v, err = strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
@ -94,7 +101,8 @@ func (c *interfaceCollector) collectMetricForProperty(property string, re *proto
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address,
|
||||
ctx.ch <- prometheus.MustNewConstMetric(desc, vtype, v, ctx.device.Name, ctx.device.Address,
|
||||
re.Map["name"], re.Map["type"], re.Map["disabled"], re.Map["comment"], re.Map["running"], re.Map["slave"])
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ func (c *resourceCollector) collectForStat(re *proto.Sentence, ctx *collectorCon
|
||||
|
||||
func (c *resourceCollector) collectMetricForProperty(property string, re *proto.Sentence, ctx *collectorContext) {
|
||||
var v float64
|
||||
var vtype prometheus.ValueType
|
||||
var err error
|
||||
// const boardname = "BOARD"
|
||||
// const version = "3.33.3"
|
||||
@ -90,11 +91,13 @@ func (c *resourceCollector) collectMetricForProperty(property string, re *proto.
|
||||
|
||||
if property == "uptime" {
|
||||
v, err = parseUptime(re.Map[property])
|
||||
vtype = prometheus.CounterValue
|
||||
} else {
|
||||
if re.Map[property] == "" {
|
||||
return
|
||||
}
|
||||
v, err = strconv.ParseFloat(re.Map[property], 64)
|
||||
vtype = prometheus.GaugeValue
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -108,7 +111,7 @@ func (c *resourceCollector) collectMetricForProperty(property string, re *proto.
|
||||
}
|
||||
|
||||
desc := c.descriptions[property]
|
||||
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address, boardname, version)
|
||||
ctx.ch <- prometheus.MustNewConstMetric(desc, vtype, v, ctx.device.Name, ctx.device.Address, boardname, version)
|
||||
}
|
||||
|
||||
func parseUptime(uptime string) (float64, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user