当前位置:网站首页>开源一夏 | 教你快速实现“基于Docker快速构建基于Prometheus的MySQL监控系统”
开源一夏 | 教你快速实现“基于Docker快速构建基于Prometheus的MySQL监控系统”
2022-08-03 10:06:00 【InfoQ】
先来捋一下数据流的传输
Mysql
mysql_export
prometheus
grafana
Mysql的创建
- 创建init.d配置文件的文件夹
mkdir -p /etc/mysql/init.d
- 配置文件的设置
SET NAMES utf8mb4;
SET @[email protected]@UNIQUE_CHECKS,UNIQUE_CHECKS=0;
SET @[email protected]@FOREIGN_KEY_CHECKS,FOREIGN_KEY_CHECKS=0;
SET @[email protected]@SQL_MODE,SQL_MODE='TRADITIONAL';
DROP SCHEMA IF EXISTS sakila;
CREATE SCHEMA sakila;
USE sakila;
CREATE TABLE actor(
actor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
first_name VARCHAR(45) NOT NULL,
last_name VARCHAR(45) NOT NULL,
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(actor_id),
KEY idx_actor_last_name (last_name)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
# 创建远程的用户名和密码用于连接数据库
CREATE USER [email protected]'%'IDENTIFIED with mysql_native_password BY 'remote';
grant all privileges on *.* to [email protected]'%';
# 创建exporter需要读取数据库日志信息的登陆账户,并授予权限
CREATE USER 'exporter'@'%' IDENTIFIED BY 'exporter';
GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'exporter'@'%';
GRANT SELECT ON performance_schema.* TO 'exporter'@'%';
解释:docker-entrypoint-initdb.d这个为创建mysql的时候默认执行的初始脚本
docker run -p 3306:3306 --name db -v /etc/mysql/init.d:/docker-entrypoint-initdb.d -e MYSQL_ROOT_PASSWORD=root -d mysql:8
mysql_exporter搭建
docker run -d -p 9104:9104 --name mysql_exporter -e DATA_SOURCE_NAME="exporter:[email protected](127.0.0.1:3306)/sakila" prom/mysqld-exporter
-e DATA_SOURCE_NAME="exporter:[email protected](你的mysql数据库所在的ip:3306)/sakila"
Prometheus搭建
- mkdir -p /etc/prometheus
- vi /etc/prometheus/prometheus.yml
#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: ['localhost:9090']
### 以下内容为mysql_exporter的配置,主要是这个地方
- job_name: 'mysql_promethues'
scrape_interval: 5s
metrics_path: '/metrics'
static_configs:
- targets: ['localhost:9104']
docker run -d --name=prometheus -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -p 9090:9090 bitnami/prometheus:latest
Grafana搭建
docker run -d --name=grafana -p 3000:3000 grafana/grafana
总结
边栏推荐
猜你喜欢
Go Redis database operation
What exactly does a firmware engineer do?
Ultra-detailed Asp.net uses SSL two-way authentication, one article is enough
pixel手机升系统
决策树和随机森林
ImportError: DLL load failed with error code -1073741795
MySQL 中 is null 和 =null 的区别
阿里本地生活全域日志平台 Xlog 的思考与实践
Redis和MySQL如何保持数据一致性
MySQL——几种常见的嵌套查询
随机推荐
如何优雅的消除系统重复代码
几款永久免费内网穿透,好用且简单_内网穿透平台
Scrapy + Selenium 实现模拟登录,获取页面动态加载数据
Mysql OCP 75 questions
Enter the SQL Client to create the table, in another node into the SQL Client queries
2022T电梯修理考试题及答案
投稿有礼,双社区签约博主名额等你赢!
大佬们,我遇到一个问题:我源端mysql有一张一直在写入的表,我使用mysql cdc connec
2022最新整理软件测试常见面试题附答案
With strong network, China mobile to calculate excitation surging energy network construction
Mysql OCP 30题
What is the IDE?Novice with which the IDE is better?
C language two-dimensional array is called with one-dimensional array
Let‘s Encrypt 使用
Oracle 迁移至Mysql
Promise 二:关键问题
集成学习、boosting、bagging、Adaboost、GBDT、随机森林
函数指针数组
pytorch安装错误
2022.8.2-----leetcode.622