前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >DockerCompose runs Grafana and integrates Prometheus+node-exporter+cadvisor multiple server

DockerCompose runs Grafana and integrates Prometheus+node-exporter+cadvisor multiple server

作者头像
码农笔录
发布2021-12-06 19:08:25
4720
发布2021-12-06 19:08:25
举报
文章被收录于专栏:码农笔录码农笔录
image.png
image.png

原文链接 https://www.aiprose.com/blog/149

Use docker to run Grafana to integrate Prometheus+node-exporter+cadvisor to monitor multiple nodes.

One of the nodes is the local machine, and the other is my other server. Prometheus only needs to start one, and the other server only needs to run a node-exporter.

The official Prometheus and some third parties have already made the collection of index data of some commonly used databases, systems, middleware, etc. into exporters, which can be directly imported and used in the production environment. In this section, we will use the Node Exporter officially provided by Prometheus to collect the running data of the Linux system. cAdvisor can perform real-time monitoring and performance data collection of resources and Docker containers on node machines, including CPU usage, memory usage, network throughput, and file system usage.

171504120201129181943262234489244.png
171504120201129181943262234489244.png

This article is based on docker-compse. If there is no docker environment, please prepare the docker environment first.

docker-compose file preparation

1.When writing the grafana.yml file, you must remember to mount it on the volume, otherwise you will have to reconfigure it after restarting.

代码语言:javascript
复制
version: '3.1'
services:
 grafana:
   image: grafana/grafana
   container_name: grafana
   restart: always
   ports:
    - "3000:3000"
   volumes:
    - /opt/grafana:/var/lib/grafana

2.Write prometheus.yml to include Prometheus+node-exporter+cadvisor

代码语言:javascript
复制
version: "3"
services:
    prometheus:
        image: prom/prometheus
        container_name: prometheus
        hostname: prometheus
        restart: always
        volumes:
            - /opt/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml
            - /opt/prometheus/config/node_down.yml:/etc/prometheus/node_down.yml
        ports:
            - "9090:9090"
    node-exporter:
        image: quay.io/prometheus/node-exporter
        container_name: node-exporter
        restart: always
        ports:
            - "9100:9100"
    cadvisor:
        image: google/cadvisor:latest
        container_name: cadvisor
        restart: always
        volumes:
            - /:/rootfs:ro
            - /var/run:/var/run:rw
            - /sys:/sys:ro
            - /var/lib/docker/:/var/lib/docker:ro
        ports:
            - "8080:8080"

3.Another node, node-exporter.yml

代码语言:javascript
复制
version: '3.1'
services:
  node-exporter:
     image: quay.io/prometheus/node-exporter
     container_name: node-exporter
     restart: always
     ports:
      - "9100:9100"

Prometheus configuration file editing

The files mounted by prometheus above have two prometheus.yml and node_down.yml

1.prometheus.yml

172.18.0.1 is the gateway address of my docker network card. The port corresponds to the address configured in the docker-compose file above, and all the default ports are used here.

代码语言:javascript
复制
# 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.

#alerting:
 # alertmanagers:
 # - static_configs:
 #   - targets: ['172.18.0.1:9093']

rule_files:
  - "node_down.yml"

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['172.18.0.1:9090']

  - job_name: 'cadvisor'
    static_configs:
    - targets: ['172.18.0.1:8080']

  - job_name: 'node'
    scrape_interval: 8s
    static_configs:
      - targets: ['172.18.0.1:9100','49.235.160.131:9100']

2.node_down.yml

代码语言:javascript
复制
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."

Start service

代码语言:javascript
复制
docker-compose -f grafana.yml up -d

docker-compose -f node-exporter.yml up -d

docker-compose -f prometheus.yml up -d

Configuration interface

Visit your grafana after startup, the address is ip:3000, you need to modify the default password (admin/admin) for the first time.

After logging in, the first step is to add the prometheus data source.

image.png
image.png

The second step is to find an official template, template ID: 1860, of course, you can also design your own dashboard.

image.png
image.png

Here you need to select the data source set in the first step.

image.png
image.png

actual effect

image.png
image.png

View other server information

image.png
image.png

Monitoring Docker host template ID: 193 (this template can be used directly to monitor docker to get the dashboard)

image.png
image.png
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-10-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • docker-compose file preparation
  • Prometheus configuration file editing
  • Start service
  • Configuration interface
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档