forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
294 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
fe/fe-core/src/main/java/org/apache/doris/metric/CloudMetricRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.metric; | ||
|
||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.cloud.system.CloudSystemInfoService; | ||
import org.apache.doris.common.Config; | ||
import org.apache.doris.metric.Metric.MetricUnit; | ||
|
||
import com.codahale.metrics.Histogram; | ||
import com.google.common.base.Strings; | ||
|
||
import java.util.List; | ||
|
||
public class CloudMetricRepo { | ||
protected static AutoMappedMetric<LongCounterMetric> CLUSTER_REQUEST_ALL_COUNTER; | ||
protected static AutoMappedMetric<LongCounterMetric> CLUSTER_QUERY_ALL_COUNTER; | ||
protected static AutoMappedMetric<LongCounterMetric> CLUSTER_QUERY_ERR_COUNTER; | ||
|
||
protected static AutoMappedMetric<GaugeMetricImpl<Double>> CLUSTER_REQUEST_PER_SECOND_GAUGE; | ||
protected static AutoMappedMetric<GaugeMetricImpl<Double>> CLUSTER_QUERY_PER_SECOND_GAUGE; | ||
protected static AutoMappedMetric<GaugeMetricImpl<Double>> CLUSTER_QUERY_ERR_RATE_GAUGE; | ||
protected static AutoMappedMetric<Histogram> CLUSTER_QUERY_LATENCY_HISTO; | ||
|
||
protected static AutoMappedMetric<GaugeMetricImpl<Integer>> CLUSTER_BACKEND_ALIVE; | ||
protected static AutoMappedMetric<GaugeMetricImpl<Integer>> CLUSTER_BACKEND_ALIVE_TOTAL; | ||
|
||
public static void init() { | ||
if (!Config.isCloudMode()) { | ||
return; | ||
} | ||
CLUSTER_REQUEST_ALL_COUNTER = new AutoMappedMetric<>(name -> { | ||
LongCounterMetric counter = new LongCounterMetric("request_total", MetricUnit.REQUESTS, | ||
"total request"); | ||
counter.addLabel(new MetricLabel("cluster_id", name)); | ||
MetricRepo.DORIS_METRIC_REGISTER.addMetrics(counter); | ||
return counter; | ||
}); | ||
|
||
CLUSTER_QUERY_ALL_COUNTER = new AutoMappedMetric<>(name -> { | ||
LongCounterMetric counter = new LongCounterMetric("query_total", MetricUnit.REQUESTS, | ||
"total query"); | ||
counter.addLabel(new MetricLabel("cluster_id", name)); | ||
MetricRepo.DORIS_METRIC_REGISTER.addMetrics(counter); | ||
return counter; | ||
}); | ||
|
||
CLUSTER_QUERY_ERR_COUNTER = new AutoMappedMetric<>(name -> { | ||
LongCounterMetric counter = new LongCounterMetric("query_err", MetricUnit.REQUESTS, | ||
"total error query"); | ||
counter.addLabel(new MetricLabel("cluster_id", name)); | ||
MetricRepo.DORIS_METRIC_REGISTER.addMetrics(counter); | ||
return counter; | ||
}); | ||
|
||
CLUSTER_REQUEST_PER_SECOND_GAUGE = new AutoMappedMetric<>(name -> { | ||
GaugeMetricImpl<Double> gauge = new GaugeMetricImpl<Double>("rps", MetricUnit.NOUNIT, | ||
"request per second"); | ||
gauge.addLabel(new MetricLabel("cluster_id", name)); | ||
MetricRepo.DORIS_METRIC_REGISTER.addMetrics(gauge); | ||
return gauge; | ||
}); | ||
|
||
CLUSTER_QUERY_PER_SECOND_GAUGE = new AutoMappedMetric<>(name -> { | ||
GaugeMetricImpl<Double> gauge = new GaugeMetricImpl<Double>("qps", MetricUnit.NOUNIT, | ||
"query per second"); | ||
gauge.addLabel(new MetricLabel("cluster_id", name)); | ||
MetricRepo.DORIS_METRIC_REGISTER.addMetrics(gauge); | ||
return gauge; | ||
}); | ||
|
||
CLUSTER_QUERY_ERR_RATE_GAUGE = new AutoMappedMetric<>(name -> { | ||
GaugeMetricImpl<Double> gauge = new GaugeMetricImpl<Double>("query_err_rate", MetricUnit.NOUNIT, | ||
"query error rate"); | ||
gauge.addLabel(new MetricLabel("cluster_id", name)); | ||
MetricRepo.DORIS_METRIC_REGISTER.addMetrics(gauge); | ||
return gauge; | ||
}); | ||
} | ||
|
||
public static void increaseClusterRequestAll(String clusterName) { | ||
if (!MetricRepo.isInit || !Config.isCloudMode() || Strings.isNullOrEmpty(clusterName)) { | ||
return; | ||
} | ||
String clusterId = ((CloudSystemInfoService) Env.getCurrentSystemInfo()) | ||
.getCloudClusterNameToId().get(clusterName); | ||
if (Strings.isNullOrEmpty(clusterId)) { | ||
return; | ||
} | ||
LongCounterMetric metric = CLUSTER_REQUEST_ALL_COUNTER.getOrAdd(clusterId); | ||
metric.addOrUpdateLabel(new MetricLabel("cluster_name", clusterName)); | ||
metric.increase(1L); | ||
} | ||
|
||
public static void increaseClusterQueryAll(String clusterName) { | ||
if (!MetricRepo.isInit || !Config.isCloudMode() || Strings.isNullOrEmpty(clusterName)) { | ||
return; | ||
} | ||
String clusterId = ((CloudSystemInfoService) Env.getCurrentSystemInfo()) | ||
.getCloudClusterNameToId().get(clusterName); | ||
if (Strings.isNullOrEmpty(clusterId)) { | ||
return; | ||
} | ||
LongCounterMetric metric = CLUSTER_QUERY_ALL_COUNTER.getOrAdd(clusterId); | ||
metric.addOrUpdateLabel(new MetricLabel("cluster_name", clusterName)); | ||
metric.increase(1L); | ||
} | ||
|
||
public static void increaseClusterQueryErr(String clusterName) { | ||
if (!MetricRepo.isInit || !Config.isCloudMode() || Strings.isNullOrEmpty(clusterName)) { | ||
return; | ||
} | ||
String clusterId = ((CloudSystemInfoService) Env.getCurrentSystemInfo()) | ||
.getCloudClusterNameToId().get(clusterName); | ||
if (Strings.isNullOrEmpty(clusterId)) { | ||
return; | ||
} | ||
LongCounterMetric metric = CLUSTER_QUERY_ERR_COUNTER.getOrAdd(clusterId); | ||
metric.addOrUpdateLabel(new MetricLabel("cluster_name", clusterName)); | ||
metric.increase(1L); | ||
} | ||
|
||
public static void updateClusterRequestPerSecond(String clusterId, double value, List<MetricLabel> labels) { | ||
if (!MetricRepo.isInit || !Config.isCloudMode() || Strings.isNullOrEmpty(clusterId)) { | ||
return; | ||
} | ||
GaugeMetricImpl<Double> metric = CLUSTER_REQUEST_PER_SECOND_GAUGE.getOrAdd(clusterId); | ||
metric.setLables(labels); | ||
metric.setValue(value); | ||
} | ||
|
||
public static void updateClusterQueryPerSecond(String clusterId, double value, List<MetricLabel> labels) { | ||
if (!MetricRepo.isInit || !Config.isCloudMode() || Strings.isNullOrEmpty(clusterId)) { | ||
return; | ||
} | ||
GaugeMetricImpl<Double> metric = CLUSTER_QUERY_PER_SECOND_GAUGE.getOrAdd(clusterId); | ||
metric.setLables(labels); | ||
metric.setValue(value); | ||
} | ||
|
||
public static void updateClusterQueryErrRate(String clusterId, double value, List<MetricLabel> labels) { | ||
if (!MetricRepo.isInit || !Config.isCloudMode() || Strings.isNullOrEmpty(clusterId)) { | ||
return; | ||
} | ||
GaugeMetricImpl<Double> metric = CLUSTER_QUERY_ERR_RATE_GAUGE.getOrAdd(clusterId); | ||
metric.setLables(labels); | ||
metric.setValue(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.