In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to monitor nginx based on prometheus". In daily operation, I believe many people have doubts about how to monitor nginx based on prometheus. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to monitor nginx based on prometheus". Next, please follow the editor to study!
Installation preparation
Nginx server: 172.22.3.164
Prometheus and grafnana are installed on the prometheus host
You can choose two exporter to monitor nginx based on prometheus. One is to obtain the built-in indicators in nginx-status through nginx_exporter. Nginx itself provides status information, which is relatively simple, and there are fewer corresponding metrics in promethues. The other is that more metrics can be monitored through nginx-vts-exporter, but nginx-vts-exporter relies on adding nginx-module-vts modules when compiling nginx. Vts provides information to access the status of the virtual host, including the current status of server,upstream and cache, and obviously the metrics will be richer. This practice mainly introduces the use of nginx-vts-exporter to monitor nginx based on prometheus.
Related installation files
Https://github.com/vozlt/nginx-module-vts/archive/v0.1.18.tar.gzhttps://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
Nginx adds nginx-module-vts support
# cd / opt/nginx-1.19.6# wget https://github.com/vozlt/nginx-module-vts/archive/v0.1.18.tar.gz # tar-zxf v0.1.18.tar.gz## recompile #. / configure-- add-module=nginx-module-vts-0.1.18/# make# cp objs/nginx / usr/local/nginx/sbin/nginx
Modify nginx.conf
Http {vhost_traffic_status_zone; vhost_traffic_status_filter_by_host on; server {listen 10011; server_name localhost; # vhost_traffic_status off; location / nginx_status {vhost_traffic_status_display; vhost_traffic_status_display_format html;}}
After restarting nginx, visit http://172.22.3.164:10011/stub_status
Install nginx-vts-exporter
Install nginx-vts-exporter on the nginx server
# cd / opt/# wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz# tar-zxf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz# cp nginx-vts-exporter-0.10.3.linux-amd64/nginx-vts-exporter / usr/local/bin
Create service
# # create service# vi / usr/lib/systemd/system/nginx-vts-exporter.service [Unit] Description=nginx-vts-exporterDocumentation= https://prometheus.io/After=network.target[Service]Type=simpleUser=rootExecStart=/usr/local/bin/nginx-vts-exporter\-nginx.scrape_timeout 10\-nginx.scrape_uri http://127.0.0.1:10011/nginx_status/format/jsonRestart=on-failure[Install]WantedBy=multi-user.target
Set up automatic start
# systemctl daemon-reload## setup self-boot # systemctl enable nginx-vts-exporterCreated symlink from / etc/systemd/system/multi-user.target.wants/nginx-vts-exporter.service to / usr/lib/systemd/system/nginx-vts-exporter.service. Configure nginx-vts-exporter Monitoring
Modify the prometheus configuration file prometheus.yml and add the following configuration under scrape_configs
-job_name: 'nginx-hosts' file_sd_configs:-files: [' / opt/prometheus/sd_config/nginx-hosts.yml'] refresh_interval: 5s
Add / opt/prometheus/sd_config/docker-hosts.yml file, which is as follows
Cat / opt/prometheus/sd_config/nginx-hosts.yml- targets:-172.22.3.164pur9913
Restart prometheus
# systemctl restart prometheus
Enter http://172.22.3.148:9090/targets in the browser address bar
You can see that targets has increased its monitoring of the service nginx-hosts
Configure the panel to display the monitoring content of the host nginx-hosts in grafana
Click the "+" button to pop up the import panel window
If you enter 2949 in the figure, click Load,grafana to import the panel numbered 2949 directly from the official website as follows
Select the data source Prometheus, continue with "Import", and display the nginx monitoring interface as follows
At this point, the study of "how to monitor nginx based on prometheus" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.