@@ -495,7 +495,12 @@ func (h *APIHandler) FetchHostInfo(w http.ResponseWriter, req *http.Request, ps
495
495
Units : "/s" ,
496
496
},
497
497
}
498
- hostMetrics := h .getGroupHostMetric (context .Background (), agentIDs , min , max , bucketSize , hostMetricItems , "agent.id" )
498
+ hostMetrics , err := h .getGroupHostMetric (context .Background (), agentIDs , min , max , bucketSize , hostMetricItems , "agent.id" )
499
+ if err != nil {
500
+ log .Error (err )
501
+ h .WriteError (w , err .Error (), http .StatusInternalServerError )
502
+ return
503
+ }
499
504
500
505
networkMetrics := map [string ]util.MapStr {}
501
506
for key , item := range hostMetrics {
@@ -572,7 +577,7 @@ func (h *APIHandler) GetHostInfo(w http.ResponseWriter, req *http.Request, ps ht
572
577
573
578
}
574
579
575
- func (h * APIHandler ) getSingleHostMetric (ctx context.Context , agentID string , min , max int64 , bucketSize int , metricItems []* common.MetricItem ) map [string ]* common.MetricItem {
580
+ func (h * APIHandler ) getSingleHostMetric (ctx context.Context , agentID string , min , max int64 , bucketSize int , metricItems []* common.MetricItem ) ( map [string ]* common.MetricItem , error ) {
576
581
var must = []util.MapStr {
577
582
{
578
583
"term" : util.MapStr {
@@ -608,7 +613,7 @@ func (h *APIHandler) getSingleHostMetric(ctx context.Context, agentID string, mi
608
613
return h .getSingleMetrics (ctx , metricItems , query , bucketSize )
609
614
}
610
615
611
- func (h * APIHandler ) getSingleHostMetricFromNode (ctx context.Context , nodeID string , min , max int64 , bucketSize int , metricKey string ) map [string ]* common.MetricItem {
616
+ func (h * APIHandler ) getSingleHostMetricFromNode (ctx context.Context , nodeID string , min , max int64 , bucketSize int , metricKey string ) ( map [string ]* common.MetricItem , error ) {
612
617
var must = []util.MapStr {
613
618
{
614
619
"term" : util.MapStr {
@@ -725,7 +730,12 @@ func (h *APIHandler) GetSingleHostMetrics(w http.ResponseWriter, req *http.Reque
725
730
ctx , cancel := context .WithTimeout (context .Background (), du )
726
731
defer cancel ()
727
732
if hostInfo .AgentID == "" {
728
- resBody ["metrics" ] = h .getSingleHostMetricFromNode (ctx , hostInfo .NodeID , min , max , bucketSize , key )
733
+ resBody ["metrics" ], err = h .getSingleHostMetricFromNode (ctx , hostInfo .NodeID , min , max , bucketSize , key )
734
+ if err != nil {
735
+ log .Error (err )
736
+ h .WriteError (w , err , http .StatusInternalServerError )
737
+ return
738
+ }
729
739
h .WriteJSON (w , resBody , http .StatusOK )
730
740
return
731
741
}
@@ -788,20 +798,30 @@ func (h *APIHandler) GetSingleHostMetrics(w http.ResponseWriter, req *http.Reque
788
798
metricItem .AddLine ("Disk Write Rate" , "Disk Write Rate" , "network write rate of host." , "group1" , "payload.host.diskio_summary.write.bytes" , "max" , bucketSizeStr , "%" , "bytes" , "0,0.[00]" , "0,0.[00]" , false , true )
789
799
metricItems = append (metricItems , metricItem )
790
800
case DiskPartitionUsageMetricKey , NetworkInterfaceOutputRateMetricKey :
791
- groupMetrics := h .getGroupHostMetrics (ctx , hostInfo .AgentID , min , max , bucketSize , key )
792
- resBody ["metrics" ] = groupMetrics
801
+ resBody ["metrics" ] , err = h .getGroupHostMetrics (ctx , hostInfo .AgentID , min , max , bucketSize , key )
802
+ if err != nil {
803
+ log .Error (err )
804
+ h .WriteError (w , err , http .StatusInternalServerError )
805
+ return
806
+ }
793
807
h .WriteJSON (w , resBody , http .StatusOK )
794
808
return
795
809
}
796
- hostMetrics := h .getSingleHostMetric (ctx , hostInfo .AgentID , min , max , bucketSize , metricItems )
810
+ hostMetrics , err := h .getSingleHostMetric (ctx , hostInfo .AgentID , min , max , bucketSize , metricItems )
811
+ if err != nil {
812
+ log .Error (err )
813
+ h .WriteError (w , err , http .StatusInternalServerError )
814
+ return
815
+ }
797
816
798
817
resBody ["metrics" ] = hostMetrics
799
818
800
819
h .WriteJSON (w , resBody , http .StatusOK )
801
820
}
802
821
803
- func (h * APIHandler ) getGroupHostMetrics (ctx context.Context , agentID string , min , max int64 , bucketSize int , metricKey string ) map [string ]* common.MetricItem {
822
+ func (h * APIHandler ) getGroupHostMetrics (ctx context.Context , agentID string , min , max int64 , bucketSize int , metricKey string ) ( map [string ]* common.MetricItem , error ) {
804
823
var metrics = make (map [string ]* common.MetricItem )
824
+ var err error
805
825
switch metricKey {
806
826
case DiskPartitionUsageMetricKey :
807
827
diskPartitionMetric := newMetricItem (DiskPartitionUsageMetricKey , 2 , SystemGroupKey )
@@ -817,7 +837,7 @@ func (h *APIHandler) getGroupHostMetrics(ctx context.Context, agentID string, mi
817
837
Units : "%" ,
818
838
},
819
839
}
820
- metrics = h .getGroupHostMetric (ctx , []string {agentID }, min , max , bucketSize , hostMetricItems , "payload.host.disk_partition_usage.partition" )
840
+ metrics , err = h .getGroupHostMetric (ctx , []string {agentID }, min , max , bucketSize , hostMetricItems , "payload.host.disk_partition_usage.partition" )
821
841
case NetworkInterfaceOutputRateMetricKey :
822
842
networkOutputMetric := newMetricItem (NetworkInterfaceOutputRateMetricKey , 2 , SystemGroupKey )
823
843
networkOutputMetric .AddAxi ("Network interface output rate" , "group1" , common .PositionLeft , "bytes" , "0.[0]" , "0.[0]" , 5 , true )
@@ -832,13 +852,13 @@ func (h *APIHandler) getGroupHostMetrics(ctx context.Context, agentID string, mi
832
852
Units : "" ,
833
853
},
834
854
}
835
- metrics = h .getGroupHostMetric (ctx , []string {agentID }, min , max , bucketSize , hostMetricItems , "payload.host.network_interface.name" )
855
+ metrics , err = h .getGroupHostMetric (ctx , []string {agentID }, min , max , bucketSize , hostMetricItems , "payload.host.network_interface.name" )
836
856
}
837
857
838
- return metrics
858
+ return metrics , err
839
859
}
840
860
841
- func (h * APIHandler ) getGroupHostMetric (ctx context.Context , agentIDs []string , min , max int64 , bucketSize int , hostMetricItems []GroupMetricItem , groupField string ) map [string ]* common.MetricItem {
861
+ func (h * APIHandler ) getGroupHostMetric (ctx context.Context , agentIDs []string , min , max int64 , bucketSize int , hostMetricItems []GroupMetricItem , groupField string ) ( map [string ]* common.MetricItem , error ) {
842
862
var must = []util.MapStr {
843
863
{
844
864
"term" : util.MapStr {
0 commit comments