Skip to content

Commit

Permalink
clean/formatted floats, removed trailing 0s
Browse files Browse the repository at this point in the history
  • Loading branch information
portertech committed Oct 3, 2017
1 parent e9c1a23 commit c3ff3ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ Application instrumentation:

```
$ sensu-prometheus-collector -exporter-url http://localhost:8080/metrics
go_memstats_last_gc_time_seconds value=0.000000 1506991233
go_memstats_mspan_sys_bytes value=32768.000000 1506991233
go_memstats_last_gc_time_seconds value=0 1506991233
go_memstats_mspan_sys_bytes value=32768 1506991233
...
```

```
$ sensu-prometheus-collector -exporter-url http://localhost:8080/metrics -output-format graphite -metric-prefix foo.bar.
foo.bar.go_memstats_stack_inuse_bytes 294912.000000 1506991405
foo.bar.go_memstats_mallocs_total 6375.000000 1506991405
foo.bar.go_memstats_stack_inuse_bytes 294912 1506991405
foo.bar.go_memstats_mallocs_total 6375 1506991405
...
```

Prometheus query API:

```
$ sensu-prometheus-collector -prom-url http://localhost:9090 -prom-query up
up,instance=localhost:9090,job=prometheus value=1.000000 1506991495
up,instance=localhost:9090,job=prometheus value=1 1506991495
```
9 changes: 5 additions & 4 deletions sensu-prometheus-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"os"
"strconv"
"time"

"github.com/prometheus/client_golang/api/prometheus"
Expand Down Expand Up @@ -56,12 +57,12 @@ func CreateGraphiteMetrics(samples model.Vector, metricPrefix string) string {
for _, sample := range samples {
name := fmt.Sprintf("%s%s", metricPrefix, sample.Metric["__name__"])

value := sample.Value
value := strconv.FormatFloat(float64(sample.Value), 'f', -1, 64)

now := time.Now()
timestamp := now.Unix()

metric := fmt.Sprintf("%s %f %v\n", name, value, timestamp)
metric := fmt.Sprintf("%s %s %d\n", name, value, timestamp)

metrics += metric
}
Expand All @@ -81,12 +82,12 @@ func CreateInfluxMetrics(samples model.Vector, metricPrefix string) string {
}
}

value := sample.Value
value := strconv.FormatFloat(float64(sample.Value), 'f', -1, 64)

now := time.Now()
timestamp := now.Unix()

metric += fmt.Sprintf(" value=%f %v\n", value, timestamp)
metric += fmt.Sprintf(" value=%s %d\n", value, timestamp)

metrics += metric
}
Expand Down

0 comments on commit c3ff3ea

Please sign in to comment.