使用docker-compose搭建Prometheus+Gra

2020-08-13  本文已影响0人  丿捺人生

概念与设计总览

一、环境说明


二、安装node_exporter

  1. node_exporter用于采集系统信息,github地址

  2. 前往https://github.com/prometheus/node_exporter/releases列表下载对应系统的最新文件

    2.png
  3. 解压

3.png
  1. 启动:./node_exporter &

    4.png
  1. 打开页面:http://localhost:9100

    5.png

三、docker-compose安装Prometheus

  1. 编写docker-compose.yml

    version: '3.3'
    services:
      prometheus:
        image: prom/prometheus:latest
        container_name: prometheus
        restart: always
        privileged: true
        user: root
        ports:
          - 9090:9090
        volumes:
          #将刚刚准备好的defaults.ini直接映射到/usr/share/grafana/conf/defaults.ini路径
          - ./prometheus.yml:/etc/prometheus/prometheus.yml
    
  2. 新建prometheus.yml并配置node exporter监控数据

    # 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: ['docker.for.mac.host.internal:9090'] # 服务器上使用内网ip
      # 采集node exporter监控数据
      - job_name: 'node'
        static_configs:
        - targets: ['docker.for.mac.localhost:9100']  # 服务器上使用内网ip
    
    
  3. 启动docker

    启动容器:docker-compose up -d

    查看容器:docker-compose ps

    删除容器:docker-compose rm

  4. 验证并查看node_exporter状态


四、docker-compose安装Grafana

  1. 编写docker-compose.yml

    version: '3.3'
    services:
      grafana:
        image: grafana/grafana:latest
        container_name: grafana
        restart: always
        privileged: true
        user: root
        ports:
          - 3000:3000
        environment:
          - GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
        volumes:
          #将刚刚准备好的defaults.ini直接映射到/usr/share/grafana/conf/defaults.ini路径
          - ./config/defaults.ini:/usr/share/grafana/conf/defaults.ini
          #data目录,如果使用了默认的sqlite3数据库,则文件会存在这边
          - ./data/grafana:/var/lib/grafana
          #log目录,后期会写入log文件
          - ./log:/var/log/grafana
      # 添加插件 *注意修改defaults.ini文件:server_url = http://renderer:8081/render
    #  renderer:
    #    image: grafana/grafana-image-renderer
    #    restart: always
    #    ports:
    #      - 8081:8081
    #    container_name: renderer
    #    environment:
    #      - GF_RENDERER_PLUGIN_TZ=Asia/Shanghai
    #      - GF_RENDERER_PLUGIN_IGNORE_HTTPS_ERRORS=true
    
  2. 启动docker

    启动容器:docker-compose up -d

    查看容器:docker-compose ps

    删除容器:docker-compose rm

  3. 验证,默认用户名密码为admin/admin

  1. 新增prometheus数据源并配置服务地址

    image.png
  1. 寻找别人配置好的模板,其他模板查看https://grafana.com/grafana/dashboards

    image.png
  1. 导入模板

    image.png
  1. 查看

    image.png
image.png
上一篇下一篇

猜你喜欢

热点阅读