环境:Centos7,Supervisor持久化运行
下载以及安装Grafana,需要放通3000
端口用于Grafana的网页后台控制。(IP:3000)
wget https://dl.grafana.com/oss/release/grafana-8.0.3-1.x86_64.rpm
sudo yum install grafana-8.0.3-1.x86_64.rpm
用.deb
或.rpm
安装完成之后可以用systemd
或init.d
控制。
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server
登入后台,默认用户名密码admin
,首次登录会被要求强制修改密码。
安装Prometheus,找到最新版,截至目前是2.28.0 https://github.com/prometheus/prometheus/releases/
(外网访问需要放通9090端口)
wget https://github.com/prometheus/prometheus/releases/download/v2.28.0-rc.0/prometheus-2.28.0-rc.0.linux-amd64.tar.gz
tar -xzvf prometheus-2.28.0-rc.0.linux-amd64.tar.gz
cd prometheus-2.28.0-rc.0.linux-amd64
编辑prometheus.yml
文件,官方默认配置文件如下,默认监控Prometheus自身。
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.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=` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
#全局时间间隔
scrape_interval: 15s
#规则扫描时间间隔
evaluation_interval: 15s
#超时时间
scrape_timeout: 5s
更详细的可以参考官方文档:https://prometheus.io/docs/prometheus/latest/configuration/configuration/
./prometheus
网页后台:IP:9090
可以看到自身的状态是UP
。
node_exporter就是获取宿主机的资源信息,CPU占用,内存占用等
安装node_exporter,找到最新版,截至目前是1.1.2 https://github.com/prometheus/node_exporter/releases/
(外网访问需要放通9100端口)
wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
tar -xzvf node_exporter-1.1.2.linux-amd64.tar.gz
cd node_exporter-1.1.2.linux-amd64
./node_exporter
Prometheus创建job获取node_exporter的数据,job_name
可以随便取。修改yml文件一定要严格注意格式(缩进)。
- job_name: 'exporter'
static_configs:
- targets: ['localhost:9100']
然后重启Prometheus,网页后台可以看到这个job上线了。
重新回到Grafana网页后台,可以自己创建Dashboard,也可以用现成的。进入官方库:https://grafana.com/grafana/dashboards
也可以用这个:https://grafana.com/grafana/dashboards/8919
复制数字,回到后台,点左侧加号然后Import
,输入数字ID点Load
,VictoriaMetrics
选择Prometheus
,最后Import
即可。