@@ -59,16 +59,29 @@ func GetExtMetrics(db, table, where, queryCacheTTL, orgID string, useQueryCache
5959 log .Error (err )
6060 return nil , err
6161 }
62+ customMetrics , err := common .GetCustomMetrics (orgID )
63+ if err != nil {
64+ log .Error (err .Error ())
65+ }
6266 for i , value := range externalMetricFloatRst .Values {
6367 tagName := value .([]interface {})[0 ]
6468 tableName := value .([]interface {})[1 ].(string )
6569 externalTag := tagName .(string )
6670 metrics_names_field , metrics_values_field := METRICS_ARRAY_NAME_MAP [db ][0 ], METRICS_ARRAY_NAME_MAP [db ][1 ]
6771 dbField := fmt .Sprintf ("if(indexOf(%s, '%s')=0, null, %s[indexOf(%s, '%s')])" , metrics_names_field , externalTag , metrics_values_field , metrics_names_field , externalTag )
6872 metricName := fmt .Sprintf ("metrics.%s" , externalTag )
73+ var mUnit , description string
74+ mType := METRICS_TYPE_COUNTER
75+ customMetric , ok := customMetrics [fmt .Sprintf ("%s.%s.%s" , db , tableName , externalTag )]
76+ if ok {
77+ mType = customMetric .Get ("TYPE" ).MustInt ()
78+ mUnit = customMetric .Get ("UNIT" ).MustString ()
79+ metricName = customMetric .Get ("DISPLAY_NAME" ).MustString ()
80+ description = customMetric .Get ("DESCRIPTION" ).MustString ()
81+ }
6982 lm := NewMetrics (
70- i , dbField , metricName , metricName , metricName , "" , "" , "" , METRICS_TYPE_COUNTER ,
71- common .NATIVE_FIELD_CATEGORY_METRICS , []bool {true , true , true }, "" , tableName , "" , "" , "" , "" , "" ,
83+ i , dbField , metricName , metricName , metricName , mUnit , mUnit , mUnit , mType ,
84+ common .NATIVE_FIELD_CATEGORY_METRICS , []bool {true , true , true }, "" , tableName , description , description , description , "" , "" ,
7285 )
7386 loadMetrics [fmt .Sprintf ("%s-%s" , metricName , tableName )] = lm
7487 }
@@ -101,8 +114,17 @@ func GetExtMetrics(db, table, where, queryCacheTTL, orgID string, useQueryCache
101114 if fieldType != common .NATIVE_FIELD_TYPE_METRIC {
102115 continue
103116 }
117+ var mUnit string
118+ mType := METRICS_TYPE_COUNTER
119+ customMetric , ok := customMetrics [fmt .Sprintf ("%s.%s.%s" , db , table , nativeMetric )]
120+ if ok {
121+ mType = customMetric .Get ("TYPE" ).MustInt ()
122+ mUnit = customMetric .Get ("UNIT" ).MustString ()
123+ displayName = customMetric .Get ("DISPLAY_NAME" ).MustString ()
124+ description = customMetric .Get ("DESCRIPTION" ).MustString ()
125+ }
104126 lm := NewMetrics (
105- len (loadMetrics ), nativeMetric , displayName , displayName , displayName , "" , "" , "" , METRICS_TYPE_COUNTER ,
127+ len (loadMetrics ), nativeMetric , displayName , displayName , displayName , mUnit , mUnit , mUnit , mType ,
106128 common .NATIVE_FIELD_CATEGORY_METRICS , []bool {true , true , true }, "" , table , description , description , description , "" , "" ,
107129 )
108130 loadMetrics [fmt .Sprintf ("%s-%s" , nativeMetric , table )] = lm
0 commit comments