使用docker部署grafana+prometheus配置

 更新时间:2021年12月22日 14:03:05   作者:runzhao  
这篇文章主要介绍了docker部署grafana+prometheus配置,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

docker-compose-monitor.yml

version: '2'

networks:
  monitor:
    driver: bridge

services:
  influxdb:
    image: influxdb:latest
    container_name: tig-influxdb
    ports:
      - "18083:8083"
      - "18086:8086"
      - "18090:8090"
    env_file:
      - 'env.influxdb'
    volumes:
      # Data persistency
      # sudo mkdir -p ./influxdb/data
      - ./influxdb/data:/var/lib/influxdb
      # 配置docker里的时间为东八区时间
      - ./timezone:/etc/timezone:ro
      - ./localtime:/etc/localtime:ro
    restart: unless-stopped #停止后自动

  telegraf:
    image: telegraf:latest
    container_name: tig-telegraf
    links:
      - influxdb
    volumes:
      - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
      - ./timezone:/etc/timezone:ro
      - ./localtime:/etc/localtime:ro
    restart: unless-stopped
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    hostname: prometheus
    restart: always
    volumes:
      - /home/qa/docker/grafana/prometheus.yml:/etc/prometheus/prometheus.yml
      - /home/qa/docker/grafana/node_down.yml:/etc/prometheus/node_down.yml
    ports:
      - '9090:9090'
    networks:
      - monitor

  alertmanager:
    image: prom/alertmanager
    container_name: alertmanager
    hostname: alertmanager
    restart: always
    volumes:
      - /home/qa/docker/grafana/alertmanager.yml:/etc/alertmanager/alertmanager.yml
    ports:
      - '9093:9093'
    networks:
      - monitor

  grafana:
    image: grafana/grafana:6.7.4
    container_name: grafana
    hostname: grafana
    restart: always
    ports:
      - '13000:3000'
    networks:
      - monitor

  node-exporter:
    image: quay.io/prometheus/node-exporter
    container_name: node-exporter
    hostname: node-exporter
    restart: always
    ports:
      - '9100:9100'
    networks:
      - monitor

  cadvisor:
    image: google/cadvisor:latest
    container_name: cadvisor
    hostname: cadvisor
    restart: always
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    ports:
      - '18080:8080'
    networks:
      - monitor

alertmanager.yml

global:
  resolve_timeout: 5m
  smtp_from: '邮箱'
  smtp_smarthost: 'smtp.exmail.qq.com:25'
  smtp_auth_username: '邮箱'
  smtp_auth_password: '密码'
  smtp_require_tls: false
  smtp_hello: 'qq.com'
route:
  group_by: ['alertname']
  group_wait: 5s
  group_interval: 5s
  repeat_interval: 5m
  receiver: 'email'
receivers:
- name: 'email'
  email_configs:
  - to: '收件邮箱'
    send_resolved: true
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance']

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.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets: ['192.168.32.117:9093']
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "node_down.yml"
  # - "node-exporter-alert-rules.yml"
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # IO存储节点组
  - job_name: 'io'
    scrape_interval: 8s
    static_configs:     #端口为node-exporter启动的端口 
      - targets: ['192.168.32.117:9100']
      - targets: ['192.168.32.196:9100']
      - targets: ['192.168.32.136:9100']
      - targets: ['192.168.32.193:9100']
      - targets: ['192.168.32.153:9100']
      - targets: ['192.168.32.185:9100']
      - targets: ['192.168.32.190:19100']
      - targets: ['192.168.32.192:9100']

  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'cadvisor'
    static_configs:     #端口为cadvisor启动的端口
      - targets: ['192.168.32.117:18080']
      - targets: ['192.168.32.193:8080']
      - targets: ['192.168.32.153:8080']
      - targets: ['192.168.32.185:8080']
      - targets: ['192.168.32.190:18080']
      - targets: ['192.168.32.192:18080']

node_down.yml

groups:
  - name: node_down
    rules:
      - alert: InstanceDown
        expr: up == 0
        for: 1m
        labels:
          user: test
        annotations:
          summary: 'Instance {{ $labels.instance }} down'
          description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 1 minutes.'

        #剩余内存小于10%
      - alert: 剩余内存小于10%
        expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: Host out of memory (instance {{ $labels.instance }})
          description: "Node memory is filling up (< 10% left)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

        #剩余磁盘小于10%
      - alert: 剩余磁盘小于10%
        expr: (node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes < 10 and ON (instance, device, mountpoint) node_filesystem_readonly == 0
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: Host out of disk space (instance {{ $labels.instance }})
          description: "Disk is almost full (< 10% left)\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

        #cpu负载 > 80%
      - alert: CPU负载 > 80%
        expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[2m])) * 100) > 80
        for: 0m
        labels:
          severity: warning
        annotations:
          summary: Host high CPU load (instance {{ $labels.instance }})
          description: "CPU load is > 80%\n  VALUE = {{ $value }}\n  LABELS = {{ $labels }}"

告警:https://awesome-prometheus-alerts.grep.to/rules#prometheus-self-monitoring

官网仪表盘:https://grafana.com/grafana/dashboards/

到此这篇关于docker部署grafana+prometheus配置的文章就介绍到这了,更多相关docker部署grafana+prometheus内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Docker实现从零开始搭建SOLO个人博客的方法步骤

    Docker实现从零开始搭建SOLO个人博客的方法步骤

    本文主要介绍了Docker实现从零开始搭建SOLO个人博客,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-11-11
  • docker比赛提交常用命令小结

    docker比赛提交常用命令小结

    这篇文章主要介绍了docker比赛提交常用命令小结,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-02-02
  • 解决nacos启动时防火墙开启8848的坑

    解决nacos启动时防火墙开启8848的坑

    最近操作Nacos时遭遇8848端口无法访问的问题,尝试通过安全组和firewall配置仍无法解决,最终发现,firewall对Docker使用专门的作用域,需要在相应作用域下开放端口,务必检查firewall中针对Docker的设置,确保8848端口在正确的作用域内被允许通行
    2022-10-10
  • docker打包python镜像的全教程分享

    docker打包python镜像的全教程分享

    Docker是一种开源的容器化平台,可以让开发者将应用程序和其依赖项打包到一个可移植的容器中,然后在不同的环境中运行,本文主要给大家介绍了docker打包python镜像全教程,需要的朋友可以参考下
    2024-02-02
  • docker搭建kafka集群的方法实现

    docker搭建kafka集群的方法实现

    本文主要介绍了docker搭建kafka集群的方法实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-05-05
  • docker实现重新打tag并删除原tag的镜像

    docker实现重新打tag并删除原tag的镜像

    这篇文章主要介绍了docker实现重新打tag并删除原tag的镜像,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-11-11
  • Docker容器的导入导出操作教程

    Docker容器的导入导出操作教程

    这篇文章主要给大家介绍了关于Docker容器的导入导出操作的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Docker具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-09-09
  • Docker容器间通信与外网通信的操作

    Docker容器间通信与外网通信的操作

    这篇文章主要介绍了Docker容器间通信与外网通信的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-03-03
  • Docker与Golang的巧妙结合

    Docker与Golang的巧妙结合

    这篇文章主要介绍了Docker与Golang的巧妙结合的相关资料,需要的朋友可以参考下
    2016-10-10
  • Docker部署MySQL主从复制的实现

    Docker部署MySQL主从复制的实现

    本文主要介绍了Docker部署MySQL主从复制的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-10-10

最新评论