首页 > 其他分享 >统计es每天增加的索引和空间使用情况

统计es每天增加的索引和空间使用情况

时间:2023-10-17 16:06:19浏览次数:34  
标签:index 每天 current 索引 date size es previous

#!/bin/bash

# Elasticsearch集群的URL
es_url="http://localhost:9200"

# 索引名称的前缀(假设索引名称为 "logs-2023.06.15")
index_prefix="logs-"

# 获取当前日期
current_date=$(date +%Y.%m.%d)

# 获取前一天的日期
previous_date=$(date -d "yesterday" +%Y.%m.%d)

# 构建前一天和当前日期的索引名称
previous_index="${index_prefix}${previous_date}"
current_index="${index_prefix}${current_date}"

# 获取前一天和当前日期的文档数量
previous_docs=$(curl -s "${es_url}/${previous_index}/_count" | jq -r '.count')
current_docs=$(curl -s "${es_url}/${current_index}/_count" | jq -r '.count')

# 获取前一天和当前日期的索引大小(字节)
previous_size=$(curl -s "${es_url}/${previous_index}/_stats/store" | jq -r '.indices."'"${previous_index}"'".total.store.size_in_bytes')
current_size=$(curl -s "${es_url}/${current_index}/_stats/store" | jq -r '.indices."'"${current_index}"'".total.store.size_in_bytes')

# 计算索引增量
index_increment=$((current_docs - previous_docs))

# 计算索引大小增量(以MB为单位)
size_increment=$(( (current_size - previous_size) / 1024 / 1024 ))

# 保存结果到文件
result_file="${current_date}.txt"

echo "Index Increment on $current_date:" > "$result_file"
echo "Previous Index: $previous_index ($previous_docs documents, ${previous_size} bytes)" >> "$result_file"
echo "Current Index: $current_index ($current_docs documents, ${current_size} bytes)" >> "$result_file"
echo "Index Increment: $index_increment documents" >> "$result_file"
echo "Size Increment: ${size_increment} MB" >> "$result_file"


标签:index,每天,current,索引,date,size,es,previous
From: https://blog.51cto.com/u_16133235/7905439

相关文章

  • ES6 module模块
    概述ES6中的module指的是JavaScript模块化规范中的一种。它通过export和import语法来导出和导入模块中的变量、函数、类等内容。使用ES6模块化的好处包括:解决了模块化的问题。消除了全局变量。管理加载顺序。使用在ES6模块中,一个文件代表一个模块当使用script标签加载模块时,需要......
  • 在Matplotlib中使用多线程multiprocessing举例
    在Matplotlib中使用多线程Matplotlib提供了一些机制来支持多线程的使用,比如使用matplotlib.pyplot.switch_backend()方法指定可用的图形后端或使用matplotlib.figure.Figure对象的canvas属性来实现绘图。但是,这些机制都需要特别小心地管理和控制,否则会引发线程之间的数据竞争和访......
  • 每天5分钟复习OpenStack(五)CPU虚拟化
    KVM虚拟化之CPU虚拟化存在是为了更高效的利用物理机的资源,而虚拟机技术主要是针对三大组件,分别是CPU虚拟化、存储虚拟化、网络虚拟化。下面我们分别介绍下三大组件的常用知识。CPU虚拟化1.1CPU虚拟化支持KVM的虚拟化是需要CPU硬件支持的。还记得我们在前面的章节讲过......
  • 在 kubernetes 环境中实现 gRPC 负载均衡
    前言前段时间写过一篇gRPC的入门文章,在最后还留了一个坑没有填:也就是gRPC的负载均衡问题,因为当时的业务请求量不算大,再加上公司没有对Istio这类服务网格比较熟悉的大牛,所以我们也就一直拖着没有解决,依然只是使用了kubernetes的service进行负载,好在也没有出什么问题......
  • [907] Merge multiple PDF files into one in Python
    YoucanmergemultiplePDFfilesintooneusingvariousPythonlibraries.OnecommonapproachistousethePyPDF2library,whichallowsyoutomanipulatePDFfiles.Here'sastep-by-stepguidetomergingmultiplePDFsintooneusingPyPDF2:First,......
  • [908] Implementation of the progress bar in Python
    YoucanimplementaprogressbarinPythontovisuallyrepresenttheprogressofataskusingvariouslibraries.Onecommonlyusedlibraryforthispurposeistqdm.Here'showtousetqdmtocreateasimpleprogressbar:First,youneedtoinstall......
  • 2023香山杯nesting详解
    nesting通过函数分析,有一个VM的指令解析器,也看不懂,VM的题看起来特别费劲在sub_16BC里面找cmp的flag比对指令,0x1E21和0x1EC9。最终发现输入正确的字符和错误的字符,0x1E21处的指令执行次数不一样,可以通过输入fo,fl,fi,其中fl是正确的字符,发现正确的字符在0x1E21处执行的次数更多,因......
  • [906] Replace NaN (Not-a-Number) values with 'Null' in Pandas
    InPandas,youcanreplaceNaN(Not-a-Number)valuesinaDataFramewithNone(Python'sNonetype)ornp.nan(NumPy'sNaN)values.Here'showyoucanreplaceNaNvalueswithNone:importpandasaspdimportnumpyasnp#CreateasampleDa......
  • 线上临时文件夹报错Failed to parse multipart servlet request; nested exception is
    线上临时文件夹报错Failedtoparsemultipartservletrequest;nestedexceptionisjava.lang.RuntimeException:java.nio.file.NoSuchFileException......
  • es - Kibana API - 批量插入
    (3).批量插入:POST_bulk{"index":{"_index":"books","_id":"19553"}}{"BookID":19552,"BookName":"C语言程序设计实验指导与习题解答","BookIntr":"导语_点评_推荐词","Book......