Skip to content

Commit 5ea7ce1

Browse files
authored
Merge pull request #11 from njam/jobs-waiting
Add metric "jobs_waiting"
2 parents e132c78 + fa079ba commit 5ea7ce1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ gearman_jobs{function="foo"} 0
5555
gearman_jobs_running{function="bar"} 0
5656
gearman_jobs_running{function="foo"} 0
5757
58+
# HELP gearman_jobs_waiting number of jobs waiting for an available worker
59+
# TYPE gearman_jobs_waiting gauge
60+
gearman_jobs_running{function="bar"} 0
61+
gearman_jobs_waiting{function="foo"} 0
62+
5863
# HELP gearman_workers number of capable workers
5964
# TYPE gearman_workers gauge
6065
gearman_workers{function="bar"} 1

collector.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type collector struct {
1212
versionInfo *prometheus.Desc
1313
statusJobs *prometheus.Desc
1414
statusJobsRunning *prometheus.Desc
15+
statusJobsWaiting *prometheus.Desc
1516
statusWorkers *prometheus.Desc
1617
}
1718

@@ -31,6 +32,7 @@ func (e *Exporter) newCollector(g *gearman) *collector {
3132
versionInfo: newFuncMetric("version_info", "gearman version", []string{"version"}),
3233
statusJobs: newFuncMetric("jobs", "number of jobs queued or running", []string{"function"}),
3334
statusJobsRunning: newFuncMetric("jobs_running", "number of running jobs", []string{"function"}),
35+
statusJobsWaiting: newFuncMetric("jobs_waiting", "number of jobs waiting for an available worker", []string{"function"}),
3436
statusWorkers: newFuncMetric("workers", "number of capable workers", []string{"function"}),
3537
}
3638
}
@@ -40,6 +42,7 @@ func (c *collector) Describe(ch chan<- *prometheus.Desc) {
4042
ch <- c.versionInfo
4143
ch <- c.statusJobs
4244
ch <- c.statusJobsRunning
45+
ch <- c.statusJobsWaiting
4346
ch <- c.statusWorkers
4447
}
4548

@@ -82,6 +85,12 @@ func (c *collector) collectStatus(ch chan<- prometheus.Metric) {
8285
float64(v.running),
8386
k)
8487

88+
ch <- prometheus.MustNewConstMetric(
89+
c.statusJobsWaiting,
90+
prometheus.GaugeValue,
91+
float64(v.total-v.running),
92+
k)
93+
8594
ch <- prometheus.MustNewConstMetric(
8695
c.statusWorkers,
8796
prometheus.GaugeValue,

0 commit comments

Comments
 (0)