@@ -16,9 +16,8 @@ package phpfpm
1616
1717import (
1818 "sync"
19-
19+ "fmt"
2020 "github.com/prometheus/client_golang/prometheus"
21- hashids "github.com/speps/go-hashids"
2221)
2322
2423const (
@@ -140,31 +139,31 @@ func NewExporter(pm PoolManager) *Exporter {
140139 processRequests : prometheus .NewDesc (
141140 prometheus .BuildFQName (namespace , "" , "process_requests" ),
142141 "The number of requests the process has served." ,
143- []string {"pool" , "pid_hash " , "scrape_uri" },
142+ []string {"pool" , "child " , "scrape_uri" },
144143 nil ),
145144
146145 processLastRequestMemory : prometheus .NewDesc (
147146 prometheus .BuildFQName (namespace , "" , "process_last_request_memory" ),
148147 "The max amount of memory the last request consumed." ,
149- []string {"pool" , "pid_hash " , "scrape_uri" },
148+ []string {"pool" , "child " , "scrape_uri" },
150149 nil ),
151150
152151 processLastRequestCPU : prometheus .NewDesc (
153152 prometheus .BuildFQName (namespace , "" , "process_last_request_cpu" ),
154153 "The %cpu the last request consumed." ,
155- []string {"pool" , "pid_hash " , "scrape_uri" },
154+ []string {"pool" , "child " , "scrape_uri" },
156155 nil ),
157156
158157 processRequestDuration : prometheus .NewDesc (
159158 prometheus .BuildFQName (namespace , "" , "process_request_duration" ),
160159 "The duration in microseconds of the requests." ,
161- []string {"pool" , "pid_hash " , "scrape_uri" },
160+ []string {"pool" , "child " , "scrape_uri" },
162161 nil ),
163162
164163 processState : prometheus .NewDesc (
165164 prometheus .BuildFQName (namespace , "" , "process_state" ),
166165 "The state of the process (Idle, Running, ...)." ,
167- []string {"pool" , "pid_hash " , "state" , "scrape_uri" },
166+ []string {"pool" , "child " , "state" , "scrape_uri" },
168167 nil ),
169168 }
170169}
@@ -211,13 +210,13 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
211210 ch <- prometheus .MustNewConstMetric (e .maxChildrenReached , prometheus .CounterValue , float64 (pool .MaxChildrenReached ), pool .Name , pool .Address )
212211 ch <- prometheus .MustNewConstMetric (e .slowRequests , prometheus .CounterValue , float64 (pool .SlowRequests ), pool .Name , pool .Address )
213212
214- for _ , process := range pool .Processes {
215- pidHash := calculateProcessHash ( process )
216- ch <- prometheus .MustNewConstMetric (e .processState , prometheus .GaugeValue , 1 , pool .Name , pidHash , process .State , pool .Address )
217- ch <- prometheus .MustNewConstMetric (e .processRequests , prometheus .CounterValue , float64 (process .Requests ), pool .Name , pidHash , pool .Address )
218- ch <- prometheus .MustNewConstMetric (e .processLastRequestMemory , prometheus .GaugeValue , float64 (process .LastRequestMemory ), pool .Name , pidHash , pool .Address )
219- ch <- prometheus .MustNewConstMetric (e .processLastRequestCPU , prometheus .GaugeValue , process .LastRequestCPU , pool .Name , pidHash , pool .Address )
220- ch <- prometheus .MustNewConstMetric (e .processRequestDuration , prometheus .GaugeValue , float64 (process .RequestDuration ), pool .Name , pidHash , pool .Address )
213+ for childNumber , process := range pool .Processes {
214+ childName := fmt . Sprintf ( "%d" , childNumber )
215+ ch <- prometheus .MustNewConstMetric (e .processState , prometheus .GaugeValue , 1 , pool .Name , childName , process .State , pool .Address )
216+ ch <- prometheus .MustNewConstMetric (e .processRequests , prometheus .CounterValue , float64 (process .Requests ), pool .Name , childName , pool .Address )
217+ ch <- prometheus .MustNewConstMetric (e .processLastRequestMemory , prometheus .GaugeValue , float64 (process .LastRequestMemory ), pool .Name , childName , pool .Address )
218+ ch <- prometheus .MustNewConstMetric (e .processLastRequestCPU , prometheus .GaugeValue , process .LastRequestCPU , pool .Name , childName , pool .Address )
219+ ch <- prometheus .MustNewConstMetric (e .processRequestDuration , prometheus .GaugeValue , float64 (process .RequestDuration ), pool .Name , childName , pool .Address )
221220 }
222221 }
223222}
@@ -242,14 +241,3 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
242241 ch <- e .processLastRequestCPU
243242 ch <- e .processRequestDuration
244243}
245-
246- // calculateProcessHash generates a unique identifier for a process to ensure uniqueness across multiple systems/containers
247- func calculateProcessHash (pp PoolProcess ) string {
248- hd := hashids .NewData ()
249- hd .Salt = "php-fpm_exporter"
250- hd .MinLength = 12
251- h , _ := hashids .NewWithData (hd )
252- e , _ := h .Encode ([]int {int (pp .StartTime ), int (pp .PID )})
253-
254- return e
255- }
0 commit comments