From 067e112bcc0360e82ebdf7116d16f5ecc82b1914 Mon Sep 17 00:00:00 2001 From: Audrius Karabanovas Date: Thu, 3 Oct 2019 11:57:07 +0300 Subject: [PATCH] Renaming to match prometheus convention for counters. Removing some obsolete metrics that could be calculated using sum() operator of prometheus. fix #11 --- collector/beat.go | 40 +++++++++++++--------------------------- collector/libbeat.go | 12 ++++++------ collector/system.go | 2 +- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/collector/beat.go b/collector/beat.go index b5cfd3b..3caeb37 100644 --- a/collector/beat.go +++ b/collector/beat.go @@ -52,34 +52,29 @@ func NewBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector { metrics: exportedMetrics{ { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "cpu_time", "milliseconds"), + prometheus.BuildFQName(beatInfo.Beat, "cpu_time", "seconds_total"), "beat.cpu.time", nil, prometheus.Labels{"mode": "system"}, ), - eval: func(stats *Stats) float64 { return stats.Beat.CPU.System.Time.MS }, + eval: func(stats *Stats) float64 { + return (time.Duration(stats.Beat.CPU.System.Time.MS) * time.Millisecond).Seconds() + }, valType: prometheus.CounterValue, }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "cpu_time", "milliseconds"), + prometheus.BuildFQName(beatInfo.Beat, "cpu_time", "seconds_total"), "beat.cpu.time", nil, prometheus.Labels{"mode": "user"}, ), - eval: func(stats *Stats) float64 { return stats.Beat.CPU.User.Time.MS }, - valType: prometheus.CounterValue, - }, - { - desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "cpu_time", "milliseconds"), - "beat.cpu.time", - nil, prometheus.Labels{"mode": "total"}, - ), - eval: func(stats *Stats) float64 { return stats.Beat.CPU.Total.Time.MS }, + eval: func(stats *Stats) float64 { + return (time.Duration(stats.Beat.CPU.User.Time.MS) * time.Millisecond).Seconds() + }, valType: prometheus.CounterValue, }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "cpu", "ticks"), + prometheus.BuildFQName(beatInfo.Beat, "cpu", "ticks_total"), "beat.cpu.ticks", nil, prometheus.Labels{"mode": "system"}, ), @@ -88,7 +83,7 @@ func NewBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector { }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "cpu", "ticks"), + prometheus.BuildFQName(beatInfo.Beat, "cpu", "ticks_total"), "beat.cpu.ticks", nil, prometheus.Labels{"mode": "user"}, ), @@ -97,16 +92,7 @@ func NewBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector { }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "cpu", "ticks"), - "beat.cpu.ticks", - nil, prometheus.Labels{"mode": "total"}, - ), - eval: func(stats *Stats) float64 { return stats.Beat.CPU.Total.Ticks }, - valType: prometheus.CounterValue, - }, - { - desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "uptime", "seconds"), + prometheus.BuildFQName(beatInfo.Beat, "uptime", "seconds_total"), "beat.info.uptime.ms", nil, nil, ), @@ -117,7 +103,7 @@ func NewBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector { }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "memstats", "gc_next"), + prometheus.BuildFQName(beatInfo.Beat, "memstats", "gc_next_total"), "beat.memstats.gc_next", nil, nil, ), @@ -139,7 +125,7 @@ func NewBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector { }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "memstats", "memory_total"), + prometheus.BuildFQName(beatInfo.Beat, "memstats", "memory"), "beat.memstats.memory_total", nil, nil, ), diff --git a/collector/libbeat.go b/collector/libbeat.go index f732047..292ad30 100644 --- a/collector/libbeat.go +++ b/collector/libbeat.go @@ -70,7 +70,7 @@ func NewLibBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector metrics: exportedMetrics{ { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "libbeat_config", "reloads"), + prometheus.BuildFQName(beatInfo.Beat, "libbeat_config", "reloads_total"), "libbeat.config.reloads", nil, nil, ), @@ -114,7 +114,7 @@ func NewLibBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "libbeat", "output_read_bytes"), + prometheus.BuildFQName(beatInfo.Beat, "libbeat", "output_read_bytes_total"), "libbeat.output.read.bytes", nil, nil, ), @@ -125,7 +125,7 @@ func NewLibBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "libbeat", "output_read_errors"), + prometheus.BuildFQName(beatInfo.Beat, "libbeat", "output_read_errors_total"), "libbeat.output.read.errors", nil, nil, ), @@ -136,7 +136,7 @@ func NewLibBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "libbeat", "output_write_bytes"), + prometheus.BuildFQName(beatInfo.Beat, "libbeat", "output_write_bytes_total"), "libbeat.output.write.bytes", nil, nil, ), @@ -147,7 +147,7 @@ func NewLibBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector }, { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "libbeat", "output_write_errors"), + prometheus.BuildFQName(beatInfo.Beat, "libbeat", "output_write_errors_total"), "libbeat.output.write.errors", nil, nil, ), @@ -322,7 +322,7 @@ func (c *libbeatCollector) Describe(ch chan<- *prometheus.Desc) { } libbeatOutputType = prometheus.NewDesc( - prometheus.BuildFQName(c.beatInfo.Beat, "libbeat", "output"), + prometheus.BuildFQName(c.beatInfo.Beat, "libbeat", "output_total"), "libbeat.output.type", []string{"type"}, nil, ) diff --git a/collector/system.go b/collector/system.go index 490a641..386585d 100644 --- a/collector/system.go +++ b/collector/system.go @@ -35,7 +35,7 @@ func NewSystemCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector { metrics: exportedMetrics{ { desc: prometheus.NewDesc( - prometheus.BuildFQName(beatInfo.Beat, "system_cpu", "cores"), + prometheus.BuildFQName(beatInfo.Beat, "system_cpu", "cores_total"), "cpu cores", nil, nil, ),