Thursday 1 August 2019

Prometheus docke-compose push gateway, client library for PHP, and alert rules based on hour and day

Promethesus push gateway is required for any promethesus client library to push metrics to:

Include the following in your docker-compose.yml services:


Prometheus client library for PHP:
https://github.com/Jimdo/prometheus_client_php
pushgateway:
image: prom/pushgateway
ports:
- 9091:9091
use push gateway example, can use in memory adapter if cron job or task is not a long running one
https://github.com/Jimdo/prometheus_client_php/blob/master/examples/pushgateway.php

configure the push_gateway IP address to be whatever the push gateway IP address and port you used in pushgateway service in docker-compose.yml


Set prometheus alert rules based on time:
https://medium.com/@tom.fawcett/time-of-day-based-notifications-with-prometheus-and-alertmanager-1bf7a23b7695
https://prometheus.io/docs/prometheus/latest/querying/functions/#hour()
https://www.robustperception.io/combining-alert-conditions

Prometheus has hour(), and day_of_month() built in function, just use them in prometheus alert.rules file . For example:
  - alert: high_load
    expr: node_load1 > 0.5 and  hour() >= 16 and day_of_week() == 6  
    for: 2m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} under high load"
      description: "{{ $labels.instance }} of job {{ $labels.job }} is under high load."

No comments:

Post a Comment