共计 1131 个字符,预计需要花费 3 分钟才能阅读完成。
一、Prometheus 下载安装
1、prometheus 启动命令
/home/service/prometheus/prometheus --config.file=/home/service/prometheus/prometheus.yml --storage.tsdb.path=/home/service/prometheus/prometheus-data --storage.tsdb.retention.time=7d
2、prometheus.yml 配置文件
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).
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
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: ['172.17.0.12:9090']
- job_name: 'node'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['172.17.0.12:9100']
**3、在本机能够启动一个 node exporter,用于下文测试,通过 http://127.0.0.1:9100/metrics 验证 node exporter 是否启动胜利
**
二、PromQL 根本语法
1、Prometheus 默认启动端口是 9090,通过浏览器即可拜访 prometheus 的 graph 页面;
2、计算每台主机在五分钟内的 cpu 均匀使用率
(1-(avg(irate(node_cpu_seconds_total{cpu='0',mode='idle'}[5m])))) * 100
正文完