prometheus 简单搭建

本文详细介绍了Prometheus监控系统的下载、安装及配置过程,包括配置文件prometheus.yml的参数解析,如何启动Prometheus服务,以及如何通过浏览器访问查看监控数据。同时,提供了基本的Prometheus查询语句示例,帮助用户快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

https://prometheus.io/download/下载最新版本

wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz

tar zxvf prometheus-2.3.2.linux-amd64.tar.gz 

 cd prometheus-2.3.2.linux-amd64

./prometheus --help

配置文件prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s

rule_files:
  # - "first.rules"
  # - "second.rules"

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']

global块,全局配置,scrape_interval:抓取的时间间隔,evaluation_interval:执行聚合规则的时间间隔

rule_files块,指定规则文件的位置,这里暂时不指定。

scrape_configs块,配置监控项。因为prometheus可以自己暴露metric,这里配置为监控自己。抓取的uri为/metrics,抓取的url为http://localhost:9090/metrics.

完整的配置轻参考:https://prometheus.io/docs/operating/configuration

启动:

./prometheus --config.file=prometheus.yml

浏览器访问:

http://127.0.0.1:9090/

http://localhost:9090/metrics

查看prometheus采集的数据:

访问 http://localhost:9090/graph 并选择console,输入 promhttp_metric_handler_requests_total。

如果只关心200,可以这样查询

promhttp_metric_handler_requests_total{code="200"}

统计数量

count(promhttp_metric_handler_requests_total)

更多查询参考:https://prometheus.io/docs/querying/basics/

统计每秒httpcode为200的比例

rate(promhttp_metric_handler_requests_total{code="200"}[1m])

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值