文档参考
下载prometheus
Download | Prometheus
对于于macos,下载prometheus-2.30.3.darwin-amd64.tar.gz版本
启动
./prometheus --config.file=prometheus.yml
mac执行上面命令可能遇到的问题
解决 MAC 无法打开“***”,因为无法验证开发者_lightserver.cn-优快云博客_无法验证开发者
启动示例应用
Go 客户端库包含一个示例,该示例为具有不同延迟分布的三个服务暴露 RPC 延迟。
确保你已经安装了 Go 语言编译器并且指定 Go 工作目录 (在环境变量中指定正确的 GOPATH)
下载 Prometheus 的 Go 客户端库并运行这三个示例:
# Fetch the client library code and compile example.
git clone https://github.com/prometheus/client_golang.git
cd client_golang/examples/random
go get -d
go build
# Start 3 example targets in separate terminals:
./random -listen-address=:8080
./random -listen-address=:8081
./random -listen-address=:8082
此时监听目标启动 http://localhost:8080/metrics, http://localhost:8081/metrics 和 http://localhost:8082/metrics
修改配置文件
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).
# Attach these extra labels to all timeseries collected by this Prometheus instance.
external_labels:
monitor: 'codelab-monitor'
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- 'prometheus.rules.yml'
# - "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=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: 'example-random'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:8080', 'localhost:8081']
labels:
group: 'production'
- targets: ['localhost:8082']
labels:
group: 'canary'
prometheus.rules.yml文件
groups:
- name: example
rules:
- record: job_service:rpc_durations_seconds_count:avg_rate5m
expr: avg(rate(rpc_durations_seconds_count[5m])) by (job, service)
其他:
Deploy Prometheus monitoring system using ansible.
GitHub - cloudalchemy/ansible-prometheus: Deploy Prometheus monitoring system