查詢ES集群全部索引的數據量


工作需要,查詢目前ES集群下各索引的數據量及日增量。用於資源管理統計。

查詢url:

http://clusterIP:clusterPort/_cat/indices?v

示例:

部分列說明:

index:索引名

status:是否啟用

rep:副本數

storesize:總大小(包含副本)

pristoresize:不包含副本的大小

 

C#代碼:

 1 public Dictionary<string, ResourceEntity> GetESTableSizeInfo()
 2         {
 3             Dictionary<string, ResourceEntity> result = new Dictionary<string, ResourceEntity>();
 4             StreamReader reader = null ;
 5             WebResponse rs = null;
 6             string uri = string.Format("{0}/_cat/indices?v", AppConfigGetter.Get(ConfigConstants.KEY_ESurl));
 7             try
 8             {
 9                 HttpWebRequest req = WebRequest.Create(new Uri(uri)) as HttpWebRequest;
10                 req.Method = "GET";
11                 rs = req.GetResponse();
12                 Stream rss = rs.GetResponseStream();
13                 reader = new StreamReader(rss);
14                 
15                 reader.ReadLine();
16                 string data = reader.ReadLine();
17                 
18                 while (string.IsNullOrEmpty(data) == false)
19                 {
20                     string[] fields = System.Text.RegularExpressions.Regex.Split(data, "[ ]+");
21                     if (fields.Length == 10)//如果是close的,則fields.Length=5
22                     {
23                         string index = fields[2];
24                         int copiesNum = Convert.ToInt32(fields[5]);
25                         string size_ = fields[8];
26                         if (result.ContainsKey(index)==false)
27                         {
28                             result.Add(index, new ResourceEntity()
29                             {
30                                 Type = ResourceType.ES,
31                                 TableName = index,
32                                 CopiesNum = copiesNum,
33                                 Size_B = DataUtils.FormatData_GetB(size_)
34                             });
35                         }
36                     }
37                     data = reader.ReadLine();
38                 }
39             }
40             catch
41             {
42                 throw;
43             }
44             finally
45             {
46                 if (null != reader)
47                     reader.Close();
48                 if (null != rs)
49                     rs.Close();
50             }
51             return result;
52         }
53     }
C#獲取ES索引數據量

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM