diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/StoreNodeApplication.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/StoreNodeApplication.java index c793ed96f2..275de58368 100644 --- a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/StoreNodeApplication.java +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/StoreNodeApplication.java @@ -25,10 +25,13 @@ import com.alipay.remoting.util.StringUtils; +import org.springframework.scheduling.annotation.EnableScheduling; + /** * */ @SpringBootApplication +@EnableScheduling public class StoreNodeApplication { //TODO Is this OK? diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java index d5ca11b3f5..38bcf4d9f6 100644 --- a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java @@ -65,10 +65,18 @@ public class JRaftMetrics { private JRaftMetrics() { } - public synchronized static void init(MeterRegistry meterRegistry) { + public synchronized static void init(MeterRegistry meterRegistry, boolean isInitialCall) { if (registry == null) { registry = meterRegistry; registerMeters(); + if (isInitialCall) { + log.debug("JRaftMetrics initialized during application startup"); + } else { + log.debug("JRaftMetrics initialized during scheduled refresh"); + } + } else if (!isInitialCall) { + registerNodeMetrics(); + log.debug("JRaftMetrics refreshed during scheduled refresh"); } } @@ -108,9 +116,7 @@ private static void registerNodeMetrics() { synchronized (groupSet) { map.forEach((group, metrics) -> { - if (!groupSet.add(group)) { - return; - } + groupSet.add(group); metrics.getMetricRegistry().getGauges() .forEach((k, v) -> registerGauge(group, k, v)); diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsConfig.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsConfig.java index 7062ee7eb8..c739fad1ee 100644 --- a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsConfig.java +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsConfig.java @@ -39,7 +39,7 @@ public MeterRegistryCustomizer registerMeters() { return (registry) -> { StoreMetrics.init(registry); RocksDBMetrics.init(registry); - JRaftMetrics.init(registry); + JRaftMetrics.init(registry, true); ProcfsMetrics.init(registry); GRpcExMetrics.init(registry); }; diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java new file mode 100644 index 0000000000..42b7113255 --- /dev/null +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/MetricsRefresher.java @@ -0,0 +1,41 @@ +/* + * 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.hugegraph.store.node.metrics; + +import io.micrometer.core.instrument.MeterRegistry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +public class MetricsRefresher { + private static final Logger log = LoggerFactory.getLogger(MetricsRefresher.class); + + private final MeterRegistry registry; + + public MetricsRefresher(MeterRegistry registry) { + this.registry = registry; + } + + @Scheduled(fixedRate = 30000) + public void refreshMetrics() { + log.info("Refreshing metrics"); + JRaftMetrics.init(registry, false); + } +}