|
8 | 8 | cloudcost_exporter "github.com/grafana/cloudcost-exporter" |
9 | 9 | "github.com/grafana/cloudcost-exporter/pkg/provider" |
10 | 10 | "github.com/prometheus/client_golang/prometheus" |
11 | | - io_prometheus_client "github.com/prometheus/client_model/go" |
12 | 11 | ) |
13 | 12 |
|
14 | 13 | var gathererDurationHistogramVec = prometheus.NewHistogramVec( |
@@ -38,26 +37,13 @@ var gathererTotalCounterVec = prometheus.NewCounterVec( |
38 | 37 | ) |
39 | 38 |
|
40 | 39 | func emitHistogramMetric(ch chan<- prometheus.Metric, collectorName string, duration float64) { |
41 | | - ch <- prometheus.MustNewConstHistogram( |
42 | | - gathererDurationHistogramVec.WithLabelValues(collectorName).(prometheus.Histogram).Desc(), |
43 | | - 1, |
44 | | - duration, |
45 | | - nil, |
46 | | - collectorName, |
47 | | - ) |
| 40 | + h := gathererDurationHistogramVec.WithLabelValues(collectorName).(prometheus.Histogram) |
| 41 | + h.Observe(duration) |
| 42 | + ch <- h |
48 | 43 |
|
49 | 44 | counter := gathererTotalCounterVec.WithLabelValues(collectorName) |
50 | 45 | counter.Inc() |
51 | | - |
52 | | - m := &io_prometheus_client.Metric{} |
53 | | - if err := counter.Write(m); err == nil && m.Counter != nil { |
54 | | - ch <- prometheus.MustNewConstMetric( |
55 | | - gathererTotalCounterVec.WithLabelValues(collectorName).Desc(), |
56 | | - prometheus.CounterValue, |
57 | | - m.GetCounter().GetValue(), |
58 | | - collectorName, |
59 | | - ) |
60 | | - } |
| 46 | + ch <- counter |
61 | 47 | } |
62 | 48 |
|
63 | 49 | // CollectWithGatherer collects metrics from a collector and uses the Gatherer interface to detect errors. |
@@ -94,16 +80,7 @@ func CollectWithGatherer(ctx context.Context, c provider.Collector, ch chan<- pr |
94 | 80 | ) |
95 | 81 | errorCounter := gathererErrorCounterVec.WithLabelValues(c.Name()) |
96 | 82 | errorCounter.Inc() |
97 | | - |
98 | | - m := &io_prometheus_client.Metric{} |
99 | | - if err := errorCounter.Write(m); err == nil && m.Counter != nil { |
100 | | - ch <- prometheus.MustNewConstMetric( |
101 | | - gathererErrorCounterVec.WithLabelValues(c.Name()).Desc(), |
102 | | - prometheus.CounterValue, |
103 | | - m.GetCounter().GetValue(), |
104 | | - c.Name(), |
105 | | - ) |
106 | | - } |
| 83 | + ch <- errorCounter |
107 | 84 | } |
108 | 85 |
|
109 | 86 | emitHistogramMetric(ch, c.Name(), duration) |
|
0 commit comments