promethus基础
1.下载prometheus并解压
主要配置prometheus.yml文件
在scrape_configs配置项下添加配置(hadoop202是主机名):
scrape_configs:
- job_name: ‘prometheus’
static_configs:- targets: [‘hadoop202:9090’]
添加 PushGateway 监控配置
- job_name: ‘pushgateway’
static_configs:- targets: [‘hadoop202:9091’]
-
instance: pushgatewaylabels:
添加 Node Exporter 监控配置
- job_name: ‘node exporter’
static_configs:- targets: [‘hadoop202:9100’, ‘hadoop203:9100’, ‘hadoop204:9100’]
解压启动node_exporter后,浏览器可访问该地址。
- targets: [‘hadoop202:9100’, ‘hadoop203:9100’, ‘hadoop204:9100’]
设置node_exporter开机自启动并分发给另外的机器
创建service文件node_exporter.service修改执行地址
[atguigu@hadoop202 module] sudo vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=atguigu
ExecStart= /opt/module/node_exporter-1.2.2/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
设为开机自启动(所有机器都执行)
[atguigu@hadoop202 module] sudo systemctl enable node_exporter.service
启动服务(所有机器都执行)
[atguigu@hadoop202 module] sudo systemctl start node_exporter.service
2.后台启动prometheus
nohup ./prometheus --config.file=./prometheus.yml
启动完成http://192.168.126.5:9090/可以访问
启动pushgateway—:9091前边记得加空格
nohup ./pushgateway --web.listen-address :9091 > .pushgateway.log 2>&1 &
启动后状态全部正常
3.promql简单查询–瞬时向量,也可以通过正则表达式查询
4.时间向量–5h表示5小时内的
5时间位移操作–统计前一天的数据(5小时)
6.聚合操作
sum(prometheus_http_requests_total)
7.正则匹配多个值
prometheus_http_requests_total{code=~“302|400”}
8.启动grafana
访问grafana
http://192.168.126.5:3000/
默认密码admin