准备工作
下载
wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
官方文档
https://songjiayang.gitbooks.io/prometheus/content/
第三方exporter
,本次示例只以node_exporter
为例
https://prometheus.io/docs/instrumenting/exporters/
启动node_exporter
-
解压
tar.gz
的包,并放到/usr/local/
下tar xzvf node_exporter-1.0.1.linux-amd64.tar.gz mv node_exporter-1.0.1.linux-amd64 /usr/local/node_exporter
-
编写
systemd
配置文件[root@home prometheus]$ cat /etc/systemd/system/node_exporter.service [Unit] Description=Node_exporter After=network.target [Service] Type=simple ExecStart=/usr/local/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target
-
启动
node_export
systemctl daemon-reload && systemctl start node_exporter && systemctl status node_exporter
启动prometheus
-
解压
tar.gz
的包,并放到/usr/local/
目录下tar xzvf prometheus-2.19.2.linux-amd64.tar.gz && mv prometheus-2.19.2.linux-amd64 /usr/local/prometheus
-
配置
prometheus.yml
文件# A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. 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'] ## 如果需要增加额外的exporter,直接在该文件中填写以下2行,重启prometheus即可 - job_name: 'node_exporter' static_configs: - targets: ['localhost:9100']
-
编写
systemd
文件root@home local]$ cat /etc/systemd/system/prometheus.service [Unit] Description=Prometheus Documentation=https://prometheus.io/ After=network.target [Service] Type=simple ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/data Restart=on-failure [Install] WantedBy=multi-user.target
-
启动
prometheus
systemctl daemon-reload && systemctl start prometheus && systemctl status prometheus
启动grafana
-
下载
grafana
的rpm
包wget https://dl.grafana.com/oss/release/grafana-7.1.0-1.x86_64.rpm && yum localinstall grafana-7.1.0-1.x86_64.rpm
-
启动
grafana
systemctl daemon-reload && systemctl start grafana-server
-
登录
grafana
,并设置prometheus
为数据源 -
查看
dashborad
,并导入好看的dashboard
,好看的dashboard
可以去官网找