---
apiVersion: v1
kind: Service
metadata:
name: phpfpm-exporter-svc
namespace: monitoring
spec:
ports:
- name: tcp
port: 9253
protocol: TCP
clusterIP: None
selector:
app: phpfpm-exporter
sessionAffinity: None
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: phpfpm-exporter
namespace: monitoring
labels:
app: phpfpm-exporter
spec:
selector:
matchLabels:
app: phpfpm-exporter
replicas: 1
template:
metadata:
labels:
app: phpfpm-exporter
spec:
containers:
- name: phpfpm-exporter
image: "hipages/php-fpm_exporter"
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: 256m
memory: 256Mi
requests:
cpu: 50m
memory: 64Mi
env:
- name: PHP_FPM_SCRAPE_URI
value: "tcp://192.168.100.64:40011/status,tcp://192.168.100.64:40011/ping"
ports:
- containerPort: 9253
Подключимся на под prometeus и проверим получения метрик
root@prometheus-server-98dc898c9-k28zb:/opt/bitnami/prometheus# curl -s phpfpm-exporter-svc:9253/metrics | grep "phpfpm_process_state" | grep -v "#"
phpfpm_process_state{child="0",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Ending"} 0
phpfpm_process_state{child="0",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Finishing"} 0
phpfpm_process_state{child="0",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Getting request informations"} 0
phpfpm_process_state{child="0",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Idle"} 1
phpfpm_process_state{child="0",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Reading headers"} 0
phpfpm_process_state{child="0",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Running"} 0
phpfpm_process_state{child="1",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Ending"} 0
phpfpm_process_state{child="1",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Finishing"} 0
phpfpm_process_state{child="1",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Getting request informations"} 0
phpfpm_process_state{child="1",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Idle"} 0
phpfpm_process_state{child="1",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Reading headers"} 0
phpfpm_process_state{child="1",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Running"} 1
phpfpm_process_state{child="2",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Ending"} 0
phpfpm_process_state{child="2",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Finishing"} 1
phpfpm_process_state{child="2",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Getting request informations"} 0
phpfpm_process_state{child="2",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Idle"} 0
phpfpm_process_state{child="2",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Reading headers"} 0
phpfpm_process_state{child="2",pool="www",scrape_uri="tcp://192.168.100.64:40011/status",state="Running"} 0
Приведем конфиг prometeus к таком виду и перезапусим под
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "haproxy"
static_configs:
- targets: ["haproxy-exporter-svc:9101"]
labels:
alias: "haproxy"
- job_name: "mysql"
static_configs:
- targets: ["mysql-exporter-svc:9104"]
labels:
alias: "mysql"
- job_name: "node"
static_configs:
- targets: ["node-exporter-svc:9100"]
labels:
alias: "node"
- job_name: "phpfpm"
static_configs:
- targets: ["phpfpm-exporter-svc:9253"]
labels:
alias: "phpfpm"
Проверим отображения метрик
PS Дальше делаем отображение в grafana, шаблон можно найти в интернете