数据洞察 视图 视图模板 自建MySQL 监控
自建MySQL 监控
简介
展示 自建MySQL 的系统监控指标和数据库监控指标
前置条件
需安装 DataKit,并开启以下指标采集:
cpu mem net kernel kernel_vmstat disk swap processes mysql
数据库授权
create user datakit identified by Zyadmin123;
GRANT select,replication client ON *.* TO 'datakit'@'%';
flush privileges;
配置
打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到cpu
文件夹,打开里面的cpu.conf
。[[inputs.cpu]] # ## Whether to report per-cpu stats or not percpu = true ## Whether to report total system cpu stats or not totalcpu = true # ## If true, collect raw CPU time metrics. # collect_cpu_time = false ## If true, compute and report the sum of all non-idle CPU states. report_active = false
打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到memory
文件夹,打开里面的memory.conf
。# Read metrics about memory usage [[inputs.mem]] #no configuration
打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到。network
文件夹,打开里面的network.conf
# # Read metrics about network interface usage
[[inputs.net]]
# ## By default, telegraf gathers stats from any up interface (excluding loopback)
# ## Setting interfaces will tell it to gather these explicit interfaces,
# ## regardless of status.
# ##
# # interfaces = ["eth0"]
# ##
# ## On linux systems telegraf also collects protocol stats.
# ## Setting ignore_protocol_stats to true will skip reporting of protocol metrics.
# ##
# # ignore_protocol_stats = false
# ##
- 打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到kernel
文件夹,打开里面的kernel.conf
。
# Get kernel statistics from /proc/stat
[[inputs.kernel]]
# no configuration
# # Get kernel statistics from /proc/vmstat
[[inputs.kernel_vmstat]]
# # no configuration
- 打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到disk
文件夹,打开里面的disk.conf
。
# Read metrics about disk usage by mount point
[[inputs.disk]]
## By default stats will be gathered for all mount points.
## Set mount_points will restrict the stats to only the specified mount points.
# mount_points = ["/"]
## Ignore mount points by filesystem type.
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
- 打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到swap
文件夹,打开里面的swap.conf
。
# Read metrics about swap memory usage
[[inputs.swap]]
# no configuration
- 打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到processes
文件夹,打开里面的processes.conf
。
[[inputs.procstat]]
pid_file = "/alidata/mysql/data/MySQL-01.pid"
- 打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的
conf.d
文件夹),找到mysql
文件夹,打开里面的mysql.conf
。
[[inputs.mysql]]
interval = "300s"
servers = ["user:password@tcp(ip:port)/?tls=false"]
metric_version = 2
perf_events_statements_digest_text_limit = 120
perf_events_statements_limit = 250
perf_events_statements_time_limit = 86400
table_schema_databases = []
gather_table_schema = false
gather_process_list = true
gather_user_statistics = true
gather_info_schema_auto_inc = false
gather_innodb_metrics = true
gather_slave_status = true
gather_binary_logs = false
gather_table_io_waits = false
gather_table_lock_waits = false
gather_index_io_waits = false
gather_event_waits = false
gather_file_events_stats = false
gather_perf_events_statements = false
interval_slow = "30m"
[inputs.mysql.tags]
instance_name='DBA团队自建MySQL实例'
project='SuperCloud'
其中 servers 的格式:username[:password]@][protocol[(address)]]/[?tls=[true|false|skip-verify|custom]
配置好后,重启 DataKit 即可生效。
下面的shell 脚本可以将上述的所有配置文件自动开启,属于覆盖原油配置的方式,如果您需要快速打开配置可以使用。
# auto_configure_datakit_for_mysql
cd /usr/local/cloudcare/forethought/datakit/conf.d
cat > cpu/cpu.conf << ENDF1
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
ENDF1
cat > memory/memory.conf << ENDF2
[[inputs.mem]]
ENDF2
cat > network/network.conf << ENDF3
[[inputs.net]]
ENDF3
cat > kernel/kernel.conf << ENDF4
[[inputs.kernel]]
[[inputs.kernel_vmstat]]
ENDF4
cat > disk/disk.conf << ENDF5
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "overlay", "aufs", "squashfs"]
ENDF5
cat > swap/swap.conf << ENDF6
[[inputs.swap]]
ENDF6
mysql_pid=`ps -ef| grep mysql[d] | sed 's/.*pid-file=\(.*\)\.pid.*/\1.pid/' | tail -n 1`
cat > processes/processes.conf << ENDF7
[[inputs.procstat]]
pid_file = "$mysql_pid"
ENDF7
cat > mysql/mysql.conf << ENDF8
[[inputs.mysql]]
interval = "300s"
servers = ["user:password@tcp(ip:port)/?tls=false"]
metric_version = 2
perf_events_statements_digest_text_limit = 120
perf_events_statements_limit = 250
perf_events_statements_time_limit = 86400
table_schema_databases = []
gather_table_schema = false
gather_process_list = true
gather_user_statistics = true
gather_info_schema_auto_inc = false
gather_innodb_metrics = true
gather_slave_status = true
gather_binary_logs = false
gather_table_io_waits = false
gather_table_lock_waits = false
gather_index_io_waits = false
gather_event_waits = false
gather_file_events_stats = false
gather_perf_events_statements = false
interval_slow = "30m"
[inputs.mysql.tags]
instance_name='DBA团队自建MySQL实例'
project='SuperCloud'
ENDF8
概览
指标
监控图中使用的指标明细
measurements | Fields | Alias |
---|---|---|
mysql | aborted_connects | 尝试与服务器进行连接结果失败的次数 |
mysql | bytes_received | 平均每秒从所有客户端接收到的字节数 |
mysql | bytes_sent | 平均每秒发送给所有客户端的字节数 |
mysql | com_commit | 平均每秒事务数 TPS |
mysql | com_commit | Current QPS |
mysql | com_delete | 平均每秒delete语句执行次数 |
mysql | com_insert | 平均每秒insert语句执行次数 |
mysql | com_replace | 平均每秒replace语句执行次数 |
mysql | com_replace_select | 平均每秒replace_select语句执行次数 |
mysql | com_select | 平均每秒select语句执行次数 |
mysql | com_show_variables | 平均每秒show语句执行次数 |
mysql | com_update | 平均每秒update语句执行次数 |
mysql | connection_errors_internal | 由服务器错误导致的失败连接数 |
mysql | connection_errors_max_connections | 由 max_connections 限制导致的失败连接数 |
mysql | connections | 当前总连接数 |
mysql | created_tmp_disk_tables | 服务器执行语句时在硬盘上自动创建的临时表的数量 |
mysql | created_tmp_tables | 服务器执行语句时自动创建的内存中的临时表的数量 |
mysql | handler_commit | 每秒内部提交语句的次数 |
mysql | handler_delete | 每秒从表中删除行的次数 |
mysql | handler_discover | 每秒发现表的次数 |
mysql | handler_read_key | 每秒基于键读取行的次数 |
mysql | handler_read_rnd_next | 每秒读取数据文件中下一行的次数 |
mysql | handler_update | 每秒更新表中某一行的次数 |
mysql | handler_write | 每秒在表中插入行的次数 |
mysql | innodb_buffer_pool_pages_free | InnoDB缓冲池中的可用页数 |
mysql | innodb_buffer_pool_pages_total | InnoDB缓冲池的总大小(以页为单位) |
mysql | innodb_buffer_pool_read_requests | 平均每秒从物理磁盘读取页的次数 |
mysql | innodb_buffer_pool_read_requests | 平均每秒从InnoDB缓冲池读的次数 |
mysql | innodb_buffer_pool_reads | 平均每秒从innodb缓冲池的读次数(逻辑读请求数) |
mysql | innodb_buffer_pool_write_requests | 平均每秒往InnoDB缓冲池写入的次数 |
mysql | innodb_data_read | InnoDB平均每秒读取的数据量 |
mysql | innodb_data_written | InnoDB平均每秒写入的数据量 |
mysql | innodb_log_write_requests | 平均每秒日志写次数 |
mysql | innodb_log_writes | 平均每秒向日志文件的物理写次数 |
mysql | innodb_os_log_fsyncs | 平均每秒向日志文件完成的fsync的写次数 |
mysql | innodb_rows_deleted | 平均每秒从InnoDB表删除的行数 |
mysql | innodb_rows_inserted | 平均每秒从InnoDB表插入的行数 |
mysql | innodb_rows_read | 平均每秒从InnoDB表读取的行数 |
mysql | innodb_rows_updated | 平均每秒从InnoDB表更新的行数 |
mysql | open_files | 每秒打开文件数 |
mysql | open_files | 打开文件数量 |
mysql | open_tables | 每秒打开表数 |
mysql | opened_tables | 打开表数 |
mysql | questions | 平均每秒SQL语句执行次数 |
mysql | questions | Current QPS |
mysql | select_full_join | 每秒由于不使用索引而执行表扫描的联接数 |
mysql | select_full_range_join | 每秒在引用表上使用范围搜索的联接数 |
mysql | select_range | 每秒使用第一个表上的范围的联接数 |
mysql | select_range_check | 每秒在每行之后检查键用法的没有键的联接数 |
mysql | select_scan | 每秒对第一个表进行完全扫描的联接数 |
mysql | slow_queries | 每秒慢查询 |
mysql | sort_merge_passes | 每秒排序算法必须执行的合并传递数 |
mysql | sort_range | 每秒使用范围完成的排序数 |
mysql | sort_rows | 每秒已排序的行数 |
mysql | sort_scan | 每秒通过扫描表完成的排序数 |
mysql | threads_connected | 当前活跃连接数 |
mysql | uptime | 运行时长 |
mysql_dead_lock_rows | deadlock | 死锁总数 |
mysql_innodb_blocking_trx_id | command | 会话执行的语句类型 |
mysql_innodb_blocking_trx_id | db | 会话访问的数据库名 |
mysql_innodb_blocking_trx_id | host | 会话的来源地址 |
mysql_innodb_blocking_trx_id | id | 会话id |
mysql_innodb_blocking_trx_id | info | 会话执行的具体SQL语句 |
mysql_innodb_blocking_trx_id | state | 会话状态 |
mysql_innodb_blocking_trx_id | time | 会话持续时间 |
mysql_innodb_blocking_trx_id | trx_id | 事务id |
mysql_innodb_blocking_trx_id | trx_requested_lock_id | 等待事物的锁id |
mysql_innodb_blocking_trx_id | trx_started | 事务开始时间 |
mysql_innodb_blocking_trx_id | user | 会话的登录用户名 |
mysql_innodb_lock_waits | lock_data | 事务锁定记录的主键值 |
mysql_innodb_lock_waits | lock_id | 锁id |
mysql_innodb_lock_waits | lock_index | 锁住的索引 |
mysql_innodb_lock_waits | lock_mode | 锁的模式 |
mysql_innodb_lock_waits | lock_page | 事务锁定页的数量 |
mysql_innodb_lock_waits | lock_rec | 事务锁定行的数量 |
mysql_innodb_lock_waits | lock_space | 锁对象的space id |
mysql_innodb_lock_waits | lock_table | 申请锁的表 |
mysql_innodb_lock_waits | lock_trx_id | 事务id |
mysql_innodb_lock_waits | lock_type | 锁的类型 |
mysql_innodb_locks_counts | countnum | 行锁总数 |
mysql_innodb_status | name | engine别名 |
mysql_innodb_status | status | engine具体信息 |
mysql_innodb_status | type | engine类型 |
mysql_metadatalock_coun | count | 元锁总数 |
mysql_metadatalock_session | command | 会话执行的语句类型 |
mysql_metadatalock_session | db | 会话访问的数据库名 |
mysql_metadatalock_session | host | 会话的来源地址 |
mysql_metadatalock_session | id | 会话id |
mysql_metadatalock_session | info | 会话执行的具体SQL语句 |
mysql_metadatalock_session | state | 会话状态 |
mysql_metadatalock_session | time | 会话持续时间 |
mysql_metadatalock_session | user | 会话的登录用户名 |
mysql_metadatalock_trx_id | id | 导致元锁冲突的长时间未提交的事务会话id |
mysql_table_length | data_free | 碎片空间 |
mysql_table_length | data_length | 数据空间 |
mysql_table_length | engine | 存储引擎 |
mysql_table_length | index_length | 索引空间 |
mysql_table_length | rate_data_free | 碎片率 |
mysql_table_length | table_name | 表名 |
mysql_table_length | table_rows | 行数 |
mysql_table_length | table_schema | 数据库 |
mysql_table_length | total_length | 总空间 |
mysql_users | connections | 会话总数 |
mysql_users | user | 用户 |
mysql_variables | character_set_connection | 字符集 |
mysql_variables | innodb_version | 数据库版本 |
mysql_variables | long_query_time | 慢查询时间 |
mysql_variables | tx_isolation | 事务隔离级别 |