ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 示例 启动三个node ``` tar -xzvf node_exporter-*.*.tar.gz cd node_exporter-*.* ./node_exporter --web.listen-address 127.0.0.1:8080 ./node_exporter --web.listen-address 127.0.0.1:8081 ./node_exporter --web.listen-address 127.0.0.1:8082 ``` 假设三个 node 中,两个2生成环境`production`,一个测试环境`canary` ``` scrape_configs: - job_name: 'node' # 覆盖全局默认的参数,并将采样时间间隔设置为 5s scrape_interval: 5s static_configs: - targets: ['localhost:8080', 'localhost:8081'] labels: group: 'production' - targets: ['localhost:8082'] labels: group: 'canary' ``` **配置规则将采集的数据汇总到新的时间序列中 ** 但在临时计算时,汇总了数千个时间序列的查询可能会变慢。为了提高效率,Prometheus 允许通过配置的记录规则将表达式预记录到全新的持久时间序列中 创建 `prometheus.rules.yml:` ``` groups: - name: cpu-node rules: - record: job_instance_mode:node_cpu_seconds:avg_rate5m expr: avg by (job, instance, mode) (rate(node_cpu_seconds_total[5m])) ``` 完整示例 ``` global: scrape_interval: 15s # 默认情况下,每 15s 采集一次目标数据 evaluation_interval: 15s # 每 15s 进行一次规则评估 # 与外部系统通信时,可以将这些标签应用到到和时间序列或告警上 external_labels: monitor: 'codelab-monitor' rule_files: - 'prometheus.rules.yml' scrape_configs: - job_name: 'prometheus' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s static_configs: - targets: ['localhost:9090'] - job_name: 'node' # 覆盖全局默认的参数,并将采样时间间隔设置为 5s scrape_interval: 5s static_configs: - targets: ['localhost:8080', 'localhost:8081'] labels: group: 'production' - targets: ['localhost:8082'] labels: group: 'canary' ```