Emulate PHP-FPMs metrics calculations for --phpfpm.fix-process-count
This commit is contained in:
parent
afbeb201b1
commit
6de4433881
2 changed files with 12 additions and 33 deletions
|
@ -178,21 +178,15 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
|||
continue
|
||||
}
|
||||
|
||||
pps := CountProcessState(pool)
|
||||
if !e.CalculateProcessScoreboard && (pps.Active() != pool.ActiveProcesses || pps.Idle != pool.IdleProcesses) {
|
||||
active, idle, total := CountProcessState(pool.Processes)
|
||||
if !e.CalculateProcessScoreboard && (active != pool.ActiveProcesses || idle != pool.IdleProcesses) {
|
||||
log.Error("Inconsistent active and idle processes reported. Set `--fix-process-count` to have this calculated by php-fpm_exporter instead.")
|
||||
}
|
||||
|
||||
var active, idle, total int64
|
||||
|
||||
if e.CalculateProcessScoreboard {
|
||||
active = pool.ActiveProcesses
|
||||
idle = pool.IdleProcesses
|
||||
total = pool.TotalProcesses
|
||||
} else {
|
||||
active = pps.Active()
|
||||
idle = pps.Idle
|
||||
total = pps.Total()
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1, pool.Name)
|
||||
|
|
|
@ -97,7 +97,7 @@ type PoolProcess struct {
|
|||
User string `json:"user"`
|
||||
Script string `json:"script"`
|
||||
LastRequestCPU float64 `json:"last request cpu"`
|
||||
LastRequestMemory int `json:"last request memory"`
|
||||
LastRequestMemory int64 `json:"last request memory"`
|
||||
}
|
||||
|
||||
// PoolProcessStateCounter holds the calculated metrics for pool processes.
|
||||
|
@ -192,40 +192,25 @@ func (p *Pool) error(err error) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Active calculates the number of active processes.
|
||||
func (pps *PoolProcessStateCounter) Active() int64 {
|
||||
return pps.Running + pps.ReadingHeaders
|
||||
}
|
||||
|
||||
// Total calculates the total number of process (Idle + Active).
|
||||
func (pps *PoolProcessStateCounter) Total() int64 {
|
||||
return pps.Idle + pps.Active()
|
||||
}
|
||||
|
||||
// CountProcessState creates a scoreboard with the calculated process metrics.
|
||||
func CountProcessState(p Pool) PoolProcessStateCounter {
|
||||
pps := PoolProcessStateCounter{}
|
||||
|
||||
for idx := range p.Processes {
|
||||
switch p.Processes[idx].State {
|
||||
// CountProcessState return the calculated metrics based on the reported processes.
|
||||
func CountProcessState(processes []PoolProcess) (active int64, idle int64, total int64) {
|
||||
for idx := range processes {
|
||||
switch processes[idx].State {
|
||||
case PoolProcessRequestRunning:
|
||||
pps.Running++
|
||||
active++
|
||||
case PoolProcessRequestIdle:
|
||||
pps.Idle++
|
||||
idle++
|
||||
case PoolProcessRequestEnding:
|
||||
pps.Ending++
|
||||
case PoolProcessRequestFinishing:
|
||||
pps.Finishing++
|
||||
case PoolProcessRequestInfo:
|
||||
pps.Info++
|
||||
case PoolProcessRequestReadingHeaders:
|
||||
pps.ReadingHeaders++
|
||||
active++
|
||||
default:
|
||||
log.Errorf("Unknown process state '%v'", p.Processes[idx].State)
|
||||
log.Errorf("Unknown process state '%v'", processes[idx].State)
|
||||
}
|
||||
}
|
||||
|
||||
return pps
|
||||
return active, idle, active + idle
|
||||
}
|
||||
|
||||
type timestamp time.Time
|
||||
|
|
Loading…
Reference in a new issue