prometheus入门(一)

时间:2022-07-25
本文章向大家介绍prometheus入门(一),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

prometheus入门(一)

大纲

  • 基础架构介绍
  • 官方站点以及后期用到的软件包介绍
  • prometheus以及各类exporter的使用
  • 告警配置
  • 高可用架构
  • docker&k8s监控

基础架构介绍

官方站点: https://prometheus.io 官方架构图:

大体组成部分以及流程介绍

  • 数据采集: 主要是由各类的exporter采集上报,如图中的1所表示的地方
  • 数据处理: server端,图中2所在的位置,主要的功能是定期抓取上面数据采集的数据,然后将数据落盘和根据告警条件向alertmanager发送告警提示;还有就是根据webUI或者grafana去展示
  • 告警处理: alertmanager根据server定义的阈值和告警去通过不同的媒介(email,pagerduty)向定义的告警接收方发送告警
  • 数据展示: 自身存在prometheusUI这个web界面,利用promSQL去查询和展示数据,也有对应的API,通过grafana或者其他二次开发产品将prometheus数据加以展示

官方站点以及后期用到的软件包介绍

prometheus以及各类exporter的使用

  • 注意事项:
    • 操作系统为centos7+
    • 数据存储可以使用本地或者influxdb
    • 数据默认的保存时间是15天
    • 可以根据不同的业务场景采用不同的expoter或者其组合
  • 大体部署如下:

prometheus的安装

> wget https://github.com/prometheus/prometheus/releases/download/v2.18.1/prometheus-2.18.1.linux-amd64.tar.gz
> tar xf prometheus-2.18.1.linux-amd64.tar.gz
> mv prometheus-2.18.1.linux-amd64/* /usr/local/bin/
------------写入启动文件
> cat /etc/systemd/system/prometheus.service 
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System

[Service]
ExecStart=/usr/local/bin/prometheus 
  --config.file=/etc/prometheus/prometheus.yml 
  --web.listen-address=:9090

[Install]
WantedBy=multi-user.target
-------准备配置文件
> cat /etc/prometheus/prometheus.yml 
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.
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

prometheus配置文件简介

  • 配置问价是yaml格式的
  • 字段介绍:
    • global: 全局配置,配置抓取的间隔和评估时间
    • remoteDB: 远端数据库存储配置,主要使用influxdb
    • alertManager: 配置alertmanager告警发送
    • rules: 告警阈值的定义
    • scrape_configs: 定义锁抓取的exporter地址,后期加入exporter主要在这操作即可

服务配置检测与启动

> promtool  check config /etc/prometheus/prometheus.yml # 检测配置文件正确性
> systemctl enable prometheus && systemctl start prometheus  #服务启动与开机自启动