Prometheus【普罗米修斯】--- prometheus+grfana+mysql

用户默认为root操作

前期准备

系统环境:CentOS 7.9  #防火墙若开启,请打开对应端口

已安装软件:Docker、Docker-compose

相关文件:prometheus相关镜像包、grafana仪表盘文件

创建文件夹路径:mkdir -p /u01/prometheus

创建docker-compose.yml

  • 移动至/u01/prometheus
cd /u01/prometheus

  • 创建docker-compose.yml
vi docker-compose.yml

  • docker-compose.yml内容(不需要mysql8.0,mysql部分可以省略)
version: '3'


networks:
    monitor:
        driver: bridge

services:
    prometheus:
        image: prom/prometheus
        container_name: prometheus
        hostname: prometheus
        restart: always
        volumes:
            - ./prometheus.yml:/etc/prometheus/prometheus.yml
#            - ./node_down.yml:/usr/local/etc/node_down.yml:rw
        ports:
            - "9090:9090"
        networks:
            - monitor

    alertmanager:
        image: prom/alertmanager
        container_name: alertmanager
        hostname: alertmanager
        restart: always
#        volumes:
#            - ./alertmanager.yml:/usr/local/etc/alertmanager.yml
        ports:
            - "9093:9093"
        networks:
            - monitor

    grafana:
        image: grafana/grafana
        container_name: grafana
        hostname: grafana
        restart: always
        ports:
            - "3000: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:
            - "8899:8080"
        networks:
            - monitor
            
    mysqld-exporter:
        image: quay.io/prometheus/mysqld-exporter
        container_name: mysqld-exporter
        hostname: mysqld-exporter
        environment:
            - DATA_SOURCE_NAME="exporter:123456@(192.168.192.23:3306)
        volumes:
            - ./mysql-exporter/.my.cnf:/.my.cnf
        restart: always
        ports:
            - "9104:9104"
        networks:
            - monitor
        links:
            - mysql

    mysql:
       image: mysql:8.0
       container_name: mysql
       volumes:
         - ./mysql/data:/var/lib/mysql
         - ./mysql/conf:/etc/mysql/conf.d
         - ./mysql/logs:/var/log/mysql
         - /etc/localtime:/etc/localtime
       restart: always
       privileged: true
       environment:
         - MYSQL_ROOT_PASSWORD=myrootpass
         - MYSQL_DATABASE=zabbix
         - MYSQL_USER=exporter
         - MYSQL_PASSWORD=123456
         - TZ=Asia/Shanghai
         - LANG=en_US.UTF-8
       ports:
           - "3306:3306"
       networks:
            - monitor
       command: --character-set-server=utf8 --collation-server=utf8_bin

  • docker-compose.yml内容简介
  1. cadvisor 用于获取docker容器的指标
  2. node-exporter 用户获取服务器的指标
  3. mysqld-exporter 用于获取mysql的指标
  4. grafana 监控的web-ui好用的可视化组件
  5. alertmanager 告警组件
  6. prometheus 核心监控组件
  7. Mysql 使用mysql数据库

创建prometheus.yml

  • 新建prometheus的配置文件prometheus.yml
vi prometheus.yml

  • prometheus.yml内容
global:
  scrape_interval:     15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['ip:9090']  ## 指定监控ip
  - job_name: 'cadvisor'
    static_configs:
    - targets: ['ip:8899']  ## 指定监控ip
  - job_name: 'node'
    static_configs:
    - targets: ['ip:9100']  ## 指定监控ip
  - job_name: 'mysql_monitor'
    static_configs:
    - targets: ['ip:9104']  ## 指定监控ip

启动docker-compose

#启动命令

docker-compose up -d

#查看容器状态命令

docker-compose ps

#重启指定服务命令

docker-compose restart mysql

WEB端查看监控信息

监控网址

http://ip:9090/targets

prometheus的原生web-ui

http://ip:9100/metrics

查看服务器的指标

http://ip:8899/metrics

查看docker容器的指标

http://ip:3000/

Grafana开源的监控可视化组件页面

Grafana设置

初始账户密码:admin/admin

添加prometheus数据源

进到配置页面,写下对应的URL,例如http://ip:9090,然后保存。

导入仪表盘文件即可(本地文件或者下载模版)

下载Mysql模版:8919

修改仪表盘名称,并且选择数据源

仪表盘效果展示

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值