First, the basic environment

Environment/Component version Download address
The operating system CentOS 7.3 Archive.kernel.org/centos-vaul…
Prometheus server Prometheus. IO/download / # p…
go 1.11.4 golang.org/dl/
Grafana 5.4.2 Dl.grafana.com/oss/release…

Install go

1, decompression installation
Tar -c /usr/local/-xvf go1.11.4.linux-amd64.tar.gzCopy the code
2. Configure environment variables
vim /etc/profile

export PATH=$PATH:/usr/local/go/bin

source /etc/profile
Copy the code
3, validation,
go version
Copy the code

Install Prometheus

1, install,
Tar -c /usr/local/-xvf Prometheus -2.6.0.linux-amd64.tar.gz ln -sv /usr/local/prometheus-2.6.0.linux-amd64/ /usr/local/PrometheusCopy the code
2, start,

Prometheus default vim configuration file/usr/local/Prometheus/Prometheus yml

/usr/local/Prometheus/prometheus --config.file=/usr/local/Prometheus/prometheus.yml &
Copy the code
3, validation,

To open the Prometheus monitoring page, open port 9090

Install Grafana

The default Prometheus page may not be as intuitive, but we can install Grafana to make monitoring look more intuitive

1, install,
RPM - the ivh -- nodeps grafana 5.4.2-1. X86_64. RPMCopy the code
2, start,
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server.service
sudo /bin/systemctl start grafana-server.service
Copy the code
3. Visit Grafana

The grafana page will be opened when the browser accesses IP:3000 port. The default user name and password are admin, and the default login password will be changed upon the first login

4. Add Prometheus data source

(1) Click “Add Data Source” on the main screen(2) Select Prometheus(3) Select Prometheus 2.0 Stats on the Dashboards page(4) Settings page fill in the Prometheus address and save(5) Switch to the “Prometheus 2.0 Stats” we just added to see the entire monitoring page

Five, some common monitoring examples

1. Monitor Linux machines (Node-Exporter)

Github.com/prometheus/…

(1) The monitored machine is installed with Node – EXPORTER

Tar -xvf node_exi-0.17.0.linux-amd64.tar. gz -c /usr/local/Copy the code

(2) Start Node – Exporter

/ usr/local/node_exporter - 0.17.0. Linux - amd64 / node_exporter &Copy the code

(3) Add monitoring items to the Prometheus configuration file

vim /usr/local/Prometheus/prometheus.yml
Copy the code

The default Node-exporter port is 9100

  - job_name: 'Prometheus'
    static_configs:
    - targets: ['192.168.0.102:9100']
      labels:
        instance: Prometheus
Copy the code

Restart Prometheus

(4) Grafana imports the drawn dashboard

  • dashboard json
  • Link: pan.baidu.com/s/1Dlm0IHTg… Extraction code: myv6

To change the name, select the data source we created earlier and click ImportGrafana’s default plugin directory is /var/lib/grafana/plugins. You can decompress the downloaded plugin to this directory and restart Grafana

  • Piechart plug-in:
  • Link: pan.baidu.com/s/1tvZWI9vh… Extraction code: TLYL
Service grafana-server restart /usr/sbin/grafana-cli plugins lsCopy the code

Refresh the Grafana page to see the Node monitoring we just set up

2. Monitor Windows machines (WMI-Exporter)

Github.com/martinlindh…

(1) WMI-Exporter is installed on monitored Windows machines and can automatically create a boot self-service service (2) Add configuration items to the Prometheus configuration file

vim /usr/local/Prometheus/prometheus.yml
Copy the code

The default WMI-exporter port is 9182

-job_name: 'Prometheus' static_configs: -targets: ['192.168.0.102:9182']Copy the code

Restart Prometheus

Grafana import the drawn dashboard and select Prometheus data source

  • Link: pan.baidu.com/s/1nfTE2dqc… Extraction code: OHV4

MySQL: mysqlD-exporter

Github.com/prometheus/…

(1) Monitored mysql machines are installed with mysqlD-EXPORTER

Tar -c /usr/local/-xvf mysqLD_xxX-0.11.0.linux-amd64.tar.gzCopy the code

(2) Set the configuration file. User is the database login user, and password is the password of the user

vi .my.cnf

[client]
user=root
password=123456
Copy the code

(3) Start mysqlD-EXPORTER

/ usr/local/mysqld_exporter - 0.11.0. Linux - amd64 / mysqld_exporter -- config. My - CNF = "/ usr/local/mysqld_exporter - 0.11.0. Linux - amd64 /. My. The CNF" &Copy the code

(4) Add mysql monitoring to Prometheus configuration file and restart

vim /usr/local/Prometheus/prometheus.yml
Copy the code

The default mysqlD-exporter port is 9104

-job_name: 'MySQL' static_configs: -targets: ['192.168.0.103:9104']Copy the code

Add mysql data source to grafana interface Add the database to be monitored and related information(6) Import dashboard that has been drawn and select mysql data source that has just been created

  • Link: pan.baidu.com/s/1GBzogDLs… Extraction code: EF6E

4. Monitor Redis (redis_exporter)

Link: pan.baidu.com/s/12y7HxtQl… Extraction code: 13V2

(1) Install redis_exporter

Tar -c /usr/local/-xvf redis_exi-v0.15.0.linux-amd64.tar.gzCopy the code

(2) Start redis_exporter

The default redis_exporter port is 9121

. / redis_exporter redis / / 192.168.0.103:6379 & - web. Listenaddress 192.168.0.103:9121Copy the code

(3) Add Redis monitoring to Prometheus configuration file and restart

vim /usr/local/Prometheus/prometheus.yml
Copy the code

The default redis-exporter port is 9121

- job_name: 'Redis' static_configs: -targets: ['192.168.0.103:9121']Copy the code

(4) Grafana imports the drawn dashboard

  • Link: pan.baidu.com/s/1LIkVC0o3… Extraction code: GF1D

Six, some websites

  • Grafana dashboard:grafana.com/dashboards
  • Grafana plugins:grafana.com/plugins

This paper has participated in the activity of “Newcomer Creation Ceremony”, and started the road of gold creation together