Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.

Commit 4b99f0f

Browse files
authored
Merge pull request #236 from colakong/cnelson/add_idle_metric
Add idle metric
2 parents 4d350be + bd6cfc4 commit 4b99f0f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

haproxy_exporter.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ var (
232232
61: newBackendMetric("http_total_time_average_seconds", "Avg. HTTP total time for last 1024 successful connections.", prometheus.GaugeValue, nil),
233233
}
234234

235-
haproxyInfo = prometheus.NewDesc(prometheus.BuildFQName(namespace, "version", "info"), "HAProxy version info.", []string{"release_date", "version"}, nil)
236-
haproxyUp = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "up"), "Was the last scrape of HAProxy successful.", nil, nil)
235+
haproxyInfo = prometheus.NewDesc(prometheus.BuildFQName(namespace, "version", "info"), "HAProxy version info.", []string{"release_date", "version"}, nil)
236+
haproxyUp = prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "up"), "Was the last scrape of HAProxy successful.", nil, nil)
237+
haproxyIdlePct = prometheus.NewDesc(prometheus.BuildFQName(namespace, "idle", "percent"), "Time spent waiting for events instead of processing them.", nil, nil)
237238
)
238239

239240
// Exporter collects HAProxy stats from the given URI and exports them using
@@ -317,6 +318,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
317318
}
318319
ch <- haproxyInfo
319320
ch <- haproxyUp
321+
ch <- haproxyIdlePct
320322
ch <- e.totalScrapes.Desc()
321323
ch <- e.csvParseFailures.Desc()
322324
}
@@ -397,6 +399,9 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) (up float64) {
397399
level.Debug(e.logger).Log("msg", "Failed parsing show info", "err", err)
398400
} else {
399401
ch <- prometheus.MustNewConstMetric(haproxyInfo, prometheus.GaugeValue, 1, info.ReleaseDate, info.Version)
402+
if info.IdlePct != -1 {
403+
ch <- prometheus.MustNewConstMetric(haproxyIdlePct, prometheus.GaugeValue, info.IdlePct)
404+
}
400405
}
401406
}
402407

@@ -435,10 +440,13 @@ loop:
435440
type versionInfo struct {
436441
ReleaseDate string
437442
Version string
443+
IdlePct float64
438444
}
439445

440446
func (e *Exporter) parseInfo(i io.Reader) (versionInfo, error) {
441447
var version, releaseDate string
448+
// idlePct value of -1 is used to indicate it's unset
449+
var idlePct float64 = -1
442450
s := bufio.NewScanner(i)
443451
for s.Scan() {
444452
line := s.Text()
@@ -452,9 +460,14 @@ func (e *Exporter) parseInfo(i io.Reader) (versionInfo, error) {
452460
releaseDate = field[1]
453461
case "Version":
454462
version = field[1]
463+
case "Idle_pct":
464+
i, err := strconv.ParseFloat(field[1], 10)
465+
if err == nil && i >= 0 && i <= 100 {
466+
idlePct = i
467+
}
455468
}
456469
}
457-
return versionInfo{ReleaseDate: releaseDate, Version: version}, s.Err()
470+
return versionInfo{ReleaseDate: releaseDate, Version: version, IdlePct: idlePct}, s.Err()
458471
}
459472

460473
func (e *Exporter) parseRow(csvRow []string, ch chan<- prometheus.Metric) {

haproxy_exporter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
const (
3535
testSocket = "/tmp/haproxyexportertest.sock"
36-
testInfo = "Release_date: test date\nVersion: test version\n"
36+
testInfo = "Release_date: test date\nVersion: test version\nIdle_pct: 100\n"
3737
)
3838

3939
type haproxy struct {

test/unix_domain.metrics

+3
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ haproxy_up 1
8181
# HELP haproxy_version_info HAProxy version info.
8282
# TYPE haproxy_version_info gauge
8383
haproxy_version_info{release_date="test date",version="test version"} 1
84+
# HELP haproxy_idle_percent Time spent waiting for events instead of processing them.
85+
# TYPE haproxy_idle_percent gauge
86+
haproxy_idle_percent 100

0 commit comments

Comments
 (0)