prometheus+grafana

prometheus

  1. 官网下载

Download | Prometheus

例如linux:wget https://github.com/prometheus/prometheus/releases/download/v2.43.0/prometheus-2.43.0.linux-amd64.tar.gz

  1. 配置文件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

  1. 启动

./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 &
  1. 浏览器访问

输入地址:127.0.0.1:8889

页面 Status -> Targets 可查看配置的tagets的状态。

grafana

  1. 下载

Index of grafana-local

例如linux:wget https://mirrors.huaweicloud.com/grafana/9.4.7/grafana-enterprise-9.4.7.linux-amd64.tar.gz

  1. 配置文件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
  1. 启动

./bin/grafana-server
  1. 浏览器访问

输入地址:127.0.0.1:8888

初始用户密码:admin admin

  1. 配置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.*'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值