Skip to content

Commit 635088a

Browse files
committed
remove zero values from the export...
1 parent 4e02336 commit 635088a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

accounts.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,17 @@ func (ac *AccountsCollector) Describe(ch chan<- *prometheus.Desc) {
105105
func (ac *AccountsCollector) Collect(ch chan<- prometheus.Metric) {
106106
am := ParseAccountsMetrics(AccountsData())
107107
for a := range am {
108-
ch <- prometheus.MustNewConstMetric(ac.pending, prometheus.GaugeValue, am[a].pending, a)
109-
ch <- prometheus.MustNewConstMetric(ac.running, prometheus.GaugeValue, am[a].running, a)
110-
ch <- prometheus.MustNewConstMetric(ac.running_cpus, prometheus.GaugeValue, am[a].running_cpus, a)
111-
ch <- prometheus.MustNewConstMetric(ac.suspended, prometheus.GaugeValue, am[a].suspended, a)
108+
if am[a].pending > 0 {
109+
ch <- prometheus.MustNewConstMetric(ac.pending, prometheus.GaugeValue, am[a].pending, a)
110+
}
111+
if am[a].running > 0 {
112+
ch <- prometheus.MustNewConstMetric(ac.running, prometheus.GaugeValue, am[a].running, a)
113+
}
114+
if am[a].running_cpus > 0 {
115+
ch <- prometheus.MustNewConstMetric(ac.running_cpus, prometheus.GaugeValue, am[a].running_cpus, a)
116+
}
117+
if am[a].suspended > 0 {
118+
ch <- prometheus.MustNewConstMetric(ac.suspended, prometheus.GaugeValue, am[a].suspended, a)
119+
}
112120
}
113121
}

users.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,18 @@ func (uc *UsersCollector) Describe(ch chan<- *prometheus.Desc) {
105105
func (uc *UsersCollector) Collect(ch chan<- prometheus.Metric) {
106106
um := ParseUsersMetrics(UsersData())
107107
for u := range um {
108-
ch <- prometheus.MustNewConstMetric(uc.pending, prometheus.GaugeValue, um[u].pending, u)
109-
ch <- prometheus.MustNewConstMetric(uc.running, prometheus.GaugeValue, um[u].running, u)
110-
ch <- prometheus.MustNewConstMetric(uc.running_cpus, prometheus.GaugeValue, um[u].running_cpus, u)
111-
ch <- prometheus.MustNewConstMetric(uc.suspended, prometheus.GaugeValue, um[u].suspended, u)
108+
if um[u].pending > 0 {
109+
ch <- prometheus.MustNewConstMetric(uc.pending, prometheus.GaugeValue, um[u].pending, u)
110+
}
111+
if um[u].running > 0 {
112+
ch <- prometheus.MustNewConstMetric(uc.running, prometheus.GaugeValue, um[u].running, u)
113+
}
114+
if um[u].running_cpus > 0 {
115+
ch <- prometheus.MustNewConstMetric(uc.running_cpus, prometheus.GaugeValue, um[u].running_cpus, u)
116+
}
117+
if um[u].suspended > 0 {
118+
ch <- prometheus.MustNewConstMetric(uc.suspended, prometheus.GaugeValue, um[u].suspended, u)
119+
}
112120
}
113121
}
114122

0 commit comments

Comments
 (0)