Compare languages | Модуль Prometheus Pushgateway: примеры

Пример настройки модуля

Example of the module configuration

yaml apiVersion: deckhouse.io/v1alpha1 kind: ModuleConfig metadata: name: prometheus-pushgateway spec: version: 1 enabled: true settings: instances:

  • first
  • second
  • another

yaml apiVersion: deckhouse.io/v1alpha1 kind: ModuleConfig metadata: name: prometheus-pushgateway spec: version: 1 enabled: true settings: instances:

  • first
  • second
  • another

Адрес PushGateway (из контейнера пода): http://first.kube-prometheus-pushgateway:9091.

PushGateway address (from a container pod): http://first.kube-prometheus-pushgateway:9091.

Отправка метрики

Pushing a metric

Пример отправки метрики через curl:

An example of pushing a metric using curl:

shell echo “test_metric{env=”dev”} 3.14” | curl –data-binary @- http://first.kube-prometheus-pushgateway:9091/metrics/job/myapp

shell echo “test_metric{env=”dev”} 3.14” | curl –data-binary @- http://first.kube-prometheus-pushgateway:9091/metrics/job/myapp

Через 30 секунд (после скрейпа данных) метрики будут доступны в Prometheus. Пример:

The metrics will be available in Prometheus in 30 seconds (after the data are scraped). An example:

text test_metric{container=”prometheus-pushgateway”, env=”dev”, exported_job=”myapp”, instance=”10.244.1.155:9091”, job=”prometheus-pushgateway”, pushgateway=”prometheus-pushgateway”, tier=”cluster”} 3.14

text test_metric{container=”prometheus-pushgateway”, env=”dev”, exported_job=”myapp”, instance=”10.244.1.155:9091”, job=”prometheus-pushgateway”, pushgateway=”prometheus-pushgateway”, tier=”cluster”} 3.14

Название job (в примере — myapp) будет доступно в Prometheus в лейбле exported_job, а не job (так как лейбл job уже занят в Prometheus, он переименовывается при приеме метрики от PushGateway).

The job name (myapp in the example) will be available in Prometheus in the label exported_job, and not job (because the label job already exists in Prometheus and is renamed when receiving metrics from PushGateway).

Возможно, вам потребуется получить список всех имеющихся job для выбора уникального названия (чтобы не испортить существующие графики и алерты). Получить список всех имеющихся job можно следующим запросом: count({__name__=~".+"}) by (job).

You may need to get a list of all available job names to choose a unique name (in order not to spoil existing graphs and alerts). Use the following query to get a list of all existing jobs: count({__name__=~".+"}) by (job).

Удаление метрик

Deleting metrics

Пример удаления всех метрик группы {instance="10.244.1.155:9091",job="myapp"} через curl:

An example of deleting all metrics of a group {instance="10.244.1.155:9091",job="myapp"} using curl:

shell curl -X DELETE http://first.kube-prometheus-pushgateway:9091/metrics/job/myapp/instance/10.244.1.155:9091

shell curl -X DELETE http://first.kube-prometheus-pushgateway:9091/metrics/job/myapp/instance/10.244.1.155:9091

Так как PushGateway хранит полученные метрики в памяти, при рестарте пода все метрики будут утеряны.

Since PushGateway stores the scraped metrics in memory, all metrics will be lost when the Pod is restarted.