feat: add scrape_url as prometheus label for each metric (#72)
Co-authored-by: Alexander Korelskiy <korelskiy@uteka.ru> Co-authored-by: Enrico Stahn <enrico.stahn@gmail.com>
This commit is contained in:
parent
d110606e22
commit
505fe34b2c
1 changed files with 37 additions and 37 deletions
|
@ -62,109 +62,109 @@ func NewExporter(pm PoolManager) *Exporter {
|
||||||
up: prometheus.NewDesc(
|
up: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "up"),
|
prometheus.BuildFQName(namespace, "", "up"),
|
||||||
"Could PHP-FPM be reached?",
|
"Could PHP-FPM be reached?",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
scrapeFailues: prometheus.NewDesc(
|
scrapeFailues: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "scrape_failures"),
|
prometheus.BuildFQName(namespace, "", "scrape_failures"),
|
||||||
"The number of failures scraping from PHP-FPM.",
|
"The number of failures scraping from PHP-FPM.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
startSince: prometheus.NewDesc(
|
startSince: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "start_since"),
|
prometheus.BuildFQName(namespace, "", "start_since"),
|
||||||
"The number of seconds since FPM has started.",
|
"The number of seconds since FPM has started.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
acceptedConnections: prometheus.NewDesc(
|
acceptedConnections: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "accepted_connections"),
|
prometheus.BuildFQName(namespace, "", "accepted_connections"),
|
||||||
"The number of requests accepted by the pool.",
|
"The number of requests accepted by the pool.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
listenQueue: prometheus.NewDesc(
|
listenQueue: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "listen_queue"),
|
prometheus.BuildFQName(namespace, "", "listen_queue"),
|
||||||
"The number of requests in the queue of pending connections.",
|
"The number of requests in the queue of pending connections.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
maxListenQueue: prometheus.NewDesc(
|
maxListenQueue: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "max_listen_queue"),
|
prometheus.BuildFQName(namespace, "", "max_listen_queue"),
|
||||||
"The maximum number of requests in the queue of pending connections since FPM has started.",
|
"The maximum number of requests in the queue of pending connections since FPM has started.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
listenQueueLength: prometheus.NewDesc(
|
listenQueueLength: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "listen_queue_length"),
|
prometheus.BuildFQName(namespace, "", "listen_queue_length"),
|
||||||
"The size of the socket queue of pending connections.",
|
"The size of the socket queue of pending connections.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
idleProcesses: prometheus.NewDesc(
|
idleProcesses: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "idle_processes"),
|
prometheus.BuildFQName(namespace, "", "idle_processes"),
|
||||||
"The number of idle processes.",
|
"The number of idle processes.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
activeProcesses: prometheus.NewDesc(
|
activeProcesses: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "active_processes"),
|
prometheus.BuildFQName(namespace, "", "active_processes"),
|
||||||
"The number of active processes.",
|
"The number of active processes.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
totalProcesses: prometheus.NewDesc(
|
totalProcesses: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "total_processes"),
|
prometheus.BuildFQName(namespace, "", "total_processes"),
|
||||||
"The number of idle + active processes.",
|
"The number of idle + active processes.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
maxActiveProcesses: prometheus.NewDesc(
|
maxActiveProcesses: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "max_active_processes"),
|
prometheus.BuildFQName(namespace, "", "max_active_processes"),
|
||||||
"The maximum number of active processes since FPM has started.",
|
"The maximum number of active processes since FPM has started.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
maxChildrenReached: prometheus.NewDesc(
|
maxChildrenReached: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "max_children_reached"),
|
prometheus.BuildFQName(namespace, "", "max_children_reached"),
|
||||||
"The number of times, the process limit has been reached, when pm tries to start more children (works only for pm 'dynamic' and 'ondemand').",
|
"The number of times, the process limit has been reached, when pm tries to start more children (works only for pm 'dynamic' and 'ondemand').",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
slowRequests: prometheus.NewDesc(
|
slowRequests: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "slow_requests"),
|
prometheus.BuildFQName(namespace, "", "slow_requests"),
|
||||||
"The number of requests that exceeded your 'request_slowlog_timeout' value.",
|
"The number of requests that exceeded your 'request_slowlog_timeout' value.",
|
||||||
[]string{"pool"},
|
[]string{"pool", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
processRequests: prometheus.NewDesc(
|
processRequests: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "process_requests"),
|
prometheus.BuildFQName(namespace, "", "process_requests"),
|
||||||
"The number of requests the process has served.",
|
"The number of requests the process has served.",
|
||||||
[]string{"pool", "pid_hash"},
|
[]string{"pool", "pid_hash", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
processLastRequestMemory: prometheus.NewDesc(
|
processLastRequestMemory: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "process_last_request_memory"),
|
prometheus.BuildFQName(namespace, "", "process_last_request_memory"),
|
||||||
"The max amount of memory the last request consumed.",
|
"The max amount of memory the last request consumed.",
|
||||||
[]string{"pool", "pid_hash"},
|
[]string{"pool", "pid_hash", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
processLastRequestCPU: prometheus.NewDesc(
|
processLastRequestCPU: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "process_last_request_cpu"),
|
prometheus.BuildFQName(namespace, "", "process_last_request_cpu"),
|
||||||
"The %cpu the last request consumed.",
|
"The %cpu the last request consumed.",
|
||||||
[]string{"pool", "pid_hash"},
|
[]string{"pool", "pid_hash", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
processRequestDuration: prometheus.NewDesc(
|
processRequestDuration: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "process_request_duration"),
|
prometheus.BuildFQName(namespace, "", "process_request_duration"),
|
||||||
"The duration in microseconds of the requests.",
|
"The duration in microseconds of the requests.",
|
||||||
[]string{"pool", "pid_hash"},
|
[]string{"pool", "pid_hash", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
|
|
||||||
processState: prometheus.NewDesc(
|
processState: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, "", "process_state"),
|
prometheus.BuildFQName(namespace, "", "process_state"),
|
||||||
"The state of the process (Idle, Running, ...).",
|
"The state of the process (Idle, Running, ...).",
|
||||||
[]string{"pool", "pid_hash", "state"},
|
[]string{"pool", "pid_hash", "state", "scrape_uri"},
|
||||||
nil),
|
nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,10 +179,10 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pool := range e.PoolManager.Pools {
|
for _, pool := range e.PoolManager.Pools {
|
||||||
ch <- prometheus.MustNewConstMetric(e.scrapeFailues, prometheus.CounterValue, float64(pool.ScrapeFailures), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.scrapeFailues, prometheus.CounterValue, float64(pool.ScrapeFailures), pool.Name, pool.Address)
|
||||||
|
|
||||||
if pool.ScrapeError != nil {
|
if pool.ScrapeError != nil {
|
||||||
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0, pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0, pool.Name, pool.Address)
|
||||||
log.Errorf("Error scraping PHP-FPM: %v", pool.ScrapeError)
|
log.Errorf("Error scraping PHP-FPM: %v", pool.ScrapeError)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -198,26 +198,26 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||||
total = pool.TotalProcesses
|
total = pool.TotalProcesses
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1, pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1, pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.startSince, prometheus.CounterValue, float64(pool.StartSince), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.startSince, prometheus.CounterValue, float64(pool.StartSince), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.acceptedConnections, prometheus.CounterValue, float64(pool.AcceptedConnections), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.acceptedConnections, prometheus.CounterValue, float64(pool.AcceptedConnections), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.listenQueue, prometheus.GaugeValue, float64(pool.ListenQueue), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.listenQueue, prometheus.GaugeValue, float64(pool.ListenQueue), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.maxListenQueue, prometheus.CounterValue, float64(pool.MaxListenQueue), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.maxListenQueue, prometheus.CounterValue, float64(pool.MaxListenQueue), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.listenQueueLength, prometheus.GaugeValue, float64(pool.ListenQueueLength), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.listenQueueLength, prometheus.GaugeValue, float64(pool.ListenQueueLength), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.idleProcesses, prometheus.GaugeValue, float64(idle), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.idleProcesses, prometheus.GaugeValue, float64(idle), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.activeProcesses, prometheus.GaugeValue, float64(active), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.activeProcesses, prometheus.GaugeValue, float64(active), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.totalProcesses, prometheus.GaugeValue, float64(total), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.totalProcesses, prometheus.GaugeValue, float64(total), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.maxActiveProcesses, prometheus.CounterValue, float64(pool.MaxActiveProcesses), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.maxActiveProcesses, prometheus.CounterValue, float64(pool.MaxActiveProcesses), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.maxChildrenReached, prometheus.CounterValue, float64(pool.MaxChildrenReached), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.maxChildrenReached, prometheus.CounterValue, float64(pool.MaxChildrenReached), pool.Name, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.slowRequests, prometheus.CounterValue, float64(pool.SlowRequests), pool.Name)
|
ch <- prometheus.MustNewConstMetric(e.slowRequests, prometheus.CounterValue, float64(pool.SlowRequests), pool.Name, pool.Address)
|
||||||
|
|
||||||
for _, process := range pool.Processes {
|
for _, process := range pool.Processes {
|
||||||
pidHash := calculateProcessHash(process)
|
pidHash := calculateProcessHash(process)
|
||||||
ch <- prometheus.MustNewConstMetric(e.processState, prometheus.GaugeValue, 1, pool.Name, pidHash, process.State)
|
ch <- prometheus.MustNewConstMetric(e.processState, prometheus.GaugeValue, 1, pool.Name, pidHash, process.State, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.processRequests, prometheus.CounterValue, float64(process.Requests), pool.Name, pidHash)
|
ch <- prometheus.MustNewConstMetric(e.processRequests, prometheus.CounterValue, float64(process.Requests), pool.Name, pidHash, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.processLastRequestMemory, prometheus.GaugeValue, float64(process.LastRequestMemory), pool.Name, pidHash)
|
ch <- prometheus.MustNewConstMetric(e.processLastRequestMemory, prometheus.GaugeValue, float64(process.LastRequestMemory), pool.Name, pidHash, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.processLastRequestCPU, prometheus.GaugeValue, process.LastRequestCPU, pool.Name, pidHash)
|
ch <- prometheus.MustNewConstMetric(e.processLastRequestCPU, prometheus.GaugeValue, process.LastRequestCPU, pool.Name, pidHash, pool.Address)
|
||||||
ch <- prometheus.MustNewConstMetric(e.processRequestDuration, prometheus.GaugeValue, float64(process.RequestDuration), pool.Name, pidHash)
|
ch <- prometheus.MustNewConstMetric(e.processRequestDuration, prometheus.GaugeValue, float64(process.RequestDuration), pool.Name, pidHash, pool.Address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue