prometheus
-
官网下载
例如linux:wget https://github.com/prometheus/prometheus/releases/download/v2.43.0/prometheus-2.43.0.linux-amd64.tar.gz
-
配置文件prometheus.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: 'bci'
scrape_interval: 1m
metrics_path: '/metrics'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['127.0.0.1:8090']
如果是启动后再修改配置文件,可以热加载:curl -XPOST localhost:8889/-/reload
-
启动
./prometheus --web.listen-address=0.0.0.0:8889 --web.enable-lifecycle
或者
nohup ./prometheus --web.listen-address=:8766 --storage.tsdb.path=/home/disk2/prom/data --storage.tsdb.retention=30d --web.enable-lifecycle --web.enable-admin-api --query.max-samples=5000000000 --query.timeout=5m 2>&1 &
-
浏览器访问
输入地址:127.0.0.1:8889
页面 Status -> Targets 可查看配置的tagets的状态。
grafana
-
下载
例如linux:wget https://mirrors.huaweicloud.com/grafana/9.4.7/grafana-enterprise-9.4.7.linux-amd64.tar.gz
-
配置文件conf/defaults.ini
按需设置端口http_port
[server]
# Protocol (http, https, h2, socket)
protocol = http
# The ip address to bind to, empty will bind to all interfaces
http_addr =
# The http port to use
http_port = 8888
-
启动
./bin/grafana-server
-
浏览器访问
输入地址:127.0.0.1:8888
初始用户密码:admin admin
-
配置dashboard
a. 设置data source
选择Prometheus,设置url(例如:http://127.0.0.1:8889)、按需配置Scrape interval。
b. 配置dashboard
按需添加Variables。
query: label_values(bci_api_qps, region)
c. 设置panel
metrics: sum(bci_api_qps{region="$region"}) by (source,api,method)
legend: api={{api}} {{method}}, source={{source}}
prometheus的targets使用ip列表配置文件
prometheus.yml
- job_name: "halo_offline_isolator"
scrape_interval: 1m
metrics_path: '/resource/metrics'
file_sd_configs:
- files: ['/tmp/ips.json']
/tmp/ips.json
[
{
"targets": [
"10.212.70.224:410",
"10.212.70.162:410"
],
"labels": {
"instance": "halolet"
}
}
]
prometheus不采集指定指标
prometheus.yml
- job_name: "halo_offline_isolator"
scrape_interval: 1m
metrics_path: '/resource/metrics'
file_sd_configs:
- files: ['/tmp/ips.json']
metric_relabel_configs:
- action: drop
source_labels: [__name__]
regex: '^container.*'