count host from .infini_host priority

This commit is contained in:
liugq 2022-09-09 20:38:55 +08:00
parent 43b6322188
commit 320ee33390
2 changed files with 17 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import (
httprouter "infini.sh/framework/core/api/router"
"infini.sh/framework/core/elastic"
"infini.sh/framework/core/event"
"infini.sh/framework/core/host"
"infini.sh/framework/core/orm"
"infini.sh/framework/core/util"
"net/http"
@ -80,10 +81,19 @@ func (handler APIHandler) ElasticsearchOverviewAction(w http.ResponseWriter, req
}
}
hostCount, err := handler.getMetricCount(orm.GetIndexName(elastic.NodeConfig{}), "metadata.host", clusterIDs)
hostCount, err := handler.getMetricCount(orm.GetIndexName(host.HostInfo{}), "ip", nil)
if err != nil{
log.Error(err)
}
log.Info(hostCount)
if v, ok := hostCount.(float64); ok && v == 0 {
log.Error("sss")
hostCount, err = handler.getMetricCount(orm.GetIndexName(elastic.NodeConfig{}), "metadata.host", clusterIDs)
if err != nil{
log.Error(err)
}
}
nodeCount, err := handler.getMetricCount(orm.GetIndexName(elastic.NodeConfig{}), "id", clusterIDs)
if err != nil{
log.Error(err)

View File

@ -22,7 +22,7 @@ func (handler APIHandler) HandleGetMappingsAction(w http.ResponseWriter, req *ht
_, _, idxs, err := client.GetMapping(copyAll, indexName)
if err != nil {
log.Error(err)
resBody["error"] = err
resBody["error"] = err.Error()
handler.WriteJSON(w, resBody, http.StatusInternalServerError)
return
}
@ -91,14 +91,14 @@ func (handler APIHandler) HandleUpdateSettingsAction(w http.ResponseWriter, req
err := handler.DecodeJSON(req, &settings)
if err != nil {
log.Error(err)
resBody["error"] = err
resBody["error"] = err.Error()
handler.WriteJSON(w, resBody, http.StatusInternalServerError)
return
}
err = client.UpdateIndexSettings(indexName, settings)
if err != nil {
log.Error(err)
resBody["error"] = err
resBody["error"] = err.Error()
handler.WriteJSON(w, resBody, http.StatusInternalServerError)
return
}
@ -114,7 +114,7 @@ func (handler APIHandler) HandleDeleteIndexAction(w http.ResponseWriter, req *ht
err := client.DeleteIndex(indexName)
if err != nil {
log.Error(err)
resBody["error"] = err
resBody["error"] = err.Error()
handler.WriteJSON(w, resBody, http.StatusInternalServerError)
return
}
@ -132,14 +132,14 @@ func (handler APIHandler) HandleCreateIndexAction(w http.ResponseWriter, req *ht
err := handler.DecodeJSON(req, &config)
if err != nil {
log.Error(err)
resBody["error"] = err
resBody["error"] = err.Error()
handler.WriteJSON(w, resBody, http.StatusInternalServerError)
return
}
err = client.CreateIndex(indexName, config)
if err != nil {
log.Error(err)
resBody["error"] = err
resBody["error"] = err.Error()
handler.WriteJSON(w, resBody, http.StatusInternalServerError)
return
}