Carry の Blog Carry の Blog
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Carry の Blog

好记性不如烂键盘
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 工作笔记

  • K8S

  • Systemd

  • Nginx

  • Supervisord

  • OpenLdap

  • OpenVPN

  • GitLab

  • Sshd

  • WebDev

  • Docker

  • Prometheus

    • prometheus监控介绍
      • PromQL介绍
    • Rclone

    • Iptables

    • Firewalld

    • Linux笔记
    • Prometheus
    Carry の Blog
    2022-03-10
    目录

    prometheus监控介绍原创

    Prometheus 是一个开源的系统监控和报警工具,最初由SoundCloud开发,现为Cloud Native Computing Foundation的一部分。它特别适用于监控分布式系统和微服务架构。

    # Prometheus 的基本架构

    Prometheus 的架构由多个组件组成,每个组件可以独立运行。主要组件包括:

    1. Prometheus Server:

      • 负责数据采集和存储。
      • 通过HTTP拉取方式从各种目标收集时间序列数据。
      • 存储收集到的数据并提供查询能力。
    2. Exporters:

      • 监控目标的代理程序,用于暴露指标数据。
      • 常见的 Exporters 有 Node Exporter(监控主机硬件和操作系统指标)、MySQL Exporter、Redis Exporter等。
    3. Pushgateway:

      • 用于短生命周期的作业将指标推送到 Prometheus。
      • 例如,批处理作业在完成时将结果发送到 Pushgateway,然后由 Prometheus 拉取这些结果。
    4. Alertmanager:

      • 处理来自 Prometheus Server 的警报。
      • 支持告警去重、分组和路由,并可以将警报发送到不同的通知渠道(如邮件、Slack、PagerDuty等)。
    5. 客户端库:

      • 允许用户在自己的应用程序中埋点,生成自定义指标。
      • 支持多种编程语言,如Go、Java、Python、Ruby等。

    # 数据模型

    Prometheus 使用多维数据模型来存储时间序列数据。每个时间序列由唯一的指标名称和一组键值对(标签)标识。标签用于区分不同来源或维度的同一类型指标。

    例如:

    http_requests_total{method="GET", handler="/api"}  1027  1395066363000
    
    1
    • http_requests_total 是指标名称。
    • {method="GET", handler="/api"} 是标签。
    • 1027 是指标值。
    • 1395066363000 是时间戳。

    # Prometheus 的工作流程

    1. 数据收集: Prometheus Server 定期从配置的目标上拉取数据。这些目标通过 HTTP 暴露指标接口,通常为 /metrics 端点。

    2. 数据存储: Prometheus 使用本地存储将时间序列数据存储在磁盘上。数据采用基于时间的块存储,每个块包含一个时间范围内的所有数据。

    3. 数据查询: 使用 PromQL(Prometheus Query Language)进行数据查询。PromQL 是一种功能强大的查询语言,可以聚合、筛选和转换时间序列数据。

    4. 警报: Prometheus 根据定义的规则评估数据,并生成警报。警报通过 Alertmanager 发送到相应的通知渠道。

    # Prometheus 安装与配置

    以下是 Prometheus 的基本安装和配置步骤:

    1. 下载并安装 Prometheus:

      wget https://github.com/prometheus/prometheus/releases/download/v2.37.0/prometheus-2.37.0.linux-amd64.tar.gz
      tar xvfz prometheus-2.37.0.linux-amd64.tar.gz
      cd prometheus-2.37.0.linux-amd64
      
      1
      2
      3
    2. 配置 Prometheus: 编辑 prometheus.yml 文件,配置监控目标:

      global:
        scrape_interval: 15s # 默认抓取间隔
      
      scrape_configs:
        - job_name: 'node'
          static_configs:
            - targets: ['localhost:9100'] # Node Exporter 目标
      
      1
      2
      3
      4
      5
      6
      7
    3. 启动 Prometheus:

      ./prometheus --config.file=prometheus.yml
      
      1
    4. 安装 Exporter: 以 Node Exporter 为例,下载并启动 Node Exporter:

      wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
      tar xvfz node_exporter-1.3.1.linux-amd64.tar.gz
      cd node_exporter-1.3.1.linux-amd64
      ./node_exporter
      
      1
      2
      3
      4
    5. 访问 Prometheus: 打开浏览器访问 http://localhost:9090 可以看到 Prometheus 的仪表盘,可以进行数据查询和监控配置。

    # PromQL 示例

    • 查询一分钟内每秒的 HTTP 请求总数:

      rate(http_requests_total[1m])
      
      1
    • 查询指定时间范围内的 CPU 使用率:

      avg(rate(node_cpu_seconds_total{mode!="idle"}[5m])) by (instance)
      
      1
    上次更新: 4/24/2025

    ← bitwarden docker启动 PromQL介绍→

    最近更新
    01
    tidb fast ddl
    04-04
    02
    TiDB配置文件调优 原创
    04-03
    03
    如何移除TiDB中的表分区 原创
    04-03
    更多文章>
    Theme by Vdoing
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式