Skip to content

Commit

Permalink
Merge commit 'b237d44' (nshttpd#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinhard Tartler committed Oct 15, 2023
2 parents aa7c013 + b237d44 commit db941d7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions collector/netwatch_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func newNetwatchCollector() routerOSCollector {
}

func (c *netwatchCollector) init() {
c.props = []string{"host", "comment", "status"}
labelNames := []string{"name", "address", "host", "comment"}
c.props = []string{"host", "comment", "disabled", "status"}
labelNames := []string{"name", "address", "host", "comment", "disabled"}
c.descriptions = make(map[string]*prometheus.Desc)
for _, p := range c.props[1:] {
for _, p := range c.props[3:] {
c.descriptions[p] = descriptionForPropertyName("netwatch", p, labelNames)
}
}
Expand All @@ -49,7 +49,7 @@ func (c *netwatchCollector) collect(ctx *collectorContext) error {
}

func (c *netwatchCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error) {
reply, err := ctx.client.Run("/tool/netwatch/print", "?disabled=false", "=.proplist="+strings.Join(c.props, ","))
reply, err := ctx.client.Run("/tool/netwatch/print", "=.proplist="+strings.Join(c.props, ","))
if err != nil {
log.WithFields(log.Fields{
"device": ctx.device.Name,
Expand All @@ -64,13 +64,14 @@ func (c *netwatchCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, err
func (c *netwatchCollector) collectForStat(re *proto.Sentence, ctx *collectorContext) {
host := re.Map["host"]
comment := re.Map["comment"]
disabled := re.Map["disabled"]

for _, p := range c.props[2:] {
c.collectMetricForProperty(p, host, comment, re, ctx)
for _, p := range c.props[3:] {
c.collectMetricForProperty(p, host, comment, disabled, re, ctx)
}
}

func (c *netwatchCollector) collectMetricForProperty(property, host, comment string, re *proto.Sentence, ctx *collectorContext) {
func (c *netwatchCollector) collectMetricForProperty(property, host, comment, disabled string, re *proto.Sentence, ctx *collectorContext) {
desc := c.descriptions[property]
if value := re.Map[property]; value != "" {
var numericValue float64
Expand All @@ -90,6 +91,6 @@ func (c *netwatchCollector) collectMetricForProperty(property, host, comment str
"error": fmt.Errorf("unexpected netwatch status value"),
}).Error("error parsing netwatch metric value")
}
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, numericValue, ctx.device.Name, ctx.device.Address, host, comment)
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, numericValue, ctx.device.Name, ctx.device.Address, host, comment, disabled)
}
}

0 comments on commit db941d7

Please sign in to comment.