diff --git a/hmily-bom/pom.xml b/hmily-bom/pom.xml
index 570464f8..5d0ed104 100644
--- a/hmily-bom/pom.xml
+++ b/hmily-bom/pom.xml
@@ -89,7 +89,8 @@
1.0.0
3.4.0
3.2.0
- 0.6.0
+ 0.10.0
+ 0.15.0
3.6.0
0.4
1.8.9
@@ -185,6 +186,13 @@
${prometheus-java-client.version}
+
+
+ io.prometheus.jmx
+ collector
+ ${prometheus-jmx.version}
+
+
com.google.code.gson
gson
diff --git a/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/entity/HmilyMetricsConfig.java b/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/entity/HmilyMetricsConfig.java
index 854cc6ae..ca8e2674 100644
--- a/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/entity/HmilyMetricsConfig.java
+++ b/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/entity/HmilyMetricsConfig.java
@@ -17,16 +17,13 @@
package org.dromara.hmily.config.api.entity;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.regex.Pattern;
-import javax.management.ObjectName;
import lombok.Data;
import org.dromara.hmily.config.api.AbstractConfig;
import org.dromara.hmily.config.api.constant.PrefixConstants;
import org.dromara.hmily.spi.HmilySPI;
+import java.util.Properties;
+
/**
* Metrics config.
*
@@ -42,10 +39,6 @@ public final class HmilyMetricsConfig extends AbstractConfig {
private Integer port = 9091;
- private boolean async = true;
-
- private Integer threadCount = Runtime.getRuntime().availableProcessors() << 1;
-
private String jmxConfig;
private Properties props;
@@ -54,134 +47,5 @@ public final class HmilyMetricsConfig extends AbstractConfig {
public String prefix() {
return PrefixConstants.METRICS_PREFIX;
}
-
- @Data
- public static class HmilyJmxConfig {
-
- /**
- * The Start delay seconds.
- */
- private Integer startDelaySeconds = 0;
-
- /**
- * The Jmx url.
- */
- private String jmxUrl = "";
-
- /**
- * The Username.
- */
- private String username = "";
-
- /**
- * The Password.
- */
- private String password = "";
-
- /**
- * The Ssl.
- */
- private boolean ssl;
-
- /**
- * The Lowercase output name.
- */
- private boolean lowercaseOutputName;
-
- /**
- * The Lowercase output label names.
- */
- private boolean lowercaseOutputLabelNames;
-
- /**
- * The Whitelist object names.
- */
- private List whitelistObjectNames = new ArrayList<>();
-
- /**
- * The Blacklist object names.
- */
- private List blacklistObjectNames = new ArrayList<>();
-
- /**
- * The Rules.
- */
- private List rules = new ArrayList<>();
-
- /**
- * The type Rule.
- */
- @Data
- public static class Rule {
-
- private Pattern pattern;
-
- /**
- * The Name.
- */
- private String name;
-
- /**
- * The Value.
- */
- private String value;
-
- /**
- * The Value factor.
- */
- private Double valueFactor = 1.0;
-
- /**
- * The Help.
- */
- private String help;
-
- /**
- * The Attr name snake case.
- */
- private boolean attrNameSnakeCase;
-
- /**
- * The Type.
- */
- private Type type = Type.UNTYPED;
-
- /**
- * The Label names.
- */
- private List labelNames = new ArrayList<>();
-
- /**
- * The Label values.
- */
- private List labelValues = new ArrayList<>();
- }
-
- /**
- * The enum Type.
- */
- public enum Type {
- /**
- * Counter type.
- */
- COUNTER,
- /**
- * Gauge type.
- */
- GAUGE,
- /**
- * Summary type.
- */
- SUMMARY,
- /**
- * Histogram type.
- */
- HISTOGRAM,
- /**
- * Untyped type.
- */
- UNTYPED,
- }
- }
}
diff --git a/hmily-core/src/main/java/org/dromara/hmily/core/bootstrap/HmilyBootstrap.java b/hmily-core/src/main/java/org/dromara/hmily/core/bootstrap/HmilyBootstrap.java
index 48501f1d..e195f04e 100644
--- a/hmily-core/src/main/java/org/dromara/hmily/core/bootstrap/HmilyBootstrap.java
+++ b/hmily-core/src/main/java/org/dromara/hmily/core/bootstrap/HmilyBootstrap.java
@@ -17,7 +17,6 @@
package org.dromara.hmily.core.bootstrap;
-import java.util.Objects;
import org.dromara.hmily.common.exception.HmilyRuntimeException;
import org.dromara.hmily.common.hook.HmilyShutdownHook;
import org.dromara.hmily.common.utils.StringUtils;
@@ -33,13 +32,15 @@ import org.dromara.hmily.core.provide.ObjectProvide;
import org.dromara.hmily.core.provide.ReflectObject;
import org.dromara.hmily.core.repository.HmilyRepositoryFacade;
import org.dromara.hmily.core.schedule.HmilyTransactionSelfRecoveryScheduled;
-import org.dromara.hmily.metrics.spi.MetricsInit;
+import org.dromara.hmily.metrics.facade.MetricsTrackerFacade;
import org.dromara.hmily.repository.spi.HmilyRepository;
import org.dromara.hmily.serializer.spi.HmilySerializer;
import org.dromara.hmily.spi.ExtensionLoaderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Objects;
+
/**
* The type Hmily bootstrap.
*
@@ -92,9 +93,9 @@ public final class HmilyBootstrap {
private void initMetrics() {
HmilyMetricsConfig metricsConfig = ConfigEnv.getInstance().getConfig(HmilyMetricsConfig.class);
if (Objects.nonNull(metricsConfig) && StringUtils.isNoneBlank(metricsConfig.getMetricsName())) {
- MetricsInit metricsInit = ExtensionLoaderFactory.load(MetricsInit.class);
- metricsInit.init(metricsConfig);
- registerAutoCloseable(metricsInit);
+ MetricsTrackerFacade facade = new MetricsTrackerFacade();
+ facade.start(metricsConfig);
+ registerAutoCloseable(facade);
}
}
diff --git a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsInitFacade.java b/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsInitFacade.java
deleted file mode 100644
index 4213ed9a..00000000
--- a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsInitFacade.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.dromara.hmily.metrics.facade;
-
-import com.google.common.base.Preconditions;
-import java.util.Optional;
-import org.dromara.hmily.config.api.entity.HmilyMetricsConfig;
-import org.dromara.hmily.metrics.facade.handler.MetricsTrackerHandler;
-import org.dromara.hmily.metrics.spi.MetricsInit;
-import org.dromara.hmily.metrics.spi.MetricsTrackerManager;
-import org.dromara.hmily.spi.ExtensionLoaderFactory;
-import org.dromara.hmily.spi.HmilySPI;
-
-/**
- * The type Metrics init facade.
- *
- * @author xiaoyu
- */
-@HmilySPI(value = "metricsInit")
-public class MetricsInitFacade implements MetricsInit {
-
- private static volatile boolean enabled;
-
- private static MetricsTrackerManager metricsTrackerManager;
-
- /**
- * Gets enabled.
- *
- * @return the enabled
- */
- public static boolean getEnabled() {
- return enabled;
- }
-
- @Override
- public void init(final HmilyMetricsConfig metricsConfig) {
- if (!enabled) {
- doInit(metricsConfig);
- }
- }
-
- @Override
- public void close() {
- if (!enabled) {
- return;
- }
- if (null != metricsTrackerManager) {
- metricsTrackerManager.stop();
- }
- MetricsTrackerHandler.getInstance().close();
- enabled = false;
- }
-
- private static void doInit(final HmilyMetricsConfig metricsConfig) {
- Preconditions.checkNotNull(metricsConfig, "metrics configuration can not be null.");
- metricsTrackerManager = ExtensionLoaderFactory.load(MetricsTrackerManager.class, metricsConfig.getMetricsName());
- Preconditions.checkNotNull(metricsTrackerManager, "Can not find metrics tracker manager with metrics name in metrics configuration.");
- metricsTrackerManager.start(metricsConfig);
- Integer threadCount = Optional.ofNullable(metricsConfig.getThreadCount()).orElse(Runtime.getRuntime().availableProcessors());
- MetricsTrackerHandler.getInstance().init(metricsConfig.isAsync(), threadCount, metricsTrackerManager);
- enabled = true;
- }
-}
diff --git a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsTrackerFacade.java b/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsTrackerFacade.java
new file mode 100644
index 00000000..6c8f0042
--- /dev/null
+++ b/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsTrackerFacade.java
@@ -0,0 +1,63 @@
+/*
+ * 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.dromara.hmily.metrics.facade;
+
+import com.google.common.base.Preconditions;
+import lombok.extern.slf4j.Slf4j;
+import org.dromara.hmily.config.api.entity.HmilyMetricsConfig;
+import org.dromara.hmily.metrics.spi.MetricsBootService;
+import org.dromara.hmily.metrics.spi.MetricsRegister;
+import org.dromara.hmily.spi.ExtensionLoaderFactory;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Metrics tracker facade.
+ */
+@Slf4j
+public final class MetricsTrackerFacade implements AutoCloseable {
+
+ private MetricsBootService metricsBootService;
+
+ private final AtomicBoolean isStarted = new AtomicBoolean(false);
+
+ /**
+ * Init for metrics tracker manager.
+ *
+ * @param metricsConfig metrics config
+ */
+ public void start(final HmilyMetricsConfig metricsConfig) {
+ if (this.isStarted.compareAndSet(false, true)) {
+ metricsBootService = ExtensionLoaderFactory.load(MetricsBootService.class, metricsConfig.getMetricsName());
+ Preconditions.checkNotNull(metricsBootService,
+ "Can not find metrics tracker manager with metrics name : %s in metrics configuration.", metricsConfig.getMetricsName());
+ metricsBootService.start(metricsConfig, ExtensionLoaderFactory.load(MetricsRegister.class, metricsConfig.getMetricsName()));
+ } else {
+ log.info("metrics tracker has started !");
+ }
+ }
+
+ @Override
+ public void close() {
+ this.isStarted.compareAndSet(true, false);
+ if (null != metricsBootService) {
+ metricsBootService.stop();
+ }
+ }
+}
+
diff --git a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsTrackerHandlerFacade.java b/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsTrackerHandlerFacade.java
deleted file mode 100644
index 4583232b..00000000
--- a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/MetricsTrackerHandlerFacade.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.dromara.hmily.metrics.facade;
-
-import java.util.Optional;
-import java.util.function.Supplier;
-import lombok.extern.slf4j.Slf4j;
-import org.dromara.hmily.metrics.api.HistogramMetricsTrackerDelegate;
-import org.dromara.hmily.metrics.api.SummaryMetricsTrackerDelegate;
-import org.dromara.hmily.metrics.facade.handler.MetricsTrackerHandler;
-import org.dromara.hmily.metrics.spi.MetricsHandlerFacade;
-import org.dromara.hmily.spi.HmilySPI;
-
-/**
- * Metrics tracker facade.
- *
- * @author xiaoyu
- */
-@Slf4j
-@HmilySPI(value = "metricsTrackerHandlerFacade")
-public final class MetricsTrackerHandlerFacade implements MetricsHandlerFacade {
-
- @Override
- public void counterIncrement(final String metricsLabel, final String... labelValues) {
- if (MetricsInitFacade.getEnabled()) {
- MetricsTrackerHandler.getInstance().counterInc(metricsLabel, labelValues);
- }
- }
-
- @Override
- public void gaugeIncrement(final String metricsLabel, final String... labelValues) {
- if (MetricsInitFacade.getEnabled()) {
- MetricsTrackerHandler.getInstance().gaugeInc(metricsLabel, labelValues);
- }
- }
-
- @Override
- public void gaugeDecrement(final String metricsLabel, final String... labelValues) {
- if (MetricsInitFacade.getEnabled()) {
- MetricsTrackerHandler.getInstance().gaugeDec(metricsLabel, labelValues);
- }
- }
-
- @Override
- public Supplier histogramStartTimer(final String metricsLabel, final String... labelValues) {
- if (!MetricsInitFacade.getEnabled()) {
- return () -> false;
- }
- Optional histogramMetricsTrackerDelegate = MetricsTrackerHandler.getInstance().histogramStartTimer(metricsLabel, labelValues);
- return () -> {
- histogramMetricsTrackerDelegate.ifPresent(this::histogramObserveDuration);
- return true;
- };
- }
-
- private void histogramObserveDuration(final HistogramMetricsTrackerDelegate delegate) {
- if (MetricsInitFacade.getEnabled()) {
- MetricsTrackerHandler.getInstance().histogramObserveDuration(delegate);
- }
- }
-
- @Override
- public Supplier summaryStartTimer(final String metricsLabel, final String... labelValues) {
- if (!MetricsInitFacade.getEnabled()) {
- return () -> false;
- }
- Optional optionalSummaryMetricsTrackerDelegate = MetricsTrackerHandler.getInstance().summaryStartTimer(metricsLabel, labelValues);
- return () -> {
- optionalSummaryMetricsTrackerDelegate.ifPresent(this::summaryObserveDuration);
- return true;
- };
- }
-
- private void summaryObserveDuration(final SummaryMetricsTrackerDelegate delegate) {
- if (MetricsInitFacade.getEnabled()) {
- MetricsTrackerHandler.getInstance().summaryObserveDuration(delegate);
- }
- }
-}
-
diff --git a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/executor/MetricsThreadPoolExecutor.java b/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/executor/MetricsThreadPoolExecutor.java
deleted file mode 100644
index 990f7db0..00000000
--- a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/executor/MetricsThreadPoolExecutor.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.dromara.hmily.metrics.facade.executor;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.RejectedExecutionHandler;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
-import org.dromara.hmily.common.concurrent.HmilyThreadFactory;
-
-/**
- * Metrics thread pool executor.
- */
-@Slf4j
-public final class MetricsThreadPoolExecutor extends ThreadPoolExecutor {
-
- @Getter
- private final String name;
-
- /**
- * Instantiates a new Metrics thread pool executor.
- *
- * @param threadCount core and max thread count
- * @param queueSize queue size
- */
- public MetricsThreadPoolExecutor(final int threadCount, final int queueSize) {
- super(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(queueSize),
- HmilyThreadFactory.create("metrics", true), buildRejectedExecutionHandler(queueSize));
- this.name = "metrics";
- }
-
- private static RejectedExecutionHandler buildRejectedExecutionHandler(final int size) {
- return (r, executor) -> {
- BlockingQueue queue = executor.getQueue();
- while (queue.size() >= size) {
- if (executor.isShutdown()) {
- throw new RejectedExecutionException("metrics thread pool executor closed");
- }
- ((MetricsThreadPoolExecutor) executor).onRejected();
- }
- if (!executor.isShutdown()) {
- executor.execute(r);
- }
- };
- }
-
- private void onRejected() {
- log.info("...thread:{}, Saturation occurs, actuator:{}", Thread.currentThread().getName(), name);
- }
-}
-
diff --git a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/handler/MetricsTrackerHandler.java b/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/handler/MetricsTrackerHandler.java
deleted file mode 100644
index 227d50bb..00000000
--- a/hmily-metrics/hmily-metrics-facade/src/main/java/org/dromara/hmily/metrics/facade/handler/MetricsTrackerHandler.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * 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.dromara.hmily.metrics.facade.handler;
-
-import java.util.Arrays;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
-import org.dromara.hmily.metrics.api.CounterMetricsTracker;
-import org.dromara.hmily.metrics.api.GaugeMetricsTracker;
-import org.dromara.hmily.metrics.api.HistogramMetricsTracker;
-import org.dromara.hmily.metrics.api.HistogramMetricsTrackerDelegate;
-import org.dromara.hmily.metrics.api.MetricsTracker;
-import org.dromara.hmily.metrics.api.NoneHistogramMetricsTrackerDelegate;
-import org.dromara.hmily.metrics.api.NoneSummaryMetricsTrackerDelegate;
-import org.dromara.hmily.metrics.api.SummaryMetricsTracker;
-import org.dromara.hmily.metrics.api.SummaryMetricsTrackerDelegate;
-import org.dromara.hmily.metrics.enums.MetricsTypeEnum;
-import org.dromara.hmily.metrics.facade.executor.MetricsThreadPoolExecutor;
-import org.dromara.hmily.metrics.spi.MetricsTrackerManager;
-
-/**
- * Metrics tracker handler.
- */
-@Slf4j
-public final class MetricsTrackerHandler {
-
- private static final int FUTURE_GET_TIME_OUT_MILLISECONDS = 500;
-
- private static final int QUEUE_SIZE = 5000;
-
- @Getter
- private MetricsTrackerManager metricsTrackerManager;
-
- @Getter
- private ExecutorService executorService;
-
- private volatile boolean async;
-
- /**
- * Get metrics tracker handler of lazy load singleton.
- *
- * @return Metrics tracker handler
- */
- public static MetricsTrackerHandler getInstance() {
- return MetricsTrackerHandlerHolder.INSTANCE;
- }
-
- /**
- * Init for metrics tracker handler.
- *
- * @param async async
- * @param threadCount thread count
- * @param metricsTrackerManager metrics tracker manager
- */
- public void init(final boolean async, final int threadCount, final MetricsTrackerManager metricsTrackerManager) {
- this.async = async;
- this.metricsTrackerManager = metricsTrackerManager;
- if (async) {
- executorService = new MetricsThreadPoolExecutor(threadCount, QUEUE_SIZE);
- }
- }
-
- /**
- * Increment of counter metrics tracker.
- *
- * @param metricsLabel metrics label
- * @param labelValues label values
- */
- public void counterInc(final String metricsLabel, final String... labelValues) {
- if (async) {
- executorService.execute(() -> handlerCounter(metricsLabel, labelValues));
- } else {
- handlerCounter(metricsLabel, labelValues);
- }
- }
-
- /**
- * Increment of gauge metrics tracker.
- *
- * @param metricsLabel metrics label
- * @param labelValues label values
- */
- public void gaugeInc(final String metricsLabel, final String... labelValues) {
- if (async) {
- executorService.execute(() -> handlerGaugeInc(metricsLabel, labelValues));
- } else {
- handlerGaugeInc(metricsLabel, labelValues);
- }
- }
-
- /**
- * Decrement of gauge metrics tracker.
- *
- * @param metricsLabel metrics label
- * @param labelValues label values
- */
- public void gaugeDec(final String metricsLabel, final String... labelValues) {
- if (async) {
- executorService.execute(() -> handlerGaugeDec(metricsLabel, labelValues));
- } else {
- handlerGaugeDec(metricsLabel, labelValues);
- }
- }
-
- /**
- * Start timer of histogram metrics tracker.
- *
- * @param metricsLabel metrics label
- * @param labelValues label values
- * @return histogram metrics tracker delegate
- */
- public Optional histogramStartTimer(final String metricsLabel, final String... labelValues) {
- if (async) {
- try {
- return executorService.submit(() -> handlerHistogramStartTimer(metricsLabel, labelValues)).get(FUTURE_GET_TIME_OUT_MILLISECONDS, TimeUnit.MILLISECONDS);
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- throw new IllegalStateException(String.format("Error while fetching histogram metric with metricsLabel= %s and labelValues=%s", metricsLabel, Arrays.toString(labelValues)), e);
- }
- } else {
- return handlerHistogramStartTimer(metricsLabel, labelValues);
- }
- }
-
- /**
- * Observe amount of time since start time with histogram metrics tracker.
- *
- * @param delegate histogram metrics tracker delegate
- */
- public void histogramObserveDuration(final HistogramMetricsTrackerDelegate delegate) {
- if (async) {
- executorService.execute(delegate::observeDuration);
- } else {
- delegate.observeDuration();
- }
- }
-
- /**
- * Start timer of summary metrics tracker.
- *
- * @param metricsLabel metrics label
- * @param labelValues label values
- * @return summary metrics tracker delegate
- */
- public Optional summaryStartTimer(final String metricsLabel, final String... labelValues) {
- if (async) {
- try {
- return executorService.submit(() -> handlerSummaryStartTimer(metricsLabel, labelValues)).get(FUTURE_GET_TIME_OUT_MILLISECONDS, TimeUnit.SECONDS);
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- throw new IllegalStateException(String.format("Error while fetching summary metric with metricsLabel= %s and labelValues=%s", metricsLabel, Arrays.toString(labelValues)), e);
- }
- } else {
- return handlerSummaryStartTimer(metricsLabel, labelValues);
- }
- }
-
- /**
- * Observe amount of time since start time with summary metrics tracker.
- *
- * @param delegate summary metrics tracker delegate
- */
- public void summaryObserveDuration(final SummaryMetricsTrackerDelegate delegate) {
- if (async) {
- executorService.execute(delegate::observeDuration);
- } else {
- delegate.observeDuration();
- }
- }
-
- /**
- * Executor service close.
- */
- public void close() {
- async = false;
- if (null != executorService && !executorService.isShutdown()) {
- executorService.shutdown();
- }
- }
-
- private void handlerCounter(final String metricsLabel, final String... labelValues) {
- metricsTrackerManager.getMetricsTrackerFactory().create(MetricsTypeEnum.COUNTER.name(), metricsLabel)
- .ifPresent(metricsTracker -> ((CounterMetricsTracker) metricsTracker).inc(1.0, labelValues));
- }
-
- private void handlerGaugeInc(final String metricsLabel, final String... labelValues) {
- metricsTrackerManager.getMetricsTrackerFactory().create(MetricsTypeEnum.GAUGE.name(), metricsLabel)
- .ifPresent(metricsTracker -> ((GaugeMetricsTracker) metricsTracker).inc(1.0, labelValues));
- }
-
- /**
- * Handler gauge dec.
- *
- * @param metricsLabel the metrics label
- * @param labelValues the label values
- */
- public void handlerGaugeDec(final String metricsLabel, final String... labelValues) {
- metricsTrackerManager.getMetricsTrackerFactory().create(MetricsTypeEnum.GAUGE.name(), metricsLabel)
- .ifPresent(metricsTracker -> ((GaugeMetricsTracker) metricsTracker).dec(1.0, labelValues));
- }
-
- private Optional handlerHistogramStartTimer(final String metricsLabel, final String... labelValues) {
- Optional metricsTracker = metricsTrackerManager.getMetricsTrackerFactory().create(MetricsTypeEnum.HISTOGRAM.name(), metricsLabel);
- return metricsTracker.map(tracker -> Optional.of(((HistogramMetricsTracker) tracker).startTimer(labelValues))).orElseGet(() -> Optional.of(new NoneHistogramMetricsTrackerDelegate()));
- }
-
- private Optional handlerSummaryStartTimer(final String metricsLabel, final String... labelValues) {
- Optional metricsTracker = metricsTrackerManager.getMetricsTrackerFactory().create(MetricsTypeEnum.SUMMARY.name(), metricsLabel);
- return metricsTracker.map(tracker -> Optional.of(((SummaryMetricsTracker) tracker).startTimer(labelValues))).orElseGet(() -> Optional.of(new NoneSummaryMetricsTrackerDelegate()));
- }
-
- /**
- * Metrics tracker handler holder.
- */
- private static class MetricsTrackerHandlerHolder {
-
- private static final MetricsTrackerHandler INSTANCE = new MetricsTrackerHandler();
- }
-}
-
diff --git a/hmily-metrics/hmily-metrics-facade/src/main/resources/META-INF/hmily/org.dromara.hmily.metrics.spi.MetricsHandlerFacade b/hmily-metrics/hmily-metrics-facade/src/main/resources/META-INF/hmily/org.dromara.hmily.metrics.spi.MetricsHandlerFacade
deleted file mode 100644
index 49a1ee85..00000000
--- a/hmily-metrics/hmily-metrics-facade/src/main/resources/META-INF/hmily/org.dromara.hmily.metrics.spi.MetricsHandlerFacade
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.
-#
-
-org.dromara.hmily.metrics.facade.MetricsTrackerHandlerFacade
diff --git a/hmily-metrics/hmily-metrics-facade/src/main/resources/META-INF/hmily/org.dromara.hmily.metrics.spi.MetricsInit b/hmily-metrics/hmily-metrics-facade/src/main/resources/META-INF/hmily/org.dromara.hmily.metrics.spi.MetricsInit
deleted file mode 100644
index fd940d13..00000000
--- a/hmily-metrics/hmily-metrics-facade/src/main/resources/META-INF/hmily/org.dromara.hmily.metrics.spi.MetricsInit
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.
-#
-
-org.dromara.hmily.metrics.facade.MetricsInitFacade
diff --git a/hmily-metrics/hmily-metrics-prometheus/pom.xml b/hmily-metrics/hmily-metrics-prometheus/pom.xml
index 222ec563..3d8b93ca 100644
--- a/hmily-metrics/hmily-metrics-prometheus/pom.xml
+++ b/hmily-metrics/hmily-metrics-prometheus/pom.xml
@@ -56,5 +56,9 @@
io.prometheus
simpleclient_hotspot
+
+ io.prometheus.jmx
+ collector
+
\ No newline at end of file
diff --git a/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/PrometheusMetricsTrackerFactory.java b/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/PrometheusMetricsTrackerFactory.java
deleted file mode 100644
index 737ad599..00000000
--- a/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/PrometheusMetricsTrackerFactory.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.dromara.hmily.metrics.prometheus;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Optional;
-import org.dromara.hmily.metrics.api.MetricsTracker;
-import org.dromara.hmily.metrics.api.MetricsTrackerFactory;
-import org.dromara.hmily.metrics.prometheus.impl.counter.TransactionStatusCounterMetricsTracker;
-import org.dromara.hmily.metrics.prometheus.impl.counter.TransactionTotalCounterMetricsTracker;
-import org.dromara.hmily.metrics.prometheus.impl.histogram.TransactionLatencyHistogramMetricsTracker;
-import org.dromara.hmily.metrics.prometheus.impl.summary.TransactionLatencySummaryMetricsTracker;
-
-/**
- * Prometheus metrics tracker factory.
- *
- * @author xiaoyu
- */
-public final class PrometheusMetricsTrackerFactory implements MetricsTrackerFactory {
-
- private static final Collection REGISTER = new ArrayList<>();
-
- static {
- REGISTER.add(new TransactionTotalCounterMetricsTracker());
- REGISTER.add(new TransactionStatusCounterMetricsTracker());
- REGISTER.add(new TransactionLatencyHistogramMetricsTracker());
- REGISTER.add(new TransactionLatencySummaryMetricsTracker());
- }
-
- @Override
- public Optional create(final String metricsType, final String metricsLabel) {
- return REGISTER.stream().filter(each -> each.metricsLabel().equals(metricsLabel) && each.metricsType().equals(metricsType)).findFirst();
- }
-}
-
diff --git a/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/impl/collector/BuildInfoCollector.java b/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/collector/BuildInfoCollector.java
similarity index 95%
rename from hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/impl/collector/BuildInfoCollector.java
rename to hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/collector/BuildInfoCollector.java
index 7d503458..9815e126 100644
--- a/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/impl/collector/BuildInfoCollector.java
+++ b/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/collector/BuildInfoCollector.java
@@ -15,19 +15,17 @@
* limitations under the License.
*/
-package org.dromara.hmily.metrics.prometheus.impl.collector;
+package org.dromara.hmily.metrics.prometheus.collector;
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
/**
* The type Build info collector.
- *
- * @author xiaoyu
*/
public class BuildInfoCollector extends Collector {
diff --git a/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/impl/collector/JmxCollector.java b/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/impl/collector/JmxCollector.java
deleted file mode 100644
index c4da6ca1..00000000
--- a/hmily-metrics/hmily-metrics-prometheus/src/main/java/org/dromara/hmily/metrics/prometheus/impl/collector/JmxCollector.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * 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.dromara.hmily.metrics.prometheus.impl.collector;
-
-import io.prometheus.client.Collector;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentSkipListMap;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import org.dromara.hmily.common.utils.GsonUtils;
-import org.dromara.hmily.config.api.entity.HmilyMetricsConfig;
-
-/**
- * The type Jmx collector.
- *
- * @author xiaoyu
- */
-public class JmxCollector extends Collector implements Collector.Describable {
-
- private static final Logger LOGGER = Logger.getLogger(JmxCollector.class.getName());
-
- private HmilyMetricsConfig.HmilyJmxConfig config;
-
- private long createTimeNanoSecs = System.nanoTime();
-
- private final JmxMBeanPropertyCache jmxMBeanPropertyCache = new JmxMBeanPropertyCache();
-
- /**
- * Instantiates a new Jmx collector.
- *
- * @param json the json
- * @throws MalformedObjectNameException the malformed object name exception
- */
- public JmxCollector(final String json) throws MalformedObjectNameException {
- config = loadConfig(GsonUtils.getInstance().toObjectMap(json));
- }
-
- private HmilyMetricsConfig.HmilyJmxConfig loadConfig(final Map paramMap) throws MalformedObjectNameException {
- HmilyMetricsConfig.HmilyJmxConfig cfg = new HmilyMetricsConfig.HmilyJmxConfig();
- if (paramMap == null || paramMap.size() == 0) {
- return cfg;
- }
- if (paramMap.containsKey("startDelaySeconds")) {
- try {
- cfg.setStartDelaySeconds((Integer) paramMap.get("startDelaySeconds"));
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("Invalid number provided for startDelaySeconds", e);
- }
- }
- if (paramMap.containsKey("hostPort")) {
- if (paramMap.containsKey("jmxUrl")) {
- throw new IllegalArgumentException("At most one of hostPort and jmxUrl must be provided");
- }
- cfg.setJmxUrl("service:jmx:rmi:///jndi/rmi://" + paramMap.get("hostPort") + "/jmxrmi");
- } else if (paramMap.containsKey("jmxUrl")) {
- cfg.setJmxUrl((String) paramMap.get("jmxUrl"));
- }
-
- if (paramMap.containsKey("username")) {
- cfg.setUsername((String) paramMap.get("username"));
- }
-
- if (paramMap.containsKey("password")) {
- cfg.setPassword((String) paramMap.get("password"));
- }
-
- if (paramMap.containsKey("ssl")) {
- cfg.setSsl((Boolean) paramMap.get("ssl"));
- }
-
- if (paramMap.containsKey("lowercaseOutputName")) {
- cfg.setLowercaseOutputName((Boolean) paramMap.get("lowercaseOutputName"));
- }
-
- if (paramMap.containsKey("lowercaseOutputLabelNames")) {
- cfg.setLowercaseOutputLabelNames((Boolean) paramMap.get("lowercaseOutputLabelNames"));
- }
-
- if (paramMap.containsKey("whitelistObjectNames")) {
- List names = GsonUtils.getInstance().fromList(paramMap.get("whitelistObjectNames").toString(), String.class);
- for (String name : names) {
- cfg.getWhitelistObjectNames().add(new ObjectName(name));
- }
- }
-
- if (paramMap.containsKey("blacklistObjectNames")) {
- List names = GsonUtils.getInstance().fromList(paramMap.get("blacklistObjectNames").toString(), String.class);
- for (String name : names) {
- cfg.getBlacklistObjectNames().add(new ObjectName(name));
- }
- }
-
- if (paramMap.containsKey("rules")) {
- List