This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new c47cb7f36c9 Refactor MetricsCollectorRegistry (#23638)
c47cb7f36c9 is described below
commit c47cb7f36c9735aa0f0e82b707b554c6ec341989
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 18 22:33:15 2023 +0800
Refactor MetricsCollectorRegistry (#23638)
* Refactor MetricsCollectorRegistry
* Refactor PrometheusCollectorFactory
---
.../core/collector/MetricsCollectorRegistry.java | 6 +--
.../type/GaugeMetricFamilyMetricsCollector.java} | 34 +++++++++--------
.../collector/PrometheusCollectorFactory.java | 43 +++-------------------
.../collector/business/BuildInfoCollector.java | 11 +++---
.../business/proxy/ProxyMetaDataInfoCollector.java | 15 ++++----
.../business/proxy/ProxyStateCollector.java | 14 +++++--
.../collector/type/PrometheusCounterCollector.java | 2 +-
.../collector/type/PrometheusGaugeCollector.java | 2 +-
...a => PrometheusGaugeMetricFamilyCollector.java} | 24 ++++++------
.../type/PrometheusHistogramCollector.java | 2 +-
.../collector/type/PrometheusSummaryCollector.java | 2 +-
.../META-INF/conf/prometheus-metrics.yaml | 2 +-
.../META-INF/conf/prometheus-metrics.yaml | 2 -
13 files changed, 68 insertions(+), 91 deletions(-)
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
index be81c69f3c4..96d4be07d16 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
@@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public final class MetricsCollectorRegistry {
- private static final Map<String, MetricsCollector> METRICS_COLLECTORS =
new ConcurrentHashMap<>();
+ private static final Map<String, MetricsCollector> COLLECTORS = new
ConcurrentHashMap<>();
/**
* Get metrics collector.
@@ -40,7 +40,7 @@ public final class MetricsCollectorRegistry {
*/
@SuppressWarnings("unchecked")
public static <T extends MetricsCollector> T get(final String id, final
String pluginType) {
- T result = (T) METRICS_COLLECTORS.get(id);
- return (T) (null == result ? METRICS_COLLECTORS.computeIfAbsent(id,
PluginServiceLoader.getServiceLoader(MetricsCollectorFactory.class).getService(pluginType)::create)
: result);
+ T result = (T) COLLECTORS.get(id);
+ return (T) (null == result ? COLLECTORS.computeIfAbsent(id,
PluginServiceLoader.getServiceLoader(MetricsCollectorFactory.class).getService(pluginType)::create)
: result);
}
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/GaugeMetricFamilyMetricsCollector.java
similarity index 55%
copy from
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
copy to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/GaugeMetricFamilyMetricsCollector.java
index f142ffee90e..17942392557 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/GaugeMetricFamilyMetricsCollector.java
@@ -15,25 +15,29 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
+package org.apache.shardingsphere.agent.plugin.metrics.core.collector.type;
-import io.prometheus.client.Summary;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.SummaryMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
+
+import java.util.List;
/**
- * Prometheus summary wrapper.
+ * Gauge metric family metrics collector.
*/
-public final class PrometheusSummaryCollector implements
SummaryMetricsCollector {
-
- private final Summary summary;
+public interface GaugeMetricFamilyMetricsCollector extends MetricsCollector {
- public PrometheusSummaryCollector(final MetricConfiguration config) {
- summary =
Summary.build().name(config.getId()).help(config.getHelp()).labelNames(config.getLabels().toArray(new
String[0])).register();
- }
+ /**
+ * Add metric.
+ *
+ * @param labelValues label values
+ * @param value value
+ */
+ void addMetric(List<String> labelValues, double value);
- @Override
- public void observe(final double value) {
- summary.observe(value);
- }
+ /**
+ * Get raw metric family object.
+ *
+ * @return raw metric family object
+ */
+ Object getRawMetricFamilyObject();
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
index 9f47be186a7..1d87deed2d2 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
@@ -17,20 +17,18 @@
package org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector;
-import io.prometheus.client.GaugeMetricFamily;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricsConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.yaml.loader.YamlMetricConfigurationsLoader;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.yaml.swapper.YamlMetricsConfigurationSwapper;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusCounterCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeMetricFamilyCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusHistogramCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusSummaryCollector;
-import java.util.List;
-
/**
* Prometheus metrics collector factory.
*/
@@ -44,10 +42,7 @@ public final class PrometheusCollectorFactory implements
MetricsCollectorFactory
@Override
public MetricsCollector create(final String id) {
- return create(getMetricConfiguration(id));
- }
-
- private MetricsCollector create(final MetricConfiguration metricConfig) {
+ MetricConfiguration metricConfig = METRICS_CONFIG.get(id);
switch (metricConfig.getType().toUpperCase()) {
case "COUNTER":
return new PrometheusCounterCollector(metricConfig);
@@ -57,39 +52,13 @@ public final class PrometheusCollectorFactory implements
MetricsCollectorFactory
return new PrometheusHistogramCollector(metricConfig);
case "SUMMARY":
return new PrometheusSummaryCollector(metricConfig);
+ case "GAUGE_METRIC_FAMILY":
+ return new PrometheusGaugeMetricFamilyCollector(metricConfig);
default:
throw new UnsupportedOperationException(String.format("Can not
support type `%s`.", metricConfig.getType()));
}
}
- private MetricConfiguration getMetricConfiguration(final String id) {
- return METRICS_CONFIG.get(id);
- }
-
- /**
- * Create gauge metric family.
- *
- * @param id metric id
- * @return gauge metric family
- */
- public GaugeMetricFamily createGaugeMetricFamily(final String id) {
- MetricConfiguration metricConfig = getMetricConfiguration(id);
- List<String> labels = metricConfig.getLabels();
- return labels.isEmpty() ? new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), 1d) : new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), labels);
- }
-
- /**
- * Create gauge metric with value.
- *
- * @param id metric id
- * @param value value
- * @return gauge metric
- */
- public GaugeMetricFamily createGaugeMetric(final String id, final double
value) {
- MetricConfiguration metricConfig = getMetricConfiguration(id);
- return new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), value);
- }
-
@Override
public String getType() {
return "Prometheus";
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
index 440477e824b..5cceec954bb 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
@@ -20,7 +20,8 @@ package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.busi
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
import org.apache.shardingsphere.proxy.Bootstrap;
import java.util.Arrays;
@@ -35,21 +36,19 @@ public final class BuildInfoCollector extends Collector {
private static final String BUILD_INFO_METRIC_KEY = "build_info";
- private static final PrometheusCollectorFactory FACTORY = new
PrometheusCollectorFactory();
-
private final boolean isEnhancedForProxy;
@Override
public List<MetricFamilySamples> collect() {
- GaugeMetricFamily artifactInfo =
FACTORY.createGaugeMetricFamily(BUILD_INFO_METRIC_KEY);
+ GaugeMetricFamilyMetricsCollector artifactInfo =
MetricsCollectorRegistry.get(BUILD_INFO_METRIC_KEY, "Prometheus");
addMetric(artifactInfo, getClass().getPackage());
if (isEnhancedForProxy) {
addMetric(artifactInfo, Bootstrap.class.getPackage());
}
- return Collections.singletonList(artifactInfo);
+ return Collections.singletonList((GaugeMetricFamily)
artifactInfo.getRawMetricFamilyObject());
}
- private void addMetric(final GaugeMetricFamily artifactInfo, final Package
pkg) {
+ private void addMetric(final GaugeMetricFamilyMetricsCollector
artifactInfo, final Package pkg) {
String version = null == pkg.getImplementationVersion() ? "unknown" :
pkg.getImplementationVersion();
String name = null == pkg.getImplementationTitle() ? "unknown" :
pkg.getImplementationTitle();
artifactInfo.addMetric(Arrays.asList(version, name), 1L);
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
index 9f1f272f3dd..3f22d324b28 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
@@ -20,7 +20,8 @@ package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.busi
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import lombok.extern.slf4j.Slf4j;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
import
org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -48,23 +49,21 @@ public final class ProxyMetaDataInfoCollector extends
Collector {
private static final String ACTUAL_DB_COUNT = "database_count";
- private static final PrometheusCollectorFactory FACTORY = new
PrometheusCollectorFactory();
-
@Override
public List<MetricFamilySamples> collect() {
List<MetricFamilySamples> result = new LinkedList<>();
- GaugeMetricFamily metaDataInfo =
FACTORY.createGaugeMetricFamily(PROXY_METADATA_INFO_METRIC_KEY);
+ GaugeMetricFamilyMetricsCollector metaDataInfo =
MetricsCollectorRegistry.get(PROXY_METADATA_INFO_METRIC_KEY, "Prometheus");
if (null != ProxyContext.getInstance().getContextManager()) {
collectProxy(metaDataInfo);
- result.add(metaDataInfo);
+ result.add((GaugeMetricFamily)
metaDataInfo.getRawMetricFamilyObject());
}
return result;
}
- private void collectProxy(final GaugeMetricFamily metricFamily) {
+ private void collectProxy(final GaugeMetricFamilyMetricsCollector
collector) {
MetaDataContexts metaDataContexts =
ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- metricFamily.addMetric(Collections.singletonList(LOGIC_DB_COUNT),
metaDataContexts.getMetaData().getDatabases().size());
- metricFamily.addMetric(Collections.singletonList(ACTUAL_DB_COUNT),
getDatabaseNames(metaDataContexts).size());
+ collector.addMetric(Collections.singletonList(LOGIC_DB_COUNT),
metaDataContexts.getMetaData().getDatabases().size());
+ collector.addMetric(Collections.singletonList(ACTUAL_DB_COUNT),
getDatabaseNames(metaDataContexts).size());
}
private Collection<String> getDatabaseNames(final MetaDataContexts
metaDataContexts) {
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
index 29c845bca07..a45e9640279 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
@@ -18,10 +18,13 @@
package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
import io.prometheus.client.Collector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory;
+import io.prometheus.client.GaugeMetricFamily;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeMetricFamilyCollector;
import org.apache.shardingsphere.infra.state.StateContext;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@@ -33,8 +36,6 @@ public final class ProxyStateCollector extends Collector {
public static final String PROXY_STATE_METRIC_KEY = "proxy_state";
- private static final PrometheusCollectorFactory FACTORY = new
PrometheusCollectorFactory();
-
@Override
public List<MetricFamilySamples> collect() {
List<MetricFamilySamples> result = new LinkedList<>();
@@ -42,7 +43,12 @@ public final class ProxyStateCollector extends Collector {
return result;
}
Optional<StateContext> stateContext =
ProxyContext.getInstance().getStateContext();
- stateContext.ifPresent(optional ->
result.add(FACTORY.createGaugeMetric(PROXY_STATE_METRIC_KEY,
stateContext.get().getCurrentState().ordinal())));
+ if (!stateContext.isPresent()) {
+ return result;
+ }
+ PrometheusGaugeMetricFamilyCollector collector =
MetricsCollectorRegistry.get(PROXY_STATE_METRIC_KEY, "Prometheus");
+ collector.addMetric(Collections.emptyList(),
stateContext.get().getCurrentState().ordinal());
+ result.add((GaugeMetricFamily) collector.getRawMetricFamilyObject());
return result;
}
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
index 3c0f217701f..d94e335846b 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
@@ -22,7 +22,7 @@ import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfigur
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
/**
- * Prometheus counter wrapper.
+ * Prometheus counter collector.
*/
public final class PrometheusCounterCollector implements
CounterMetricsCollector {
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollector.java
index 254afc808e9..2ccf7690658 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollector.java
@@ -22,7 +22,7 @@ import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfigur
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricsCollector;
/**
- * Prometheus gauge wrapper.
+ * Prometheus gauge collector.
*/
public final class PrometheusGaugeCollector implements GaugeMetricsCollector {
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeMetricFamilyCollector.java
similarity index 60%
copy from
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
copy to
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeMetricFamilyCollector.java
index 3c0f217701f..6f0de294673 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeMetricFamilyCollector.java
@@ -17,28 +17,30 @@
package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
-import io.prometheus.client.Counter;
+import io.prometheus.client.GaugeMetricFamily;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+
+import java.util.List;
/**
- * Prometheus counter wrapper.
+ * Prometheus gauge metric family collector.
*/
-public final class PrometheusCounterCollector implements
CounterMetricsCollector {
+public final class PrometheusGaugeMetricFamilyCollector implements
GaugeMetricFamilyMetricsCollector {
- private final Counter counter;
+ private final GaugeMetricFamily gaugeMetricFamily;
- public PrometheusCounterCollector(final MetricConfiguration config) {
- counter =
Counter.build().name(config.getId()).help(config.getHelp()).labelNames(config.getLabels().toArray(new
String[0])).register();
+ public PrometheusGaugeMetricFamilyCollector(final MetricConfiguration
config) {
+ gaugeMetricFamily = new GaugeMetricFamily(config.getId(),
config.getHelp(), config.getLabels());
}
@Override
- public void inc() {
- counter.inc(1d);
+ public void addMetric(final List<String> labelValues, final double value) {
+ gaugeMetricFamily.addMetric(labelValues, value);
}
@Override
- public void inc(final String... labels) {
- counter.labels(labels).inc(1d);
+ public Object getRawMetricFamilyObject() {
+ return gaugeMetricFamily;
}
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollector.java
index f17e88daef1..ab76607b4a2 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollector.java
@@ -25,7 +25,7 @@ import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.Histog
import java.util.Map;
/**
- * Prometheus histogram wrapper.
+ * Prometheus histogram collector.
*/
public final class PrometheusHistogramCollector implements
HistogramMetricsCollector {
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
index f142ffee90e..3ae1b0bed26 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
@@ -22,7 +22,7 @@ import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfigur
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.SummaryMetricsCollector;
/**
- * Prometheus summary wrapper.
+ * Prometheus summary collector.
*/
public final class PrometheusSummaryCollector implements
SummaryMetricsCollector {
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
index db28dab9d9b..e8fdc771d86 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
+++
b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
@@ -48,7 +48,7 @@ metrics:
labels:
- name
- id: proxy_state
- type: GAUGE
+ type: GAUGE_METRIC_FAMILY
help: State of ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK
- id: proxy_current_connections
type: GAUGE
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/resources/META-INF/conf/prometheus-metrics.yaml
b/agent/plugins/metrics/type/prometheus/src/test/resources/META-INF/conf/prometheus-metrics.yaml
index 8b48465348f..1750a9a8fc2 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/resources/META-INF/conf/prometheus-metrics.yaml
+++
b/agent/plugins/metrics/type/prometheus/src/test/resources/META-INF/conf/prometheus-metrics.yaml
@@ -50,8 +50,6 @@ metrics:
- id: proxy_state
type: GAUGE_METRIC_FAMILY
help: State of ShardingSphere-Proxy
- labels:
- - name
- id: build_info
type: GAUGE_METRIC_FAMILY
help: build information