Skip to content

Commit 7184018

Browse files
authoredMar 3, 2025
Float and log processing (#189)
Signed-off-by: Anders Swanson <anders.swanson@oracle.com>
1 parent 0eda99a commit 7184018

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed
 

‎collector/collector.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric, tick *time.Time) {
290290
e.logger.Error("Error scraping metric",
291291
"Context", metric.Context,
292292
"MetricsDesc", fmt.Sprint(metric.MetricsDesc),
293-
"time", time.Since(scrapeStart),
293+
"duration", time.Since(scrapeStart),
294294
"error", scrapeError)
295295
}
296296
e.scrapeErrors.WithLabelValues(metric.Context).Inc()
297297
} else {
298298
e.logger.Debug("Successfully scraped metric",
299299
"Context", metric.Context,
300300
"MetricDesc", fmt.Sprint(metric.MetricsDesc),
301-
"time", time.Since(scrapeStart))
301+
"duration", time.Since(scrapeStart))
302302
}
303303
}()
304304
}
@@ -500,11 +500,9 @@ func (e *Exporter) scrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric,
500500
}
501501
// Construct Prometheus values to sent back
502502
for metric, metricHelp := range metricsDesc {
503-
value, err := strconv.ParseFloat(strings.TrimSpace(row[metric]), 64)
504-
// If not a float, skip current metric
505-
if err != nil {
506-
e.logger.Error("Unable to convert current value to float (metric=" + metric +
507-
",metricHelp=" + metricHelp + ",value=<" + row[metric] + ">)")
503+
value, ok := e.parseFloat(metric, metricHelp, row)
504+
if !ok {
505+
// Skip invalid metric values
508506
continue
509507
}
510508
e.logger.Debug("Query result",

‎collector/metrics.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package collector
55

66
import (
77
"strconv"
8+
"strings"
89
"time"
910
)
1011

@@ -52,10 +53,11 @@ func (e *Exporter) getQueryTimeout(metric Metric) time.Duration {
5253

5354
func (e *Exporter) parseFloat(metric, metricHelp string, row map[string]string) (float64, bool) {
5455
value, ok := row[metric]
55-
if !ok {
56-
return -1, ok
56+
if !ok || value == "<nil>" {
57+
// treat nil value as 0
58+
return 0.0, ok
5759
}
58-
valueFloat, err := strconv.ParseFloat(value, 64)
60+
valueFloat, err := strconv.ParseFloat(strings.TrimSpace(value), 64)
5961
if err != nil {
6062
e.logger.Error("Unable to convert current value to float (metric=" + metric +
6163
",metricHelp=" + metricHelp + ",value=<" + row[metric] + ">)")

0 commit comments

Comments
 (0)
Failed to load comments.