Skip to content

Commit fb60a03

Browse files
committed
Remove the calculation of metrics from the exporter. Use clamp_min(idelta(netgear_traffic_todaydownload[5m]), 0) instead
1 parent 130dec5 commit fb60a03

File tree

2 files changed

+3
-82
lines changed

2 files changed

+3
-82
lines changed

collectors/traffic_collector.go

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ type TrafficCollector struct {
1515
client *netgear_client.NetgearClient
1616
metrics map[string]prometheus.Gauge
1717

18-
calculateDelta bool
19-
previousIn float64
20-
previousOut float64
21-
trafficInMetric prometheus.Gauge
22-
trafficOutMetric prometheus.Gauge
23-
2418
trafficScrapesTotalMetric prometheus.Counter
2519
trafficScrapeErrorsTotalMetric prometheus.Counter
2620
lastTrafficScrapeErrorMetric prometheus.Gauge
@@ -52,7 +46,7 @@ var TrafficCollectorFields = [...]string{
5246
"LastMonthUploadAverage",
5347
}
5448

55-
func NewTrafficCollector(namespace string, client *netgear_client.NetgearClient, calculateDelta bool) *TrafficCollector {
49+
func NewTrafficCollector(namespace string, client *netgear_client.NetgearClient) *TrafficCollector {
5650
metrics := make(map[string]prometheus.Gauge)
5751
for _, name := range TrafficCollectorFields {
5852
metrics[name] = prometheus.NewGauge(
@@ -65,23 +59,6 @@ func NewTrafficCollector(namespace string, client *netgear_client.NetgearClient,
6559
)
6660
}
6761

68-
trafficInMetric := prometheus.NewGauge(
69-
prometheus.GaugeOpts{
70-
Namespace: namespace,
71-
Subsystem: "traffic",
72-
Name: "download",
73-
Help: "Value downloaded since previous check",
74-
},
75-
)
76-
trafficOutMetric := prometheus.NewGauge(
77-
prometheus.GaugeOpts{
78-
Namespace: namespace,
79-
Subsystem: "traffic",
80-
Name: "upload",
81-
Help: "Value uploaded since previous check",
82-
},
83-
)
84-
8562
trafficScrapesTotalMetric := prometheus.NewCounter(
8663
prometheus.CounterOpts{
8764
Namespace: namespace,
@@ -132,12 +109,6 @@ func NewTrafficCollector(namespace string, client *netgear_client.NetgearClient,
132109
client: client,
133110
metrics: metrics,
134111

135-
calculateDelta: calculateDelta,
136-
trafficInMetric: trafficInMetric,
137-
previousIn: float64(-1),
138-
trafficOutMetric: trafficOutMetric,
139-
previousOut: float64(-1),
140-
141112
trafficScrapesTotalMetric: trafficScrapesTotalMetric,
142113
trafficScrapeErrorsTotalMetric: trafficScrapeErrorsTotalMetric,
143114
lastTrafficScrapeErrorMetric: lastTrafficScrapeErrorMetric,
@@ -180,47 +151,6 @@ func (c *TrafficCollector) Collect(ch chan<- prometheus.Metric) {
180151
}
181152
}
182153

183-
if c.calculateDelta {
184-
currentIn, _ := strconv.ParseFloat(stats["TodayDownload"], 64)
185-
currentOut, _ := strconv.ParseFloat(stats["TodayUpload"], 64)
186-
187-
/* On the first scrape, the previous values are -1. Since we are calcluating
188-
a delta only, pretend this one was zero and update our previous value */
189-
if c.previousIn < 0 {
190-
c.previousIn = currentIn
191-
}
192-
if c.previousOut < 0 {
193-
c.previousOut = currentOut
194-
}
195-
196-
newIn := currentIn - c.previousIn
197-
newOut := currentOut - c.previousOut
198-
199-
log.Infof("In - previous: %v, current: %v, new: %v", c.previousIn, currentIn, newIn)
200-
log.Infof("Out - previous: %v, current: %v, new: %v", c.previousOut, currentOut, newOut)
201-
log.Debugf("Raw stats returned:\n")
202-
for k, v := range stats {
203-
log.Debugf(" %v => %v", k, v)
204-
}
205-
206-
c.previousIn = currentIn
207-
c.previousOut = currentOut
208-
209-
/* Metric rolled to next day or this collector started. Assume 0 */
210-
if newIn < 0 {
211-
newIn = 0
212-
}
213-
if newOut < 0 {
214-
newOut = 0
215-
}
216-
217-
c.trafficInMetric.Set(newIn)
218-
c.trafficInMetric.Collect(ch)
219-
220-
c.trafficOutMetric.Set(newOut)
221-
c.trafficOutMetric.Collect(ch)
222-
}
223-
224154
c.trafficScrapeErrorsTotalMetric.Collect(ch)
225155

226156
c.trafficScrapesTotalMetric.Inc()
@@ -241,11 +171,6 @@ func (c *TrafficCollector) Describe(ch chan<- *prometheus.Desc) {
241171
c.metrics[name].Describe(ch)
242172
}
243173

244-
if c.calculateDelta {
245-
c.trafficInMetric.Describe(ch)
246-
c.trafficOutMetric.Describe(ch)
247-
}
248-
249174
c.trafficScrapesTotalMetric.Describe(ch)
250175
c.trafficScrapeErrorsTotalMetric.Describe(ch)
251176
c.lastTrafficScrapeErrorMetric.Describe(ch)

netgear_exporter.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ var (
4747
"filter.collectors", "Comma separated collectors to filter (Traffic) ($NETGEAR_EXPORTER_FILTER_COLLECTORS)",
4848
).Envar("NETGEAR_EXPORTER_FILTER_COLLECTORS").Default("").String()
4949

50-
netgearCalculateTrafficDelta = kingpin.Flag(
51-
"traffic.calculatedelta", "When enabled, calculates a delta value for in/out bytes. See README.md for warning. ($NETGEAR_EXPORTER_CACLULATE_DELTA)",
52-
).Envar("NETGEAR_EXPORTER_CALCULATE_DELTA").Default("false").Bool()
53-
5450
metricsNamespace = kingpin.Flag(
5551
"metrics.namespace", "Metrics Namespace ($NETGEAR_EXPORTER_METRICS_NAMESPACE)",
5652
).Envar("NETGEAR_EXPORTER_METRICS_NAMESPACE").Default("netgear").String()
@@ -146,7 +142,7 @@ func main() {
146142
- When the describe function exits after returning the last item, close the channel to end the background consume function
147143
*/
148144
fmt.Println("Traffic")
149-
trafficCollector := collectors.NewTrafficCollector(*metricsNamespace, nil, true)
145+
trafficCollector := collectors.NewTrafficCollector(*metricsNamespace, nil)
150146
out = make(chan *prometheus.Desc)
151147
go eatOutput(out)
152148
trafficCollector.Describe(out)
@@ -181,7 +177,7 @@ func main() {
181177
}
182178

183179
if collectorsFilter.Enabled(filters.TrafficCollector) {
184-
trafficCollector := collectors.NewTrafficCollector(*metricsNamespace, netgearClient, *netgearCalculateTrafficDelta)
180+
trafficCollector := collectors.NewTrafficCollector(*metricsNamespace, netgearClient)
185181
prometheus.MustRegister(trafficCollector)
186182
}
187183

0 commit comments

Comments
 (0)