docker部署prometheus+grafana服务器监控(一)

news/2024/5/19 0:57:24 标签: 1024程序员节, prometheus, grafana, docker

dockercompose_prometheusgrafana_0">docker-compose 部署prometheus+grafana

Prometheus

Prometheus 是有 SoundCloud 开发的开源监控系统和时序数据库,基于 Go 语言开发。通过基于 HTTP 的 pull 方式采集时序数据,通过服务发现或静态配置去获取要采集的目标服务器,支持多节点工作,支持多种可视化图表及仪表盘。

贴一下官方提供的架构图:

在这里插入图片描述

Pormetheus 几个主要模块有,Server,Exporters,Pushgateway,PromQL,Alertmanager,WebUI 等,主要逻辑如下:

Prometheus server 定期从静态配置的 targets 或者服务发现的 targets 拉取数据。

当新拉取的数据大于配置内存缓存区时,Prometheus 会将数据持久化到磁盘(如果使用 remote storage 将持久化到云端)。

Prometheus 配置 rules,然后定时查询数据,当条件触发时,会将 alert 推送到配置的 Alertmanager。

Alertmanager 收到警告时,会根据配置,聚合、去重、降噪等操作,最后发送警告。

可以使用 API,Prometheus Console 或者 Grafana 查询和聚合数据。

Grafana

Grafana 是一个开源的度量分析及可视化套件。通过访问数据库(如 InfluxDB、Prometheus),展示自定义图表。

Exporter
Exporter 是 Prometheus 推出的针对服务器状态监控的 Metrics 工具。目前开发中常见的组件都有对应的 exporter 可以直接使用。常见的有两大类,一种是社区提供的,包含数据库,消息队列,存储,HTTP 服务,日志等,比如 node_exporter,mysqld_exporter 等;还有一种是用户自定义的 exporter,可以基于官方提供的 Client Library 创建自己的 exporter 程序。

每个 exporter 的一个实例被称为 target,Prometheus 通过轮询的方式定期从这些 target 中获取样本数据。

在这里插入图片描述

原理简介

在这里插入图片描述

dockercomposeyml_37">直接先看docker-compose.yml
version: "3.8"
services:
  node-exporter:
    image: prom/node-exporter:latest
    container_name: "node-exporter0"
    ports:
      - "9100:9100"
    restart: always
  prometheus:
    image: prom/prometheus:latest
    container_name: "prometheus0"
    user: root
    restart: always
    ports:
      - "9090:9090"
    volumes:
      - "./conf/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml"
      - "./prometheus_data:/prometheus"
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/usr/share/prometheus/console_libraries'
      - '--web.console.templates=/usr/share/prometheus/consoles'
  grafana:
    image: grafana/grafana
    container_name: "grafana0"
    user: root
    ports:
      - "3000:3000"
    restart: always
    volumes:
      - "./grafana_data:/var/lib/grafana"
    depends_on:
      -  prometheus

  alertmanager:
    image: prom/alertmanager
    hostname: alertmanager
    container_name: alertmanager
    user: root
    restart: always
    ports:
      - "9093:9093"
    volumes:
      - ./data/prometheus/alertmanager_data:/var/lib/alertmanager

prometheusyml_87">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"]

  - job_name: "node-exporter"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["node-exporter:9100"]
 # 服务器1 根据自己情况调整
  - job_name: "node-dw"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.1.5:9100"]
   # 服务器2 根据自己情况调整
  - job_name: "node-bj02-online-01"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.1.7:9100"]

http://www.niftyadmin.cn/n/5120218.html

相关文章

网络安全保险行业面临的挑战与变革

保险业内大多数资产类别的数据可以追溯到几个世纪以前&#xff1b;然而&#xff0c;网络安全保险业仍处于初级阶段。由于勒索软件攻击、高度复杂的黑客和昂贵的数据泄漏事件不断增加&#xff0c;许多网络安全保险提供商开始感到害怕继续承保更多业务。 保险行业 根据最近的路…

MyBatis实验(三)——动态SQL

前言 在编译阶段&#xff0c;就可以确定的SQL语句称为静态SQL&#xff1b;在程序运行阶段&#xff0c;根据条件不同才能确定下来的SQL叫动态SQL。如&#xff1a;学生表数据查询时&#xff0c;查询条件有年龄、姓名、专业、班级等&#xff0c;SQL语句条件根据当前的使用场景可能…

【js】单文件上传和大文件分片上传功能实现

上传功能需要的一些辅助库 1、使用第三方 vant 组件中的提示做 loading 来区分和提示。 2、大文件上传需要计算 MD5 值&#xff0c;使用 spark-md5 库。 3、上传接口&#xff0c;自定义的 axios接口&#xff0c;使用 Apis[‘方法’] 的方式调用接口&#xff08;此处不是接口封装…

docker(2)部署前后端分离springboot+vue项目

前置知识 虚拟网桥 docker容器需要在同一个网段才能通信&#xff0c;当启动一个容器时会自动连接一个docker中默认网桥段但此默认网桥段非本容器固定&#xff0c;当下次容器启动分配的ip会变&#xff0c;并且不可用名称直接访问。 自定义网段将需要互通的容器放入&#xff0c…

Linux中关于glibc包导致的服务器死机或者linux命令无法使用的情况

glibc是gnu发布的libc库&#xff0c;即c运行库。glibc是linux系统中最底层的api&#xff0c;几乎其它任何运行库都会依赖于glibc。glibc除了封装linux操作系统所提供的系统服务外&#xff0c;它本身也提供了许多其它一些必要功能服务的实现。由于 glibc 囊括了几乎所有的 UNIX …

企业财务数字化转型怎么才能落地?_光点科技

企业财务数字化转型一直是企业发展中的一个重要议题。在当今数字化的时代&#xff0c;将财务流程纳入数字化转型计划中&#xff0c;不仅能够提高工作效率&#xff0c;还能为企业带来更多的商业机会。那么&#xff0c;企业财务数字化转型如何才能真正落地呢&#xff1f; 企业需要…

众和策略可靠吗?中国资产,一夜狂飙!

可靠 当地时间10月24日&#xff0c;美股三大股指收高&#xff0c;其间道指涨0.62%&#xff0c;接连四个生意日下跌之后反弹&#xff0c;标普指数涨0.73%&#xff0c;纳斯达克指数涨0.93%。 10年期美国国债收益率小幅下滑。可口可乐等公司的财报表现弱小。美10月企业活动加速&…

火山引擎 LAS Spark 升级:揭秘 Bucket 优化技术

更多技术交流、求职机会&#xff0c;欢迎关注字节跳动数据平台微信公众号&#xff0c;回复【1】进入官方交流群 文章介绍了 Bucket 优化技术及其在实际业务中的应用&#xff0c;包括 Spark Bucket 的基本原理&#xff0c;重点阐述了火山引擎湖仓一体分析服务 LAS&#xff08;下…