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
Next revision Both sides next revision
сервис_prometheus [2021/04/19 13:35]
val [Установка в Debian 10]
сервис_prometheus [2022/02/23 16:38]
val [prometheus-snmp-exporter]
Line 5: Line 5:
   * [[https://​www.shellhacks.com/​ru/​prometheus-delete-time-series-metrics/​|Prometheus:​ Удаление Метрик Временных Рядов]]   * [[https://​www.shellhacks.com/​ru/​prometheus-delete-time-series-metrics/​|Prometheus:​ Удаление Метрик Временных Рядов]]
  
-===== Установка в Debian ​10 ===== +===== Установка в Debian/​Ubuntu ​=====
- +
-  * [[Сервис MTA#​Установка и настройка MTA на обработку почты домена hostname]]+
  
 <​code>​ <​code>​
 # apt install prometheus # apt install prometheus
 +
 +# less /​etc/​prometheus/​prometheus.yml
 +</​code><​code>​
 +...
 +global:
 +  scrape_interval: ​    15s
 +...
 </​code>​ </​code>​
  
Line 18: Line 23:
 # promtool check config /​etc/​prometheus/​prometheus.yml # promtool check config /​etc/​prometheus/​prometheus.yml
  
-service prometheus restart+service prometheus restart
 </​code>​ </​code>​
  
Line 24: Line 29:
  
   * [[http://​server.corpX.un:​9090/​targets]]   * [[http://​server.corpX.un:​9090/​targets]]
 +  * [[http://​server:​9090/​classic/​targets]]
   * [[http://​192.168.X.10:​9090/​metrics]]   * [[http://​192.168.X.10:​9090/​metrics]]
   * [[http://​10.5.N.100+X:​9090/​graph]]   * [[http://​10.5.N.100+X:​9090/​graph]]
Line 36: Line 42:
   * [[https://​www.digitalocean.com/​community/​tutorials/​how-to-use-alertmanager-and-blackbox-exporter-to-monitor-your-web-server-on-ubuntu-16-04|How To Use Alertmanager And Blackbox Exporter To Monitor Your Web Server On Ubuntu 16.04]]   * [[https://​www.digitalocean.com/​community/​tutorials/​how-to-use-alertmanager-and-blackbox-exporter-to-monitor-your-web-server-on-ubuntu-16-04|How To Use Alertmanager And Blackbox Exporter To Monitor Your Web Server On Ubuntu 16.04]]
   * [[https://​awesome-prometheus-alerts.grep.to/​|Awesome Prometheus alerts]]   * [[https://​awesome-prometheus-alerts.grep.to/​|Awesome Prometheus alerts]]
 +
 +  * [[Сервис MTA#​Установка и настройка MTA на обработку почты домена hostname]]
  
 <​code>​ <​code>​
Line 47: Line 55:
   smtp_from: '​prometheus@server.corpX.un'​   smtp_from: '​prometheus@server.corpX.un'​
   smtp_require_tls:​ false   smtp_require_tls:​ false
 +#  smtp_auth_username:​ '​alertmanager'​
 +#  smtp_auth_password:​ '​password'​
 ... ...
   # A default receiver   # A default receiver
Line 54: Line 64:
 - name: '​team-X-mails'​ - name: '​team-X-mails'​
   email_configs:​   email_configs:​
-  ​send_resolved:​ true +#  ​- to: '​student@corpX.un'​ 
-    ​to: '​student@corpX.un'​+#  - to: '​userX@isp.un'​ 
 +    send_resolved:​ true
 ... ...
 </​code><​code>​ </​code><​code>​
 +# service prometheus-alertmanager restart
 +
 # cat /​etc/​prometheus/​first_rules.yml # cat /​etc/​prometheus/​first_rules.yml
 </​code><​code>​ </​code><​code>​
Line 103: Line 116:
  
 ... ...
-</code><​code> +</​code>​ 
-promtool check config /​etc/​prometheus/​prometheus.yml + 
-</​code>​<​code>​+  * [[#Проверка конфигурации и перезапуск]] 
 + 
 +<​code>​
 ... ...
 Checking /​etc/​prometheus/​first_rules.yml Checking /​etc/​prometheus/​first_rules.yml
Line 111: Line 126:
 ... ...
 </​code>​ </​code>​
 +
 +  * [[http://​server.corpX.un:​9090/​alerts]]
 ===== Exporters ===== ===== Exporters =====
  
Line 126: Line 143:
 /​dev/​mapper/​debian--vg-root ​ 15662008 1877488 ​ 12969212 ​ 13% / /​dev/​mapper/​debian--vg-root ​ 15662008 1877488 ​ 12969212 ​ 13% /
 ... ...
 +# TYPE node_filesystem_free_bytes gauge
 node_filesystem_free_bytes{device="/​dev/​mapper/​debian--vg-root",​fstype="​ext4",​mountpoint="/"​} = (15662008 - 1877488) * 1024  node_filesystem_free_bytes{device="/​dev/​mapper/​debian--vg-root",​fstype="​ext4",​mountpoint="/"​} = (15662008 - 1877488) * 1024 
 </​code>​ </​code>​
Line 133: Line 150:
 <​code>​ <​code>​
 $ cat /​sys/​class/​net/​eth1/​statistics/​rx_bytes $ cat /​sys/​class/​net/​eth1/​statistics/​rx_bytes
 +  или
 +$ cat /​sys/​class/​net/​bond0/​statistics/​rx_bytes
  
 +# TYPE node_network_receive_bytes_total counter
 node_network_receive_bytes_total{device="​eth1"​} node_network_receive_bytes_total{device="​eth1"​}
 </​code>​ </​code>​
Line 163: Line 183:
   * [[https://​geekflare.com/​monitor-website-with-blackbox-prometheus-grafana/​|How to Monitor Website Performance with Blackbox Exporter and Grafana?]]   * [[https://​geekflare.com/​monitor-website-with-blackbox-prometheus-grafana/​|How to Monitor Website Performance with Blackbox Exporter and Grafana?]]
   * [[https://​habr.com/​ru/​company/​otus/​blog/​500448/​|Prometheus:​ мониторинг HTTP через Blackbox экспортер]]   * [[https://​habr.com/​ru/​company/​otus/​blog/​500448/​|Prometheus:​ мониторинг HTTP через Blackbox экспортер]]
-  * [[https://​www.robustperception.io/​icmp-pings-with-the-blackbox-exporter|ICMP Pings with the Blackbox exporter]], [[https://​github.com/​prometheus/​blackbox_exporter|github blackbox_exporter]],​ [[POSIX capabilities]] или [[Управление ядром и модулями в Linux#​Переменные ядра]] 
  
-=== Пример статической конфигурации === 
 <​code>​ <​code>​
 # apt install prometheus-blackbox-exporter # apt install prometheus-blackbox-exporter
 +</​code>​
  
 +=== Пример конфигурации ===
 +<​code>​
 # cat /​etc/​prometheus/​blackbox.yml # cat /​etc/​prometheus/​blackbox.yml
 </​code><​code>​ </​code><​code>​
Line 182: Line 203:
 # cat /​etc/​prometheus/​prometheus.yml # cat /​etc/​prometheus/​prometheus.yml
 </​code><​code>​ </​code><​code>​
-  ​- job_name: ​check_ssh+... 
 +  ​- job_name: ​check_http
     metrics_path:​ /probe     metrics_path:​ /probe
     params:     params:
-      module: [ssh_banner]+      module: [http_2xx]
     static_configs:​     static_configs:​
       - targets:       - targets:
-        - switch1:22 +        - https://​google.com 
-        - switch2:22 +        - https://ya.ru
-        - switch3:22+
     relabel_configs:​     relabel_configs:​
       - source_labels:​ [__address__]       - source_labels:​ [__address__]
Line 197: Line 218:
         target_label:​ instance         target_label:​ instance
       - target_label:​ __address__       - target_label:​ __address__
-        replacement: ​127.0.0.1:9115+        replacement: ​localhost:9115
  
-  - job_name: ​check_http+  - job_name: ​check_ssh
     metrics_path:​ /probe     metrics_path:​ /probe
     params:     params:
-      module: [http_2xx]+      module: [ssh_banner]
     static_configs:​     static_configs:​
       - targets:       - targets:
-        - http://​val.bmstu.ru +        - switch1:22 
-        - https://ya.ru+        - switch2:22 
 +        - switch3:22
     relabel_configs:​     relabel_configs:​
       - source_labels:​ [__address__]       - source_labels:​ [__address__]
Line 213: Line 235:
         target_label:​ instance         target_label:​ instance
       - target_label:​ __address__       - target_label:​ __address__
-        replacement: ​127.0.0.1:9115+        replacement: ​localhost:9115
 </​code>​ </​code>​
  
-  * [[http://10.5.7.100+X:9115/]]+  ​* [[#​Проверка конфигурации и перезапуск]] 
 +  ​* [[http://server.corpX.un:9115/]] Blackbox Exporter->​Logs и [[http://​server.corpX.un:​9090/​graph]]
  
 <​code>​ <​code>​
Line 225: Line 248:
 probe_http_duration_seconds... probe_http_duration_seconds...
 </​code>​ </​code>​
-=== Пример ​динамической конфигурации ===+=== Пример использования file-based service discovery и сервиса ping === 
 + 
 +  * [[https://​www.robustperception.io/​icmp-pings-with-the-blackbox-exporter|ICMP Pings with the Blackbox exporter]], [[https://​github.com/​prometheus/​blackbox_exporter|github blackbox_exporter]],​ [[POSIX capabilities]] или [[Управление ядром и модулями в Linux#​Переменные ядра]] 
 <​code>​ <​code>​
 # cat /​etc/​prometheus/​prometheus.yml # cat /​etc/​prometheus/​prometheus.yml
Line 255: Line 281:
 </​code><​code>​ </​code><​code>​
 # cat /​etc/​prometheus/​switchs.yml # cat /​etc/​prometheus/​switchs.yml
 +</​code><​code>​
 - targets: - targets:
   - switch1   - switch1
Line 261: Line 288:
 </​code>​ </​code>​
  
 +  * [[#​Проверка конфигурации и перезапуск]]
 ==== prometheus-snmp-exporter ==== ==== prometheus-snmp-exporter ====
  
Line 307: Line 335:
 </​code><​code>​ </​code><​code>​
 # service prometheus-snmp-exporter restart # service prometheus-snmp-exporter restart
 +</​code>​
  
 +  * [[http://​server.corpX.un:​9116/​]]
 +
 +<​code>​
 # curl --noproxy 127.0.0.1 '​http://​127.0.0.1:​9116/​snmp?​target=router&​module=snmp_in_out_octets'​ # curl --noproxy 127.0.0.1 '​http://​127.0.0.1:​9116/​snmp?​target=router&​module=snmp_in_out_octets'​
 </​code><​code>​ </​code><​code>​
Line 326: Line 358:
         target_label:​ instance         target_label:​ instance
       - target_label:​ __address__       - target_label:​ __address__
-        replacement: ​server:9116 +        replacement: ​localhost:9116 
-</​code>​<​code>​ +</​code>​
-# promtool check config /​etc/​prometheus/​prometheus.yml+
  
-service prometheus restart +  * [[#Проверка конфигурации и перезапуск]] 
-</​code>​<​code>​+ 
 +<​code>​
 rate(if_in_octets{ifDescr="​FastEthernet1/​1",​ifIndex="​3",​instance="​router",​job="​snmp"​}[1m]) rate(if_in_octets{ifDescr="​FastEthernet1/​1",​ifIndex="​3",​instance="​router",​job="​snmp"​}[1m])
 +  или
 +rate(if_in_octets{ifIndex="​5",​instance="​router",​job="​snmp"​}[1m])
  
 8*rate(if_in_octets{ifDescr="​FastEthernet1/​1",​instance="​router"​}[1m]) 8*rate(if_in_octets{ifDescr="​FastEthernet1/​1",​instance="​router"​}[1m])
 +  или
 +8*rate(if_in_octets{ifDescr="​Port-channel1",​instance="​router"​}[1m])
 </​code>​ </​code>​
  
Line 346: Line 382:
 </​code><​code>​ </​code><​code>​
 ... ...
-  - job_name: 'Pushgateway'+  - job_name: 'pushgateway'
     honor_labels:​ true     honor_labels:​ true
     static_configs:​     static_configs:​
     - targets: ['​localhost:​9091'​]     - targets: ['​localhost:​9091'​]
 </​code>​ </​code>​
 +
 +  * [[#​Проверка конфигурации и перезапуск]]
 ==== Пример prometheus pushgateway на bash ==== ==== Пример prometheus pushgateway на bash ====
  
Line 372: Line 410:
 </​code><​code>​ </​code><​code>​
 ip_dhcp_binding{dhcp_server="​router",​job="​cisco_dhcp",​net="​192.168"​} ip_dhcp_binding{dhcp_server="​router",​job="​cisco_dhcp",​net="​192.168"​}
 +</​code><​code>​
 +# crontab -l
 +</​code><​code>​
 +* * * * * /​root/​ip_dhcp_binding.sh
 </​code>​ </​code>​
сервис_prometheus.txt · Last modified: 2024/06/28 10:19 by val