From 15b028b0bcfe454ff901527b03ca39fec26fac4d Mon Sep 17 00:00:00 2001 From: Ilia Naryzhny Date: Thu, 26 Mar 2020 19:54:40 -0700 Subject: [PATCH] Add frozen flag and counters per class and total for issue #395 --- .../org/orienteer/metrics/OMetricsModule.java | 2 +- .../orienteer/metrics/OMetricsOrientDB.java | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/orienteer-metrics/src/main/java/org/orienteer/metrics/OMetricsModule.java b/orienteer-metrics/src/main/java/org/orienteer/metrics/OMetricsModule.java index 884bc2176..0d94ca07f 100644 --- a/orienteer-metrics/src/main/java/org/orienteer/metrics/OMetricsModule.java +++ b/orienteer-metrics/src/main/java/org/orienteer/metrics/OMetricsModule.java @@ -34,7 +34,7 @@ public void onInitialize(OrienteerWebApplication app, ODatabaseDocument db) { DefaultExports.initialize(); OMetricsRequestCycleListener.install(app); OMetricSessionListener.install(app); -// new OMetricsOrientDB().register(); + new OMetricsOrientDB().register(); // OPerformanceStatisticManager psm = OMetricsOrientDB.getPerformanceStatisticManager(); //WorkAround to avoid NPEs in logs //TODO: Remove when https://github.com/orientechnologies/orientdb/issues/9169 will be fixed diff --git a/orienteer-metrics/src/main/java/org/orienteer/metrics/OMetricsOrientDB.java b/orienteer-metrics/src/main/java/org/orienteer/metrics/OMetricsOrientDB.java index c421ca342..60b30b93a 100644 --- a/orienteer-metrics/src/main/java/org/orienteer/metrics/OMetricsOrientDB.java +++ b/orienteer-metrics/src/main/java/org/orienteer/metrics/OMetricsOrientDB.java @@ -1,14 +1,18 @@ package org.orienteer.metrics; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.function.Function; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.orientechnologies.orient.core.Orient; import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.storage.OStorage; import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage; import com.orientechnologies.orient.core.storage.impl.local.statistic.OPerformanceStatisticManager; @@ -16,6 +20,7 @@ import io.prometheus.client.Collector; import io.prometheus.client.CounterMetricFamily; import io.prometheus.client.GaugeMetricFamily; +import ru.ydn.wicket.wicketorientdb.OrientDbWebSession; import ru.ydn.wicket.wicketorientdb.utils.DBClosure; /** @@ -26,11 +31,13 @@ public class OMetricsOrientDB extends Collector { /** * Utility interface to pack building of {@link MetricFamilySamples} collection + * TODO: Uncomment when performance metrics gathering will be fixed in OrientDB + * https://github.com/orientechnologies/orientdb/issues/9169 */ - @FunctionalInterface + /*@FunctionalInterface private static interface IAddMetricFunction { void addMetric(String name, boolean counter, Function getter); - } + }*/ @Override public List collect() { @@ -38,7 +45,20 @@ public List collect() { @Override protected List execute(ODatabaseDocument db) { List mfs = new ArrayList(); - OPerformanceStatisticManager perf = getPerformanceStatisticManager(db); + mfs.add(new GaugeMetricFamily("orientdb_frozen", "Is DB frozen and in RO mode", db.isFrozen()?1.0:0.0)); + + GaugeMetricFamily count = new GaugeMetricFamily("orientdb_count", "Count of instances per class including subclasses", Collections.singletonList("class")); + long total = 0; + Collection classes = ((ODatabaseDocumentTx)db).getMetadata().getImmutableSchemaSnapshot().getClasses(); + for (OClass oClass : classes) { + count.addMetric(Collections.singletonList(oClass.getName()), oClass.count()); + total+=oClass.count(false); + } + mfs.add(count); + mfs.add(new GaugeMetricFamily("orientdb_count_total", "Count of total instances", total)); + + + /*OPerformanceStatisticManager perf = getPerformanceStatisticManager(db); if(perf!=null) { IAddMetricFunction doOp = (name, counter, getter) -> { Number value = getter.apply(perf); @@ -66,13 +86,13 @@ protected List execute(ODatabaseDocument db) { doOp.addMetric("write_cache_pages_per_flush", false, OPerformanceStatisticManager::getWriteCachePagesPerFlush); doOp.addMetric("write_cache_size", false, OPerformanceStatisticManager::getWriteCacheSize); doOp.addMetric("write_speed_in_cache_in_pages", false, OPerformanceStatisticManager::getWriteSpeedInCacheInPages); - } + }*/ return mfs; } }.execute(); } - public static OPerformanceStatisticManager getPerformanceStatisticManager() { + /*public static OPerformanceStatisticManager getPerformanceStatisticManager() { return new DBClosure() { @Override @@ -90,6 +110,6 @@ public static OPerformanceStatisticManager getPerformanceStatisticManager(ODatab } } return null; - } + }*/ }