Send metrics to Prometheus. +High Availability Setup
-
Redis(the service & the PHP extension): to act as a buffer before push and avoid latency in the code, and as a store for the current counter values. -
bin/console comsave:prometheus:pushcronjob: to push data periodically to Prometheus Pushgateway
In your services.yml add:
comsave_prometheus_pushgateway:
prometheus:
host: 'prometheus:9090'
username: 'admin' # optional
password: 'duuude' # optional
instance: 'moms_basement:6666' # your server host/name/etc
pushgateway:
host: 'pushgateway:9191'
username: 'admin2' # optional
password: 'duuude2' # optional
redis: 'redis:6379'
metrics:
api: # metric namespace
- name: 'orders'
type: 'counter'
help: 'counts the number of orders'
prefetch_group_label: 'user_id' # optional & only available for the counter; prefetch current value from prometheus by grouping sum() query by this label and populate the counter if it's missing in redis cache
labels:
- 'order_id'
- 'user_id'Add the bundle to your Symfony kernel.
new Comsave\PrometheusPushGatewayBundle\ComsavePrometheusPushGatewayBundle(),Single node is pretty straightforward.
- Use
PushGatewayClientto create a metric. Metric is stored inRedis. - Use
PushGatewayClientcan be pushed manually or with a command. After push metrics stored in Redis are transported to the actualPushGatewayservice. Prometheusperiodically pulls in new metrics fromPushGateway.
Multi-node set up works with the basics described above, with a couple exceptions:
- There's an
Haproxy(or other load balancer) that decides whichPushGatewaywill receive thepush. - Each
Prometheuspulls from everyPushGatewayin every node. That way eachPrometheushas the latest metrics. - Each
Prometheuspulls (federates) from otherPrometheusnodes (all but itself) though less often. This ensures data integrity (sort of replication).
Start single node docker-compose up -d
Or multi node docker-compose up -f docker-compose.multi-node.yml -d
Tests docker exec $(docker ps | grep _php | awk '{print $1}') vendor/bin/phpunit tests
MIT

