Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up Monitoring in Prometheus

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to build monitoring in Prometheus. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Prometheus (Prometheus)

Lab environment: (each host, ip, required services)

Docker01 docker02 docker03

1.10 1.20 1.30

NodeEXporter NodeEXporter NodeEXporter

CAdvisor cAdvisor cAdvisor

Prometheus Server

Grafana

Turn off all firewalls and disable selinux.

[root@docker01 ~] # systemctl stop firewalld

[root@docker01 ~] # systemctl disable firewalld

[root@docker01 ~] # setenforce 0

Setenforce: SELinux is disabled

Components need to be deployed:

Prometheus Server: the main server of Prometheus.

NodeEXporter: responsible for collecting Host hardware information and operating system information.

CAdvisor: responsible for collecting container information running on Host.

Grafana: responsible for displaying the Prometheus monitoring interface.

1. Import Mirror

Docker01:

[root@docker01 ~] # docker load

< mycadvisor.tar && docker load < grafana.tar && docker load < node-exporter.tar && docker load < prometheus.tar docker02: [root@docker02 ~]# docker load < mycadvisor.tar && docker load < node-exporter.tar docker03:

[root@docker03 ~] # docker load < mycadvisor.tar & & docker load < node-exporter.tar

Mirror pull complete!

1) 3 nodes, all deploy node-EXporter and cAdvisor.

Do it all on PS:3, go to the browser for verification.

Deploy node-EXporter to collect hardware and system information

[root@docker01 ~] # docker run-d-p 9100vis9100-v / proc:/host/proc-v / sys:/host/sys-v /: / rootfs-- net=host prom/node-exporter-- path.procfs / host/proc-- path.sysfs / host/sys-- collector.filesystem.ignored-mount-points "^ / (sys | proc | dev | host | etc) ($| /)

PS: notice that-- net=host is used here so that Prometheus Server can communicate directly with Node-Exporter.

Verification: open the browser verification result: ip plus port 9100:

/ / deploy and install cAdvisor. Collect node container information.

Do it all on PS:3, go to the browser for verification.

[root@docker01] # docker run-v /: / rootfs:ro-v / var/run:/var/run/:rw-v / sys:/sys:ro-v / var/lib/docker:/var/lib/docker:ro-p 8080pur808080-- detach=true-- name=cadvisor-- net=host google/cadvisor

After the deployment is completed, the browser accesses: IP plus port 8080:

2) deploy the Prometheus Server service on docker01.

Before deploying Prometheus, we need to modify its configuration file, so let's run a container and copy its configuration file first.

[root@docker01] # docker run-d-p 9090 name prometheus-- net=host prom/prometheus

[root@docker01 ~] # docker cp prometheus:/etc/prometheus/prometheus.yml. /

[root@docker01 ~] # vim prometheus.yml

Change line 28 to:

-targets: ['localhost:9090','localhost:8080','localhost:9100','192.168.1.20:8080','192.168.1.20:9100','192.168.1.30:8080','192.168.1.30:9100']

Ip, port of each node

PS: the monitoring items of prometheus are established here, including that it also monitors the data collected by itself.

[root@docker01] # docker rm-f prometheus

Prometheus

[root@docker01] # docker run-d-p 9090 name prometheus-- net=host-v / root/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

Internet access authentication: docker01 ip plus port 9090:

PS: you can check our various monitoring items here.

After suspending docker02:

After continuing to run docker02:

3) on docker01, deploy the grafana service to display the data collected by prometheus.

[root@docker01 ~] # mkdir grafana-storage

[root@docker01] # chmod 777-R grafana-storage/

[root@docker01] # docker run-d-p 3000 GF_SECURITY_ADMIN_PASSWORD=123.com 3000-name grafana- v / root/grafana-storage:/var/lib/grafana-e "GF_SECURITY_ADMIN_PASSWORD=123.com" grafana/grafana

Browser access authentication:

Account: admin

Password: 123.com

PS: see this, indicating that the prometheus and grafana services are connected normally.

At this time, although granfana collected the data, but how to display it is still a problem, gafana supports custom display information, but it is very troublesome to customize, but fortunately, granfana officially provides us with some templates for us to use.

Granfana official website:

Https://grafana.com/docs/grafana/latest/

Select a template, and then we have 2 ways to apply this template.

The first way: use the template through the JSON file.

After the download is complete, put it on the desktop and go to the grafana console

The second way to import templates:

You can use the ID number of the template directly.

Template ID:

With 10619

Go back to the grafana console.

Accident:

Bring your own template:

This is the end of the article on "how to build Prometheus monitoring". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report