prometheus入门(一)

文档参考

快速开始 · Prometheus 中文文档

下载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/metricshttp://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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值