Monitoring (Prometheus) usage

monitor

Monitoring is to help us in real-time to monitor or detect whether the services we deploy are running normally

Commonly used monitoring

zabbix (database-based)

  • The components are relatively complete, the shortcomings are not high
  • When the data of a table in the database exceeds 2000W, the database performance drops sharply

Alibaba Cloud Cloud Monitoring

Tencent Cloud Blue Whale Monitoring

Prometeus (prometeus)

  • The performance is relatively high, the bottom layer uses a time series database
  • Native support for monitoring containers

prometheus deployment

Official website: https://prometheus.io/

Download link: https://github.com/prometheus/prometheus/releases/download/v2.27.1/prometheus-2.27.1.linux-amd64.tar.gz

Prometheus monitoring process

Prometheus monitoring is divided into two situations:
1. Services that carry metrics interface (kubernetes, ETCD, docker)
2. Services that do not carry mertrics interface (nginx, mysql, linux host) are for services that do not carry metrics interface. We need to install an exporter plugin.

# 下载
[[email protected] opt]# wget https://github.com/prometheus/prometheus/releases/download/v2.27.1/prometheus-2.27.1.linux-amd64.tar.gz

# 解压
[[email protected] opt]# tar -xf prometheus-2.25.0.linux-amd64.tar.gz -C /usr/local/

# 建立超链接
[[email protected] local]# ln -s /usr/local/prometheus-2.25.0.linux-amd64 /usr/local/prometheus

# 创建环境变量
[[email protected] local]# cat >> /etc/profile <<EOF
export PROMETHEUS_HOME=/usr/local/prometheus
PATH=$PATH:$PROMETHEUS_HOME
export PATH
EOF
[[email protected] ~]# source /etc/profile

# 测试
[[email protected] ~]# prometheus --version
prometheus, version 2.25.0 (branch: HEAD, revision: a6be548dbc17780d562a39c0e4bd0bd4c00ad6e2)
  build user:       [email protected]
  build date:       20210217-14:17:24
  go version:       go1.15.8
  platform:         linux/amd64

Use Prometheus to monitor a Linux host

web server

# 下载
[[email protected] opt]# wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz

[[email protected] opt]# tar -xf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/

[[email protected] local]# ln -s /usr/local/node_exporter-1.1.2.linux-amd64/ /usr/local/node_exporter

export NODE_EXPORTER=/usr/local/node_exporter
export PATH=$PATH:$NODE_EXPORTER

[[email protected] ~]# source /etc/profile
[[email protected] ~]# node_exporter 

prometheus host
[[email protected] prometheus]# vim /usr/local/prometheus/prometheus.yml

...........
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'web01'
    static_configs:
      - targets: ['192.168.1.7:9100'] 
     
[[email protected] prometheus]# prometheus --config.file=/usr/local/prometheus/prometheus.yml
最后一段出现以下内容即为正确   level=info ts=2021-06-02T02:49:57.047Z caller=main.go:959 msg="Completed loading of configuration file" filename=/usr/local/prometheus/prometheus.yml totalDuration=2.682531ms remote_storage=25.802µs web_handler=457ns query_engine=17.121µs scrape=1.593395ms scrape_sd=99.713µs notify=77.917µs notify_sd=11.912µs rules=18.563µs
level=info ts=2021-06-02T02:49:57.047Z caller=main.go:751 msg="Server is ready to receive web requests."

Finally, enter the ip + port number of the prometheus host in the browser: http://192.168.1.71:9090/ If the following interface appears, it means success.

Insert picture description here


Click status—>targets and the following interface will appear

Insert picture description here

Add a more intuitive and beautiful screen for monitoring (grafana)

1. Download grafanna to the prometheus host (here I uploaded it from the desktop to the prometheus host)
[[email protected] opt]# ls
grafana-7.3.6-1.x86_64.rpm

2. Install grafana
[[email protected] opt]# yum install -y grafana-7.3.6-1.x86_64.rpm

3. Start grafana
[[email protected] ~]# systemctl start grafana-server.service

4. Check if the port is open
[[email protected] ~]# netstat
-ntlp tcp6 0 0 :::3000 ::😗 LISTEN 7503/grafana-server

5. The browser visits
http://192.168.1.71:3000/ and the
following interface appears, which means success. Enter the account admin and the password admin to log

Insert picture description here


in. After changing the password, log in and

Insert picture description here


click the settings button on the left -------》Click on datasources- ------->Click add datasource---------->After clicking prometheus and

Insert picture description here


clicking save, the browser visits the official website of grafana: https://grafana.com/grafana/click

Insert picture description here


dashboard, as shown in the figure Show, choose the template you like

Insert picture description here


Insert picture description here


Click on the arrow, then click import,

Insert picture description here


click load------>click import to

Insert picture description here


Insert picture description here


dry it! To be continued

prometheus monitoring database