Prometheus快速入门1

Prometheus Monitor go

之前做P4-INT时用到过Prometheus并深感功能强大且好用,Now又遇到一些性能监测的需求,因此该部分记录学习过程中使用Prometheus做监测的内容

Ref:Prometheus中文文档非常喜欢的一位博主

Introduce

Prometheus是时序数据库(Time Series Database),又简称 TSDB,类似的还有InfluxDB等。

Prometheus主要组件包括:

  • Prometheus Server:服务端,用于收集指标和存储时间序列数据,并提供丰富的的查询和设置接口。
  • Client Libraries:客户端库,用于帮助需要监控采集的服务暴露 metrics handler 给 Prometheus server。
  • Push Gateway:推送网关,Prometheus 服务端仅支持 HTTP pull 的采集方式,而有一些指存在的时间短,Prometheus 来 pull 前就结束了。又或是该类指标,就是要客户端自行上报的,这时候就可以采用 Push Gateway 的方式,客户端将指标 push 到 Push Gateway,再由 Prometheus Server 从 Pushgateway 上 pull。
  • Exporters:用于暴露已有的第三方服务(HAProxy,StatsD,Graphite)的 metrics 给 Prometheus Server。
  • Alertmanager:用于处理告警,从 Prometheus server 端接收到 alerts 后,会进行去重,分组,然后路由到对应的Receiver,发出报警。
    Support Tools:各种支持工具。

此外还支持独立组件如mysqld_exporternode_exporter

Quick Start(Install Prometheus & Test)

Install

这里直接给出最具体的安装步骤(Linux@2023年7月21日)

wget https://github.com/prometheus/prometheus/releases/download/v2.37.8/prometheus-2.37.8.linux-amd64.tar.gz
tar -zxvf prometheus-2.37.8.linux-amd64.tar.gz 

备选

pip install prometheus-client
wget https://s3-eu-west-1.amazonaws.com/deb.robustperception.io/41EFC99D.gpg | sudo apt-key add -
sudo apt update
sudo apt -y install prometheus
sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl status prometheus

Test

不管那么多,直接启动先!

./prometheus 

默认启动参数可以在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).
# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "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"]

这样就可以通过http://localhost:9090/graph用来访问Prometheus(我这里用的vscode的端口转发),如下图所示:

在这里插入图片描述

这里就能看到目前所支持的Targets,访问Graph绘制走势图,这里先根据go_gc也就是go中垃圾回收的参数看一下效果,如下图:

在这里插入图片描述

添加图也很简单,Add Panel然后选择参数,这里还会有补全以及解释,然后Execute就可以了,非常简单~

在这里插入图片描述

当然,也可以用grafana这种也没问题~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值