prometheus+grafana监控Linux之Prometheus(六)
一、下载
下载地址:https://prometheus.io/download/#prometheus
二、安装(默认端口9090)
将下载好的Prometheus 拷贝并安装在/jiankong/app目录下
# mkdir /jiankong/app
# tar xvfz prometheus-*.tar.gz
三、修改配置文件
将需要监控的机器配在prometheus.yml中,前提是安装好了相应的监控软件(不建议使用localhost,建议使用具体ip)
监控ip不要随意改动。如果修改ip,运行之后Prometheus数据库中会存有原ip的数据,导致grafana面板中会偶现原ip,如果修改了ip,建议删除Prometheus数据库后再重新运行
- job_name: 'prometheus'
static_configs:
- targets: ['162.244.0.52:9090']
- job_name: 'node'
static_configs:
- targets: ['162.244.0.175:9100']
labels:
alias: Node_I_Bridge-02
- targets: ['162.244.0.42:9182']
labels:
alias: Win_C_Render-02
- job_name: 'cadvisor'
static_configs:
- targets: ['162.244.0.175:9100']
labels:
alias: Node_I_Bridge-02
- targets: ['162.244.0.42:9182']
labels:
alias: Win_C_Render-02
- job_name: ' pushgateway '
static_configs:
- targets: ['162.244.0.175:9100']
labels:
alias: Node_I_Bridge-02
- job_name: ' Windows '
static_configs:
- targets: ['162.244.0.52:9182']
labels:
alias: windoes1
四、运行
# cd /jiankong/app/prometheus
# ./prometheus --config.file=prometheus.yml --web.enable-lifecycle &
启动命理参数解释:
- –config.file=prometheus.yml
运行就读取prometheus.yml这个文件(这是默认运行就会加载的配置,可以不用写`;如果修改了prometheus.yml的名字为prometheus2.yml,则需要加–config.file=prometheus2.yml)
2.-web.enable-lifecycle
加上该参数时,重启Prometheus就很容易,使用下面命令就能进行配置文件的热加载
#curl -X POST http://PrometheusIP端口/-/reload
3.&
后台运行
4,更多参数使用./prometheus --help命令查看
五、访问
访问http://prometheusIP:端口/targets

六、重启prometheus方法
6.1 运行时没启用–web.enable-lifecycle 参数(在特定目录下运行)
①如果prometheus正在命令窗口运行的话,直接Ctrl+c结束运行,然后重新运行
②#ps -ef | grep prome 找到pid
#kill -9 pid
重新启动:在prometheus目录下运行./prometheus --config.file=prometheus.yml
6.2 运行时启用–web.enable-lifecycle 参数(在任意目录下运行)
#curl -X POST http://localhost:9090/-/reload
(如prometheus修改了端口,请自行修改上面的端口)
七、查询
访问http://prometheusIP:端口/graph


本文详细介绍了如何使用Prometheus和Grafana监控Linux系统,包括下载、安装Prometheus,配置监控目标,运行Prometheus服务,访问监控目标,以及如何重启Prometheus和查询监控数据。
2376

被折叠的 条评论
为什么被折叠?



