prometheus
下载地址
- prometheus.io/download/
启动/停止
# 解压目录
~/monitor/prometheus/prometheus-2.45.0.linux-amd64
# 编写启动脚本
echo ' ./prometheus --config.file=./prometheus.yml &' > start.sh && chmod +x start.sh
# 编写停止脚本
echo ' pkill prometheus' > stop.sh && chmod +x stop.sh
# 启动
nohup sh start.sh &
配置文件
cat prometheus.yml
# 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"]
# 采集node exporter监控数据
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
- job_name: 'your application'
scheme: https
tls_config:
insecure_skip_verify: true
static_configs:
- targets: [ 'localhost:9098' ]
labels:
application: 'your application'
注意:由于应用程序开启了https,可以简单通过tls_config跳过验证
验证
prometheus自带了前段页面。
可以在浏览器中输入:localhost:9090
打开。记得打开9090端口的访问权限
。
grafna
下载
- grafana.com/grafana/dow…
- 两种文件格式,任选其一。tar.gz是二进制文件,可以直接执行。本文使用的是二进制文件。关于rpm的安装与启动,参考文末文档。
启动/停止
cd ~/monitor/grafana
nohup ./bin/grafana server &
访问
在浏览器输入localhost:3000
。
会提示输入账号密码,默认都是admin。然后修改一下密码。
配置数据源
选择prometheus作为数据源
输入prometheus的地址
http方法改为get,保存
选择一个dashbboard
然后就能看到效果了。
node-exporter
下载
- prometheus.io/download/#n…
安装/启动/停止
cd ~/monitor/prometheus/node_exporter-1.6.1.linux-amd64
# 编写启动脚本
echo ' ./node_exporter &' > start.sh && chmod +x start.sh
# 编写停止脚本
echo ' pkill node_exporter ' > stop.sh && chmod +x stop.sh
nohup sh start.sh &
配置prometheus.yml
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"]
# 采集node exporter监控数据
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
配置grafana dashboard
- grafana.com/grafana/das…
拷贝模版号
- 在grafana导入模版
输入拷贝的模板号,点击load
选择数据源,点击import
查看效果
参考
-Prometheus+Grafana 监控服务器CPU、磁盘、内存等信息
-Configure Prometheus AlertManager
-Prometheus+Grafana+Alertmanager部署教程
-Systemd 入门教程:实战篇