Skip to content

Commit

Permalink
Fix a bug with removeCommas() function (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
peimanja authored Feb 10, 2020
1 parent ae5c73a commit 0786822
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions collector/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (e *Exporter) removeCommas(str string) (float64, error) {
if err != nil {
return 0, err
}
convertedStr, err := strconv.ParseFloat(reg.ReplaceAllString(str, ""), 64)
strArray := strings.Fields(str)
convertedStr, err := strconv.ParseFloat(reg.ReplaceAllString(strArray[0], ""), 64)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -128,7 +129,12 @@ func (e *Exporter) exportCount(metricName string, metric *prometheus.Desc, count
e.jsonParseFailures.Inc()
return
}
value, _ := e.removeCommas(count)
value, err := e.removeCommas(count)
if err != nil {
e.jsonParseFailures.Inc()
level.Debug(e.logger).Log("msg", "There was an issue calculating the value", "metric", metricName, "err", err)
return
}
level.Debug(e.logger).Log("msg", "Registering metric", "metric", metricName, "value", value)
ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, value)
}
Expand All @@ -138,7 +144,12 @@ func (e *Exporter) exportSize(metricName string, metric *prometheus.Desc, size s
e.jsonParseFailures.Inc()
return
}
value, _ := e.bytesConverter(size)
value, err := e.bytesConverter(size)
if err != nil {
e.jsonParseFailures.Inc()
level.Debug(e.logger).Log("msg", "There was an issue calculating the value", "metric", metricName, "err", err)
return
}
level.Debug(e.logger).Log("msg", "Registering metric", "metric", metricName, "value", value)
ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, value)
}
Expand All @@ -148,7 +159,12 @@ func (e *Exporter) exportFilestore(metricName string, metric *prometheus.Desc, s
e.jsonParseFailures.Inc()
return
}
value, _ := e.bytesConverter(size)
value, err := e.bytesConverter(size)
if err != nil {
e.jsonParseFailures.Inc()
level.Debug(e.logger).Log("msg", "There was an issue calculating the value", "metric", metricName, "err", err)
return
}
level.Debug(e.logger).Log("msg", "Registering metric", "metric", metricName, "type", fileStoreType, "directory", fileStoreDir, "value", value)
ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, value, fileStoreType, fileStoreDir)
}
Expand Down

0 comments on commit 0786822

Please sign in to comment.