文章目录
-
-
- 一、前言
- 二、docker-compose部署Prometheus+Grafana
-
- docker-compose-prometheus.yml
- prometheus.yml
- 三、访问
-
- 1、exporter
- 2、prometheus
- 3、grafana
- 四、Grafana配置
-
- 1、新增Prometheus数据源
- 2、导入Prometheus Dashboard
-
一、前言
本文将基于以下环境通过Prometheus+Grafana建立Liunx系统的监控
- Docker version 20.10.5, build 55c4c88
- docker-compose version 1.28.6, build 5db8d86f
- CentOS Linux release 7.6.1810 (Core)
二、docker-compose部署Prometheus+Grafana
# 环境准备
git clone https://gitee.com/zhengqingya/docker-compose.git
cd docker-compose/Liunx
# 注:
# 1. `docker-compose-prometheus.yml` 需修改grafana中配置的mysql连接信息
# 2. `prometheus.yml` 自行配置
# 运行
docker-compose -f docker-compose-prometheus.yml -p prometheus up -d
这里再展示下相关文件吧
docker-compose-prometheus.yml
# 镜像版本请自行选择 https://hub.docker.com/search?q=&type=image
version: "3"# 网桥 -> 方便相互通讯
networks:prometheus:services:prometheus:image: prom/prometheus:v2.30.0container_name: prometheusvolumes:- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.ymlcommand: "--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus"ports:- "9090:9090"depends_on:- exporternetworks:- prometheusexporter:image: prom/node-exporter:v1.2.2container_name: prometheus_exporterports:- "9100:9100"networks:- prometheus# 用于UI展示# https://grafana.com/docs/grafana/latest/installation/dockergrafana:image: grafana/grafana:8.1.5container_name: prometheus_grafanarestart: unless-stoppedports:- "3000:3000"
# volumes:
# - "./prometheus/grafana/grafana-storage:/var/lib/grafana"
# - "./prometheus/grafana/public:/usr/share/grafana/public" # 这里面可处理汉化包 可参考 https://github.com/WangHL0927/grafana-chinese
# - "./prometheus/grafana/conf:/usr/share/grafana/conf"
# - "./prometheus/grafana/log:/var/log/grafana"
# - "/etc/localtime:/etc/localtime"environment:GF_EXPLORE_ENABLED: "true"GF_SECURITY_ADMIN_PASSWORD: "admin"GF_INSTALL_PLUGINS: "grafana-clock-panel,grafana-simple-json-datasource,alexanderzobnin-zabbix-app"# 持久化到mysql数据库GF_DATABASE_URL: "mysql://root:root@www.zhengqingya.com:3306/grafana" # TODO 修改depends_on:- prometheusnetworks:- prometheus# mysql数据库 => 用于grafana持久化数据
# mysql:
# image: registry.cn-hangzhou.aliyuncs.com/zhengqing/mysql:5.7
# container_name: prometheus_mysql
# restart: unless-stopped
# volumes:
# - "./prometheus/mysql5.7/my.cnf:/etc/mysql/my.cnf"
# - "./prometheus/mysql5.7/data:/var/lib/mysql"
# - "./prometheus/mysql5.7/log/mysql/error.log:/var/log/mysql/error.log"
# environment:
# TZ: Asia/Shanghai
# LANG: en_US.UTF-8
# MYSQL_ROOT_PASSWORD: root # 设置root用户密码
# MYSQL_DATABASE: grafana # 初始化数据库grafana
# ports:
# - "3306:3306"
prometheus.yml
# 可参考 https://prometheus.io/docs/prometheus/latest/getting_started
global:scrape_interval: 10sscrape_timeout: 10sevaluation_interval: 10m
scrape_configs:# springboot项目- job_name: spring-bootscrape_interval: 5sscrape_timeout: 5smetrics_path: /application/prometheusscheme: httpbasic_auth:username: adminpassword: 123456static_configs:- targets:- 192.168.0.88:20040 # TODO 此处填写SpringBoot应用的IP+端口号# prometheus- job_name: prometheusstatic_configs:- targets: ['www.zhengqingya.com:9090']labels:instance: prometheus# 采集node exporter监控数据,即linux- job_name: linuxstatic_configs:- targets: ['www.zhengqingya.com:9100']labels:instance: localhost
运行成功后,容器如下:
三、访问
1、exporter
http://ip地址:9100/metrics
2、prometheus
http://ip地址:9090/targets
Status
-> Targets
3、grafana
http://ip地址:3000
默认登录账号密码:admin/admin
四、Grafana配置
1、新增Prometheus数据源
Configuration
-> Data sources
-> Add data source
-> Prometheus
配置prometheus地址
保存并测试连接
2、导入Prometheus Dashboard
Create
-> Import
输入8919
温馨小提示:资源可从 https://grafana.com/grafana/dashboards 中选择
查看liunx监控信息如下
今日分享语句:
不论你在什么时候开始,重要的是开始之后就不要停止。