package com.easy.es.monitor;
import com.alibaba.fastjson.JSON;
import com.easy.es.common.CommonUtils;
import com.easy.es.network.HttpClientResp;
import com.easy.es.network.HttpUtils;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
/**
* 集群统计
* @author on 2022/10/25.
*/
@Data
public class ClusterStats {
private static final String API = "/_cluster/stats";
public static ClusterStats getClusterStats(String host, String port) throws IOException, URISyntaxException {
HttpClientResp httpClientResp = HttpUtils.doGet(CommonUtils.getUrl(host, port, API));
if (200 == httpClientResp.getCode()) {
return JSON.parseObject(httpClientResp.getContent(), ClusterStats.class);
}
return null;
}
/**
* 响应节点统计
*/
private NodesDTO _nodes;
/**
*集群名称
*/
private String cluster_name;
/**
*统计时间戳
*/
private Long timestamp;
/**
*集群状态
*/
private String status;
/**
*索引信息
*/
private IndicesDTO indices;
/**
* 节点详情
*/
private NodesDTOX nodes;
@NoArgsConstructor
@Data
public static class NodesDTO {
/**
* 请求选择的节点总数
*/
private Integer total;
/**
* 成功响应的节点数
*/
private Integer successful;
/**
* 拒绝响应+响应失败的节点数
*/
private Integer failed;
}
@NoArgsConstructor
@Data
public static class IndicesDTO {
/**
* 索引总数
*/
private Integer count;
/**
* 统计的分片信息
*/
private IndicesDTO.ShardsDTO shards;
/**
* 文档信息统计
*/
private IndicesDTO.DocsDTO docs;
/**
* 分片大小统计
*/
private IndicesDTO.StoreDTO store;
/**
* field data cache 统计
*/
private IndicesDTO.FielddataDTO fielddata;
/**
* query cache 统计
*/
private IndicesDTO.QueryCacheDTO query_cache;
/**
* 段信息 统计
*/
private IndicesDTO.SegmentsDTO segments;
@NoArgsConstructor
@Data
public static class ShardsDTO {
/**
* 分片总数
*/
private Integer total;
/**
* 主分片总数
*/
private Integer primaries;
/**
* 副分片与主分片的比率
*/
private Double replication;
/**
* 索引信息
*/
private IndicesDTO.ShardsDTO.IndexDTO index;
@NoArgsConstructor
@Data
public static class IndexDTO {
/**
* 索引分片信息
*/
private IndicesDTO.ShardsDTO.IndexDTO.ShardDTO shards;
/**
* 索引主分片信息
*/
private IndicesDTO.ShardsDTO.IndexDTO.PrimariesDTO primaries;
/**
* 索引副分片信息
*/
private IndicesDTO.ShardsDTO.IndexDTO.ReplicationDTO replication;
@NoArgsConstructor
@Data
public static class ShardDTO {
/**
* 索引中的最小分片数
*/
private Integer min;
/**
* 索引中的最大分片数
*/
private Integer max;
/**
* 索引中的平均分片数
*/
private Double avg;
}
@NoArgsConstructor
@Data
public static class PrimariesDTO {
/**
* 索引中的最小主分片数
*/
private Integer min;
/**
* 索引中的最大主分片数
*/
private Integer max;
/**
* 索引中的平均主分片数
*/
private Double avg;
}
@NoArgsConstructor
@Data
public static class ReplicationDTO {
/**
* 索引中的最小副本系数
*/
private Double min;
/**
* 索引中的最大副本系数
*/
private Double max;
/**
* 索引中的平均副本系数
*/
private Double avg;
}
}
}
@NoArgsConstructor
@Data
public static class DocsDTO {
/**
* 所有主分片的未删除文档的数量
*/
private Integer count;
/**
* 所有主分片的已删除文档的数量
*/
private Integer deleted;
}
@NoArgsConstructor
@Data
public static class StoreDTO {
/**
* 分片大小
*/
private Long size_in_bytes;
}
@NoArgsConstructor
@Data
public static class FielddataDTO {
/**
* 占用的内存大小
*/
private Integer memory_size_in_bytes;
/**
* 驱逐的次数
*/
private Integer evictions;
}
@NoArgsConstructor
@Data
public static class QueryCacheDTO {
/**
* 内存占用大小
*/
private Integer memory_size_in_bytes;
/**
* 命中和未命中总数
*/
private Integer total_count;
/**
* 命中总数
*/
private Integer hit_count;
/**
* 未命中总数
*/
private Integer miss_count;
/**
* 缓存的条目数
*/
private Integer cache_size;
/**
* 添加到缓存中的条目数
*/
private Integer cache_count;
/**
* 从缓存中移除的次数
*/
private Integer evictions;
}
@NoArgsConstructor
@Data
public static class SegmentsDTO {
/**
* 总数
*/
private Integer count;
/**
* 内存占用
*/
private Integer memory_in_bytes;
/**
* 分词占用内存大小
*/
private Integer terms_memory_in_bytes;
}
}
@NoArgsConstructor
@Data
public static class NodesDTOX {
private NodesDTOX.CountDTO count;
private NodesDTOX.FsDTO fs;
@NoArgsConstructor
@Data
public static class CountDTO {
/**
* 总节点个数
*/
private Integer total;
/**
* 数据节点个数
*/
private Integer data;
/**
* 无角色节点个数
*/
private Integer coordinating_only;
/**
* 主节点个数
*/
private Integer master;
/**
* 消费节点个数
*/
private Integer ingest;
}
@NoArgsConstructor
@Data
public static class FsDTO {
/**
* 磁盘空间总大小
*/
private Long total_in_bytes;
/**
* 剩余磁盘空间大小
*/
private Long free_in_bytes;
/**
* 可用磁盘空间大小
*/
private Long available_in_bytes;
}
}
}