Technology sharing

Prometheus Grafana monitores Linux

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1. Install Promethei

1.1.

Download URL

https://github.com/prometheus/prometheus/releases
  • 1

Lego requiritur versionem

wget https://github.com/prometheus/prometheus/releases/download/v2.53.0/prometheus-2.53.0.linux-amd64.tar.gz
  • 1

1.2.

1.2.1.

groupadd prometheus
useradd -g prometheus -m -s /sbin/nologin prometheus
  • 1
  • 2

1.2.2.

tar -zxvf prometheus-2.53.0.linux-amd64.tar.gz
mv prometheus-2.53.0.linux-amd64 /usr/local/prometheus
sed -i 's/localhost/ 172.25.0.166/g' /usr/local/prometheus/prometheus.yml
  • 1
  • 2
  • 3

1.2.3.

vim /etc/profile
  • 1
export PROMETHEUS_HOME=/usr/local/prometheus
PATH=$PATH:$PROMETHEUS_HOME
export PATH
  • 1
  • 2
  • 3

Reload systema environment variabilis lima

source /etc/profile

  • 1
  • 2

1.2.4.

prometheus --version	
  • 1

1.2.5.

mkdir /usr/local/prometheus/data/
  • 1

1.2.6

chown -R prometheus.prometheus /usr/local/prometheus
  • 1

1.2.7.

cd /usr/local/prometheus/
./promtool check config prometheus.yml
  • 1
  • 2

1.2.8.

cat <<EOF > /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/data/ --web.enable-lifecycle --storage.tsdb.retention.time=30d
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

Parameter notas:

  • config.file: speciem configuratione file
  • web.enable-lifecycle: subsidia reloading configuratione per http petitionem
  • storage.tsdb.path: Specificare notitias repositionis directorium (default indicis indicis hodiernae, si non existit, novam creare)
  • storage.tsdb.retention.time: speciem data retentionis tempore (default 15d)

1.2.9.

systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus && systemctl enable prometheus
  • 1
  • 2
  • 3

1.2.10.

ss -lnput | grep 9090
  • 1
tcp     LISTEN   0        512                    *:9090                *:*       users:(("prometheus",pid=20863,fd=7))
  • 1

1.2.11.

http://172.25.0.166:9090/metrics
  • 1

Insert imaginem descriptionis hic


2. Monitor exercituum Linux

2.1.

2.1.1

Download URL

https://github.com/prometheus/node_exporter/releases
  • 1

Download requiritur versionem

wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
  • 1

2.1.2.

groupadd prometheus
useradd -g prometheus -m -s /sbin/nologin prometheus
  • 1
  • 2

2.1.3.

tar -zxvf node_exporter-1.8.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.8.1.linux-amd64  node_exporter
  • 1
  • 2
  • 3

2.1.4.

chown -R prometheus.prometheus /usr/local/node_exporter
  • 1

2.1.5.

vim /etc/profile
  • 1
export NODE_EXPORTER=/usr/local/node_exporter
export PATH=$PATH:$NODE_EXPORTER
export PATH
  • 1
  • 2
  • 3

Reload systema environment variabilis lima

source /etc/profile
  • 1

2.1.6

cat > /usr/lib/systemd/system/node_exporter.service <<EOF

[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

2.1.7.

systemctl daemon-reload
systemctl enable node_exporter && systemctl start node_exporter
systemctl status node_exporter
  • 1
  • 2
  • 3

2.1.8.

ss -lnput | grep 9100
  • 1
tcp     LISTEN   0        512                    *:9100                *:*       users:(("node_exporter",pid=21904,fd=3))
  • 1

2.2.

Prometheus mutare configuratione file

vim /usr/local/prometheus/prometheus.yml
  • 1
scrape_configs:
... 
  - job_name: 'Linux Node'					# 添加监控项的名字
    static_configs:							
      - targets: ['172.25.0.166:9100']		# 监控主机的ip地址和端口号
  • 1
  • 2
  • 3
  • 4
  • 5

Sileo prometheus ministerium

systemctl restart prometheus
  • 1

2.3.

http://172.25.0.166:9090/targets?search=&scrapePool=Linux+Node
  • 1

Insert imaginem descriptionis hic

http://172.25.0.166:9100/metrics
  • 1

Insert imaginem descriptionis hic


3 usus Grafana ad ostentationem notitia

3.1.

Download URL

https://grafana.com/grafana/download
  • 1

Download requiritur versionem

wget  https://dl.grafana.com/enterprise/release/grafana-enterprise-11.1.0-1.x86_64.rpm
  • 1

3.2.

rpm -ivh grafana-enterprise-11.1.0-1.x86_64.rpm
  • 1

3.3.

systemctl daemon-reload 
systemctl enable grafana-server && systemctl start grafana-server
  • 1
  • 2

3.4, grafana cultura Sinica

vim /etc/grafana/grafana.ini
  • 1
[users]
# 设置默认语言为中文 
default_language = zh-Hans
  • 1
  • 2
  • 3

Sileo servitium

systemctl restart grafana-server
  • 1

3.5.

https://grafana.com/grafana/dashboards/15172-node-exporter-for-prometheus-dashboard-based-on-11074/
  • 1

Insert imaginem descriptionis hic

3.6

grafana-cli plugins install grafana-piechart-panel
  • 1

or *

tar -xvf grafana-piechart-panel.tar.gz
mv grafana-piechart-panel /var/lib/grafana/plugins/grafana-piechart-panel
  • 1
  • 2

3.7.

Insert imaginem descriptionis hic


4. References

https://prometheus.io/
https://blog.csdn.net/heian_99/article/details/1269899356
https://www.cnblogs.com/saneri/p/14667301.html
https://blog.csdn.net/qq_31725371/article/details/114697770