From 26cc9ada6672b09a58528d8851a91a137887e937 Mon Sep 17 00:00:00 2001 From: Andrei Kirillov Date: Thu, 2 Sep 2021 04:32:57 +0300 Subject: [PATCH] fix: generate gauge metrics for all states (#173) --- phpfpm/exporter.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/phpfpm/exporter.go b/phpfpm/exporter.go index 25785c7..e644715 100644 --- a/phpfpm/exporter.go +++ b/phpfpm/exporter.go @@ -213,7 +213,20 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { for childNumber, process := range pool.Processes { childName := fmt.Sprintf("%d", childNumber) - ch <- prometheus.MustNewConstMetric(e.processState, prometheus.GaugeValue, 1, pool.Name, childName, process.State, pool.Address) + + states := map[string]int{ + PoolProcessRequestIdle: 0, + PoolProcessRequestRunning: 0, + PoolProcessRequestFinishing: 0, + PoolProcessRequestReadingHeaders: 0, + PoolProcessRequestInfo: 0, + PoolProcessRequestEnding: 0, + } + states[process.State]++ + + for stateName, inState := range states { + ch <- prometheus.MustNewConstMetric(e.processState, prometheus.GaugeValue, float64(inState), pool.Name, childName, stateName, pool.Address) + } ch <- prometheus.MustNewConstMetric(e.processRequests, prometheus.CounterValue, float64(process.Requests), pool.Name, childName, pool.Address) ch <- prometheus.MustNewConstMetric(e.processLastRequestMemory, prometheus.GaugeValue, float64(process.LastRequestMemory), pool.Name, childName, pool.Address) ch <- prometheus.MustNewConstMetric(e.processLastRequestCPU, prometheus.GaugeValue, process.LastRequestCPU, pool.Name, childName, pool.Address)