tkalkirill commented on code in PR #3720:
URL: https://github.com/apache/ignite-3/pull/3720#discussion_r1593913513


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/metrics/MetaStorageMetricSource.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.ignite.internal.metastorage.metrics;
+
+import java.util.HashMap;
+import org.apache.ignite.internal.metrics.LongGauge;
+import org.apache.ignite.internal.metrics.Metric;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.MetricSource;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Metric source which provides MetaStorage-related metrics.
+ */
+public class MetaStorageMetricSource implements MetricSource {
+    private static final String SOURCE_NAME = "metastorage";
+
+    private final MetaStorageMetrics metaStorageMetrics;
+
+    private boolean enabled;
+
+    /**
+     * Constructor.
+     */
+    public MetaStorageMetricSource(MetaStorageMetrics metaStorageMetrics) {
+        this.metaStorageMetrics = metaStorageMetrics;
+    }
+
+    @Override
+    public String name() {
+        return SOURCE_NAME;
+    }
+
+    @Override
+    public synchronized @Nullable MetricSet enable() {

Review Comment:
   Maybe use a mutex?



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/metrics/MetaStorageMetricSource.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.ignite.internal.metastorage.metrics;
+
+import java.util.HashMap;
+import org.apache.ignite.internal.metrics.LongGauge;
+import org.apache.ignite.internal.metrics.Metric;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.MetricSource;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Metric source which provides MetaStorage-related metrics.
+ */
+public class MetaStorageMetricSource implements MetricSource {
+    private static final String SOURCE_NAME = "metastorage";
+
+    private final MetaStorageMetrics metaStorageMetrics;
+
+    private boolean enabled;
+
+    /**
+     * Constructor.
+     */
+    public MetaStorageMetricSource(MetaStorageMetrics metaStorageMetrics) {
+        this.metaStorageMetrics = metaStorageMetrics;
+    }
+
+    @Override
+    public String name() {
+        return SOURCE_NAME;
+    }
+
+    @Override
+    public synchronized @Nullable MetricSet enable() {
+        var metrics = new HashMap<String, Metric>();
+
+        metrics.put(
+                "SafeTimeLag",
+                new LongGauge(
+                        "SafeTimeLag",
+                        "Number of milliseconds the local MetaStorage SafeTime 
lags behind the local logical clock.",
+                        metaStorageMetrics::safeTimeLag
+                )
+        );
+
+        enabled = true;
+
+        return new MetricSet(SOURCE_NAME, metrics);
+    }
+
+    @Override
+    public synchronized void disable() {

Review Comment:
   It’s interesting that in `#enable` we register metrics and mark them as 
enabled, but here we only mark them as disabled, maybe we need to unregister 
the metrics?



##########
modules/metrics/src/main/java/org/apache/ignite/internal/metrics/sources/OsMetricSource.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.ignite.internal.metrics.sources;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+import java.util.HashMap;
+import org.apache.ignite.internal.metrics.DoubleGauge;
+import org.apache.ignite.internal.metrics.Metric;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.MetricSource;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Metric source which provides OS metrics like Load Average.
+ */
+public class OsMetricSource implements MetricSource {
+
+    private static final String SOURCE_NAME = "os";
+
+    private final OperatingSystemMXBean operatingSystemMxBean;
+
+    private boolean enabled;

Review Comment:
   Same about guarded by mutex.



##########
modules/metrics/src/test/java/org/apache/ignite/internal/metrics/sources/JvmMetricSourceTest.java:
##########
@@ -136,4 +157,49 @@ public ObjectName getObjectName() {
             throw new UnsupportedOperationException("Not supported in test 
implementation");
         }
     }
+
+    private static class GarbageCollectorBean implements 
GarbageCollectorMXBean {

Review Comment:
   Maybe separate class?



##########
modules/metrics/src/main/java/org/apache/ignite/internal/metrics/sources/OsMetricSource.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.ignite.internal.metrics.sources;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+import java.util.HashMap;
+import org.apache.ignite.internal.metrics.DoubleGauge;
+import org.apache.ignite.internal.metrics.Metric;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.MetricSource;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Metric source which provides OS metrics like Load Average.
+ */
+public class OsMetricSource implements MetricSource {
+

Review Comment:
   ```suggestion
   ```



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/metrics/MetaStorageMetricSource.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.ignite.internal.metastorage.metrics;
+
+import java.util.HashMap;
+import org.apache.ignite.internal.metrics.LongGauge;
+import org.apache.ignite.internal.metrics.Metric;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.MetricSource;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Metric source which provides MetaStorage-related metrics.
+ */
+public class MetaStorageMetricSource implements MetricSource {
+    private static final String SOURCE_NAME = "metastorage";
+
+    private final MetaStorageMetrics metaStorageMetrics;
+
+    private boolean enabled;

Review Comment:
   Can you document what is guarded by a mutex?



##########
modules/metrics/src/main/java/org/apache/ignite/internal/metrics/sources/JvmMetricSource.java:
##########
@@ -117,11 +127,36 @@ public String name() {
                         () -> nonHeapMemoryUsage.get().getMax()
                 ));
 
+        for (GarbageCollectorMXBean gcMxBean : gcMxBeans) {
+            metrics.put(
+                    "gc." + nameForMetricName(gcMxBean) + ".CollectionCount",
+                    new LongGauge(
+                            "gc." + nameForMetricName(gcMxBean) + 
".CollectionCount",
+                            "Total number of collections that have occurred. 
-1 if the collection count is undefined for this collector.",
+                            gcMxBean::getCollectionCount
+                    )
+            );
+
+            metrics.put(
+                    "gc." + nameForMetricName(gcMxBean) + ".CollectionTime",

Review Comment:
   Maybe: `"gc." + nameForMetricName(gcMxBean)` to method?



##########
modules/metrics/src/test/java/org/apache/ignite/internal/metrics/sources/OsMetricSourceTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.ignite.internal.metrics.sources;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.lang.management.OperatingSystemMXBean;
+import javax.management.ObjectName;
+import org.apache.ignite.internal.metrics.DoubleMetric;
+import org.junit.jupiter.api.Test;
+
+class OsMetricSourceTest {
+    @Test
+    void testOsMetrics() {
+        var osBean = new OperatingSystemBean(1.23);
+        var metricSource = new OsMetricSource(osBean);
+
+        var metricSet = metricSource.enable();
+
+        assertEquals(1.23, metricSet.<DoubleMetric>get("LoadAverage").value());
+
+        osBean.loadAverage = 2.34;
+
+        assertEquals(2.34, metricSet.<DoubleMetric>get("LoadAverage").value());
+    }
+
+    private static class OperatingSystemBean implements OperatingSystemMXBean {

Review Comment:
   Maybe separate class?



##########
modules/metrics/src/main/java/org/apache/ignite/internal/metrics/sources/OsMetricSource.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.ignite.internal.metrics.sources;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+import java.util.HashMap;
+import org.apache.ignite.internal.metrics.DoubleGauge;
+import org.apache.ignite.internal.metrics.Metric;
+import org.apache.ignite.internal.metrics.MetricSet;
+import org.apache.ignite.internal.metrics.MetricSource;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Metric source which provides OS metrics like Load Average.
+ */
+public class OsMetricSource implements MetricSource {
+
+    private static final String SOURCE_NAME = "os";
+
+    private final OperatingSystemMXBean operatingSystemMxBean;
+
+    private boolean enabled;
+
+    /**
+     * Constructor.
+     *
+     * @param operatingSystemMxBean MXBean implementation to receive OS info.
+     */
+    OsMetricSource(OperatingSystemMXBean operatingSystemMxBean) {
+        this.operatingSystemMxBean = operatingSystemMxBean;
+    }
+
+    /**
+     * Constructs new metric source with standard MemoryMXBean as metric 
provider.
+     */
+    public OsMetricSource() {
+        operatingSystemMxBean = ManagementFactory.getOperatingSystemMXBean();
+    }
+
+    @Override
+    public String name() {
+        return SOURCE_NAME;
+    }
+
+    @Override
+    public synchronized @Nullable MetricSet enable() {

Review Comment:
   Same about mutex.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to