es中的index大小信息存入mysql

前言

直接上干活

一、数据库信息

shell 复制代码
mysql -h172.21.240.11 -P3307 -uroot -p"123456" -D elk
# 数据量增长情况
# 一张表,一天增量500条,一年182500条,5年共912500条。5年满打满算才100w条。
  1. 数据库信息 mysql -h172.21.240.11 -P3307 -uroot -p"123456" -D elk

  2. 表信息

js 复制代码
create table ks_indices
(
`index_name` varchar(255) not null,
`topic_name` varchar(255),
`index_date` date,
`index_idc` varchar(255),
`index_size` varchar(255),
`index_size_t` BIGINT,
`create_time` date,
`update_time` date,
`delete_time` date,
`is_tag` BOOLEAN,
PRIMARY KEY (index_name)
) CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

#
CREATE TABLE wg_indices (
`index_name` VARCHAR(255) not null,
`topic_name` VARCHAR(255),
`index_date` DATE,
`index_idc` VARCHAR(255),
`index_size` VARCHAR(255),
`index_size_t` BIGINT,
`create_time` DATE,
`update_time` DATE,
`delete_time` DATE,
`is_tag` BOOLEAN,
PRIMARY KEY (index_name)
) CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

二、python处理逻辑

Prometheus的es exporter地址为: http://172.25.178.245:9114/metrics,其中有一个metrics为elasticsearch_indices_store_size_bytes_total,形式为 elasticsearch_indices_store_size_bytes_total{cluster="00g0sr8qbpab",index=".kibana_1"} 1.523535e+06

现在取 elasticsearch_indices_store_size_bytes_total 指标中的index(日期为前一天的所有index)和最后的size值,如果size为科学计数法1.523535e+06则需要换算成int型的数字,index插入到elk.ks_indices的index_name中;

size插入到lk.ks_indices的index_size中; index的名字中剔除日期部分(如: -2024.11.05 后缀剔除),然后插入到elk.ks_indices的topic_name中; 插入时间获取当前时间,然后插入到elk.ks_indices的create_time 字段中; 在elk.ks_indices的index_idc 中写入yumc3 其余字段保持空。

三、插入后的数据信息

四、补充

  1. 相关命令
js 复制代码
#
select count(1) from elk.ks_indices\G

#
select * from elk.ks_indices limit 5;
select * from elk.ks_indices limit 1,20 \G
select * from elk.ks_indices where topic_name="mid-uh" limit 10;
select count(1) from elk.ks_indices limit 5;
delete from elk.ks_indices limit 5;
alter table elk.ks_indices modify index_size varchar(255) comment '单位GB';

#
select * from elk.wg_indices limit 5;
select * from elk.wg_indices limit 1,20 \G
select * from elk.wg_indices where topic_name="mid-uh" limit 10;
  1. python执行方式
js 复制代码
python3 /data/jenkins/jenkins_home/workspace/ELK/get.elk.log.size/ks_elk_indices_size.py >> ./elk_topic.log

python3 /data/jenkins/jenkins_home/workspace/ELK/get.elk.log.size/wg_elk_indices_size.py >> ./elk_topic.log
相关推荐
yuyue_9992 小时前
理解 mvcc
mysql
码码哈哈爱分享5 小时前
MariaDB 与 MySQL 区别
数据库·mysql·mariadb
爱敲代码的TOM5 小时前
深入MySQL底层1-存储引擎与索引
数据库·mysql
sz-lcw8 小时前
MySQL知识笔记
笔记·mysql·adb
牛奶咖啡138 小时前
关系数据库MySQL的常用基础命令详解实战
数据库·mysql·本地远程连接到mysql·创建mysql用户和密码·修改mysql用户的密码·设置mysql密码的使用期限·设置和移除mysql用户的权限
没有bug.的程序员9 小时前
MVCC(多版本并发控制):InnoDB 高并发的核心技术
java·大数据·数据库·mysql·mvcc
什么半岛铁盒11 小时前
C++项目:仿muduo库高并发服务器-------Channel模块实现
linux·服务器·数据库·c++·mysql·ubuntu
muxin-始终如一13 小时前
MySQL与Redis面试问题详解
数据库·redis·mysql
博睿谷IT99_15 小时前
SQL SELECT 语句怎么用?COMPANY 表查询案例(含条件 / 模糊 / 分页)
数据库·sql·mysql
浅拾光º15 小时前
mysql字符串截取,如何在MySQL备份文件中安全截取敏感字符串?
数据库·mysql·安全