User Tools

Site Tools


сервис_prometheus

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
сервис_prometheus [2026/05/06 11:17]
val
сервис_prometheus [2026/05/14 15:48] (current)
val [prometheus-apache-exporter]
Line 49: Line 49:
  
   * [[Сервис MTA#​Установка и настройка MTA на обработку почты домена hostname]]   * [[Сервис MTA#​Установка и настройка MTA на обработку почты домена hostname]]
 +  * [[Сервис adnanh/​webhook]] 
 +==== Настройка маршрутизации уведомлений ====
 <​code>​ <​code>​
 # apt install prometheus-alertmanager # apt install prometheus-alertmanager
Line 67: Line 68:
   repeat_interval:​ 3h   repeat_interval:​ 3h
   receiver: team-X-mails   receiver: team-X-mails
 +
 +#  routes:
 +#    - matchers:
 +#        - job="​roundcube_monitor"​
 +#      receiver: script-receiver
  
 receivers: receivers:
Line 73: Line 79:
   - to: '​student@corpX.un'​   - to: '​student@corpX.un'​
     send_resolved:​ true     send_resolved:​ true
 +
 +#  - name: '​script-receiver'​
 +#    webhook_configs:​
 +#    - url: '​http://​localhost:​9000/​hooks/​my-alert-script'​
 </​code><​code>​ </​code><​code>​
 +# amtool check-config /​etc/​prometheus/​alertmanager.yml
 +
 # service prometheus-alertmanager restart # service prometheus-alertmanager restart
 +</​code>​
  
 +==== Тестирование alertmanager ====
 +<​code>​
 +$ curl -H "​Content-Type:​ application/​json"​ -d '[
 +  {
 +    "​labels":​ {
 +      "​alertname":​ "​TestAlert",​
 +      "​severity":​ "​critical",​
 +      "​instance":​ "​test-host"​
 +    },
 +    "​annotations":​ {
 +      "​summary":​ "This is a test alert",​
 +      "​description":​ "​Triggered manually via curl to test Alertmanager routing."​
 +    }
 +  }
 +]' http://​localhost:​9093/​api/​v2/​alerts
 +</​code>​
 +==== Подключение готовых правил alertmanager ====
 +
 +  * [[Управление сервисами в Linux#​Управление юнитами Systemd]] reset-failed
 +
 +<​code>​
 +# wget -qO - https://​raw.githubusercontent.com/​samber/​awesome-prometheus-alerts/​master/​dist/​rules/​host-and-hardware/​node-exporter.yml | tee /​etc/​prometheus/​node_exporter_rules.yml
 +</​code>​
 +
 +==== Создание правил alertmanager ====
 +
 +<​code>​
 # cat /​etc/​prometheus/​first_rules.yml # cat /​etc/​prometheus/​first_rules.yml
 </​code><​code>​ </​code><​code>​
Line 105: Line 145:
     annotations:​     annotations:​
       summary: "​CriticalTraffic {{ $labels.instance }}"       summary: "​CriticalTraffic {{ $labels.instance }}"
-</​code><​code>​+ 
 +#  - alert: RoundcubeDown 
 +#    expr: roundcube_login_logout_runtime == 0 
 +#    for: 1m 
 +#    labels: 
 +#      severity: "​critical"​ 
 +#    annotations:​ 
 +#      summary: "​Endpoint {{ $labels.instance }} down"​ 
 +#      dashboard_url:​ "​http://​server.corpX.un:​3000/​.../​refresh=auto"​ 
 +</​code>​ 
 + 
 +==== Подключение Alertmanager к Prometheus ==== 
 +<​code>​
 # cat /​etc/​prometheus/​prometheus.yml # cat /​etc/​prometheus/​prometheus.yml
 </​code><​code>​ </​code><​code>​
Line 119: Line 171:
   - "​first_rules.yml"​   - "​first_rules.yml"​
   # - "​second_rules.yml"​   # - "​second_rules.yml"​
 +  # - "​node_exporter_rules.yml"​
  
 ... ...
Line 133: Line 186:
  
   * [[http://​server.corpX.un:​9090/​classic/​alerts]]   * [[http://​server.corpX.un:​9090/​classic/​alerts]]
 +
 +==== Отладка Alertmanager ====
 +<​code>​
 +# cat /​etc/​default/​prometheus-alertmanager
 +ARGS="​--log.level=debug"​
 +</​code>​
 ===== Exporters ===== ===== Exporters =====
  
Line 404: Line 463:
   или   или
 8*rate(ifOutOctets{ifDescr="​Port-channel1",​instance="​router"​}[1m]) 8*rate(ifOutOctets{ifDescr="​Port-channel1",​instance="​router"​}[1m])
 +</​code>​
 +
 +===== prometheus-apache-exporter =====
 +
 +<​code>​
 +root@server:​~#​ apt install prometheus-apache-exporter
 +
 +root@server:​~#​ prometheus-apache-exporter --scrape_uri="​http://​localhost/​server-status?​auto"​
 +
 +root@server:​~#​ cat /​etc/​default/​prometheus-apache-exporter
 +...
 +ARGS=""​
 +
 +rate(apache_accesses_total[1m])
 </​code>​ </​code>​
  
Line 422: Line 495:
  
   * [[#​Проверка конфигурации и перезапуск]]   * [[#​Проверка конфигурации и перезапуск]]
-==== Пример ​prometheus pushgateway ​на bash ====+==== Отправка ​метрик из приложения ==== 
 + 
 +=== Пример 1 ===
  
   * [[https://​vinayakpandey-7997.medium.com/​pushing-bash-script-result-to-prometheus-using-pushgateway-a0760cd261e|Scrape data using Bash script and push it to Prometheus using PushGateway]]   * [[https://​vinayakpandey-7997.medium.com/​pushing-bash-script-result-to-prometheus-using-pushgateway-a0760cd261e|Scrape data using Bash script and push it to Prometheus using PushGateway]]
Line 447: Line 522:
 </​code><​code>​ </​code><​code>​
 * * * * * /​root/​ip_dhcp_binding.sh * * * * * /​root/​ip_dhcp_binding.sh
 +</​code>​
 +
 +=== Пример 2 ===
 +
 +  * Web интерфейс к почте [[Web интерфейс к почте#​Roundcube]]
 +  * [[Средства программирования shell#​Тестирование Web приложения на shell]]
 +  * [[Технология cgroup]]
 +
 +<​code>​
 +root@server:​~#​ cat /​usr/​local/​bin/​roundcube_monitor_stat_log.sh
 +</​code><​code>​
 +#!/bin/bash
 +
 +start=$(date +%s.%N)
 +/​usr/​local/​bin/​roundcube_monitor.sh 2>&1 | logger -t roundcube_monitor
 +test ${PIPESTATUS[0]} -eq 0 && end=$(date +%s.%N) || end=$start
 +
 +runtime=$(echo "$end - $start"​ | bc)
 +echo "​roundcube_login_logout_runtime ${runtime}"​ | \
 +  curl --data-binary @- http://​localhost:​9091/​metrics/​job/​roundcube_monitor/​host/​$(hostname)
 +echo "​Выполнено за $runtime сек."​
 +</​code><​code>​
 +root@server:​~#​ crontab -l
 +</​code><​code>​
 +* * * * * /​usr/​local/​bin/​roundcube_monitor_stat_log.sh >/​dev/​null
 </​code>​ </​code>​
сервис_prometheus.1778055431.txt.gz · Last modified: 2026/05/06 11:17 by val