count cluster by search metadata

This commit is contained in:
liugq 2022-03-23 23:00:08 +08:00
parent f76cbd9f84
commit 06c86dab11
1 changed files with 20 additions and 7 deletions

View File

@ -17,13 +17,26 @@ func (handler APIHandler) ElasticsearchOverviewAction(w http.ResponseWriter, req
totalStoreSize int totalStoreSize int
clusterIDs []interface{} clusterIDs []interface{}
) )
elastic.WalkConfigs(func(key, value interface{})bool{ //elastic.WalkConfigs(func(key, value interface{})bool{
if handler.Config.Elasticsearch == key { // if handler.Config.Elasticsearch == key {
return true // return true
// }
// clusterIDs = append(clusterIDs, key)
// return true
//})
esClient := elastic.GetClient(handler.Config.Elasticsearch)
searchRes, err := esClient.SearchWithRawQueryDSL(orm.GetIndexName(elastic.ElasticsearchConfig{}), nil)
if err != nil {
log.Error(err)
handler.WriteJSON(w, util.MapStr{
"error": err.Error(),
}, http.StatusInternalServerError)
return
}
for _, hit := range searchRes.Hits.Hits {
clusterIDs = append(clusterIDs, hit.ID)
} }
clusterIDs = append(clusterIDs, key)
return true
})
res, err := handler.getLatestClusterMonitorData(clusterIDs) res, err := handler.getLatestClusterMonitorData(clusterIDs)
if err != nil { if err != nil {