Skip to content

Commit

Permalink
fix: expose poll interval as separate metric (#21)
Browse files Browse the repository at this point in the history
The poll interval is an ever-changing value. This should not be
in the labels as it makes the number of unique label sets
explode in k8s (and therefore has a massive performance impact
in large clusters).
  • Loading branch information
janLo authored Oct 20, 2023
1 parent 2ff6844 commit d78fd56
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,21 @@ func getMetrics() {
"pod_namespace",
// Name of Node where pod is placed.
"node_name",
// A Node's adjustTime polling rate time after a Node API query.
"adjusted_polling_rate",
},
)

prometheus.MustRegister(opsQueued)

log.Debug().Msg(fmt.Sprintf("getMetrics has been invoked"))
currentNode = getEnv("CURRENT_NODE_NAME", "")

adjustedTimeGauge := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ephemeral_storage_polling_rate_seconds",
Help: "A Node's adjustTime polling rate time after a Node API query.",
})

prometheus.MustRegister(adjustedTimeGauge)

sampleInterval, _ = strconv.ParseInt(getEnv("SCRAPE_INTERVAL", "15"), 10, 64)
sampleInterval = sampleInterval * 1000
adjustTime := sampleInterval
Expand All @@ -133,6 +139,7 @@ func getMetrics() {
_ = json.Unmarshal(content, &data)

opsQueued.Reset() // reset this metrics in the Exporter
adjustedTimeGauge.Set(float64(adjustTime / 1000.0))

nodeName := data.Node.NodeName
for _, pod := range data.Pods {
Expand All @@ -144,7 +151,7 @@ func getMetrics() {
log.Warn().Msg(fmt.Sprintf("raw content %v", content))
}
opsQueued.With(prometheus.Labels{"pod_namespace": podNamespace,
"pod_name": podName, "node_name": nodeName, "adjusted_polling_rate": strconv.FormatInt(adjustTime, 10)}).Set(usedBytes)
"pod_name": podName, "node_name": nodeName}).Set(usedBytes)

log.Debug().Msg(fmt.Sprintf("pod %s/%s on %s with usedBytes: %f", podNamespace, podName, nodeName, usedBytes))
}
Expand Down

0 comments on commit d78fd56

Please sign in to comment.