From fe136a4a88e6980e337c6aec0036b1cda87132b8 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Sun, 17 Nov 2024 18:24:35 +0100 Subject: [PATCH] #1850 disable internal metric service, add micrometer, add PrometheusMetricsPlugin --- .../com/arcadedb/GlobalConfiguration.java | 9 ++- .../java/com/arcadedb/utility/CodeUtils.java | 4 +- metrics/pom.xml | 52 ++++++++++++++++ .../prometheus/PrometheusMetricsPlugin.java | 54 ++++++++++++++++ package/pom.xml | 5 ++ pom.xml | 1 + server/pom.xml | 7 +++ .../com/arcadedb/server/ArcadeDBServer.java | 62 +++++++++++++------ .../server/event/FileServerEventLog.java | 18 ++++-- .../java/com/arcadedb/server/ha/HAServer.java | 12 ---- .../http/handler/DeleteDropUserHandler.java | 4 +- .../http/handler/GetDatabasesHandler.java | 4 +- .../handler/GetDynamicContentHandler.java | 4 +- .../handler/GetExistsDatabaseHandler.java | 4 +- .../server/http/handler/GetQueryHandler.java | 5 +- .../server/http/handler/GetReadyHandler.java | 4 +- .../server/http/handler/GetServerHandler.java | 21 ++++--- .../server/http/handler/PostBeginHandler.java | 4 +- .../http/handler/PostCommandHandler.java | 4 +- .../http/handler/PostCommitHandler.java | 5 +- .../http/handler/PostRollbackHandler.java | 5 +- .../handler/PostServerCommandHandler.java | 42 +++++++++---- 22 files changed, 260 insertions(+), 70 deletions(-) create mode 100644 metrics/pom.xml create mode 100644 metrics/src/main/java/com/arcadedb/metrics/prometheus/PrometheusMetricsPlugin.java diff --git a/engine/src/main/java/com/arcadedb/GlobalConfiguration.java b/engine/src/main/java/com/arcadedb/GlobalConfiguration.java index 484c57121a..7f4a709caf 100644 --- a/engine/src/main/java/com/arcadedb/GlobalConfiguration.java +++ b/engine/src/main/java/com/arcadedb/GlobalConfiguration.java @@ -307,8 +307,15 @@ This setting is intended as a safety measure against excessive resource consumpt SERVER_MODE("arcadedb.server.mode", SCOPE.SERVER, "Server mode between 'development', 'test' and 'production'", String.class, "development", Set.of((Object[]) new String[] { "development", "test", "production" })), + // Metrics SERVER_METRICS("arcadedb.serverMetrics", SCOPE.SERVER, "True to enable metrics", Boolean.class, true), + SERVER_METRICS_LOGGING("arcadedb.serverMetrics.logging", SCOPE.SERVER, "True to enable metrics logging", Boolean.class, true), + + SERVER_METRICS_BACKENDS("arcadedb.serverMetrics.backends", SCOPE.SERVER, "Comma separated list of metrics backends to enable", + String.class, "", Set.of("prometheus", "elasticsearch", "datadog", "jmx")), + + //paths SERVER_ROOT_PATH("arcadedb.server.rootPath", SCOPE.SERVER, "Root path in the file system where the server is looking for files. By default is the current directory", String.class, null), @@ -389,7 +396,7 @@ This setting is intended as a safety measure against excessive resource consumpt String.class, ""), HA_QUORUM("arcadedb.ha.quorum", SCOPE.SERVER, - "Default quorum between 'none', one, two, three, 'majority' and 'all' servers. Default is majority", String.class, "majority", + "Default quorum between 'none', one, two, three, 'majority' and 'all' servers. Default is majority",String.class , "majority", Set.of(new String[] { "none", "one", "two", "three", "majority", "all" })), HA_QUORUM_TIMEOUT("arcadedb.ha.quorumTimeout", SCOPE.SERVER, "Timeout waiting for the quorum", Long.class, 10000), diff --git a/engine/src/main/java/com/arcadedb/utility/CodeUtils.java b/engine/src/main/java/com/arcadedb/utility/CodeUtils.java index 2b2b9dddcb..5e2640566b 100755 --- a/engine/src/main/java/com/arcadedb/utility/CodeUtils.java +++ b/engine/src/main/java/com/arcadedb/utility/CodeUtils.java @@ -28,7 +28,9 @@ */ public class CodeUtils { - public static void executeIgnoringExceptions(final CallableNoReturn callback, final String errorMessage, + public static void executeIgnoringExceptions( + final CallableNoReturn callback, + final String errorMessage, final boolean logException) { try { callback.call(); diff --git a/metrics/pom.xml b/metrics/pom.xml new file mode 100644 index 0000000000..51bb101de9 --- /dev/null +++ b/metrics/pom.xml @@ -0,0 +1,52 @@ + + + + 4.0.0 + + + com.arcadedb + arcadedb-parent + 24.11.2-SNAPSHOT + ../pom.xml + + + arcadedb-metrics + jar + + + 1.13.6 + + + + + com.arcadedb + arcadedb-server + ${project.parent.version} + + + io.micrometer + micrometer-registry-prometheus + ${micrometer.version} + + + + diff --git a/metrics/src/main/java/com/arcadedb/metrics/prometheus/PrometheusMetricsPlugin.java b/metrics/src/main/java/com/arcadedb/metrics/prometheus/PrometheusMetricsPlugin.java new file mode 100644 index 0000000000..3e24c09d8a --- /dev/null +++ b/metrics/src/main/java/com/arcadedb/metrics/prometheus/PrometheusMetricsPlugin.java @@ -0,0 +1,54 @@ +package com.arcadedb.metrics.prometheus; + +import com.arcadedb.ContextConfiguration; +import com.arcadedb.GlobalConfiguration; +import com.arcadedb.log.LogManager; +import com.arcadedb.server.ArcadeDBServer; +import com.arcadedb.server.ServerPlugin; +import com.arcadedb.server.http.HttpServer; +import io.micrometer.core.instrument.Metrics; +import io.micrometer.prometheusmetrics.PrometheusConfig; +import io.micrometer.prometheusmetrics.PrometheusMeterRegistry; +import io.undertow.io.Sender; +import io.undertow.server.handlers.PathHandler; +import io.undertow.util.Headers; + +import java.util.logging.Level; + +public class PrometheusMetricsPlugin implements ServerPlugin { + + private PrometheusMeterRegistry registry; + private boolean enabled; + + @Override + public void configure(ArcadeDBServer arcadeDBServer, ContextConfiguration configuration) { + enabled = configuration.getValueAsBoolean(GlobalConfiguration.SERVER_METRICS); + registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); + Metrics.addRegistry(registry); + } + + @Override + public void startService() { + if (enabled) { + LogManager.instance().log(this, Level.INFO, "Prometheus backend metrics enabled"); + } + } + + @Override + public void registerAPI(final HttpServer httpServer, final PathHandler routes) { + if (!enabled) + return; + + routes.addExactPath("/prometheus", exchange -> { + String response = registry.scrape(); + exchange.setStatusCode(200); + exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, response.getBytes().length); + exchange.getResponseSender().send(response); + + }); + + LogManager.instance().log(this, Level.INFO, "Prometheus backend metrics http handler configured"); + + } + +} diff --git a/package/pom.xml b/package/pom.xml index 5d685531d4..4ca2126dd7 100644 --- a/package/pom.xml +++ b/package/pom.xml @@ -114,6 +114,11 @@ arcadedb-server ${project.parent.version} + + com.arcadedb + arcadedb-metrics + ${project.parent.version} + com.arcadedb arcadedb-studio diff --git a/pom.xml b/pom.xml index cdfe31a2a2..3fadcf9b38 100644 --- a/pom.xml +++ b/pom.xml @@ -115,6 +115,7 @@ engine network server + metrics integration console gremlin diff --git a/server/pom.xml b/server/pom.xml index 090f4c1027..4653687f23 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -36,6 +36,7 @@ 4.2.19 2.0.16 2.3.18.Final + 1.13.6 @@ -96,5 +97,11 @@ slf4j-jdk14 ${slf4j.version} + + io.micrometer + micrometer-core + ${micrometer.version} + + diff --git a/server/src/main/java/com/arcadedb/server/ArcadeDBServer.java b/server/src/main/java/com/arcadedb/server/ArcadeDBServer.java index 91c4cb9a01..e438f9f385 100644 --- a/server/src/main/java/com/arcadedb/server/ArcadeDBServer.java +++ b/server/src/main/java/com/arcadedb/server/ArcadeDBServer.java @@ -40,20 +40,37 @@ import com.arcadedb.server.ha.HAServer; import com.arcadedb.server.ha.ReplicatedDatabase; import com.arcadedb.server.http.HttpServer; -import com.arcadedb.server.monitor.DefaultServerMetrics; -import com.arcadedb.server.monitor.ServerMetrics; import com.arcadedb.server.monitor.ServerMonitor; import com.arcadedb.server.security.ServerSecurity; import com.arcadedb.server.security.ServerSecurityException; import com.arcadedb.server.security.ServerSecurityUser; import com.arcadedb.utility.CodeUtils; import com.arcadedb.utility.FileUtils; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.logging.*; +import io.micrometer.core.instrument.Metrics; +import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; +import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; +import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; +import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; +import io.micrometer.core.instrument.binder.system.ProcessorMetrics; +import io.micrometer.core.instrument.logging.LoggingMeterRegistry; +import io.micrometer.core.instrument.simple.SimpleMeterRegistry; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.logging.Level; import static com.arcadedb.engine.ComponentFile.MODE.READ_ONLY; import static com.arcadedb.engine.ComponentFile.MODE.READ_WRITE; @@ -75,7 +92,7 @@ public enum STATUS {OFFLINE, STARTING, ONLINE, SHUTTING_DOWN} private final ConcurrentMap databases = new ConcurrentHashMap<>(); private final List testEventListeners = new ArrayList<>(); private volatile STATUS status = STATUS.OFFLINE; - private ServerMetrics serverMetrics = new DefaultServerMetrics(); + // private ServerMetrics serverMetrics = new DefaultServerMetrics(); private ServerMonitor serverMonitor; static { @@ -133,12 +150,21 @@ public synchronized void start() { // START METRICS & CONNECTED JMX REPORTER if (configuration.getValueAsBoolean(GlobalConfiguration.SERVER_METRICS)) { - if (serverMetrics != null) - serverMetrics.stop(); - serverMetrics = new DefaultServerMetrics(); + Metrics.addRegistry(new SimpleMeterRegistry()); + + new ClassLoaderMetrics().bindTo(Metrics.globalRegistry); + new JvmMemoryMetrics().bindTo(Metrics.globalRegistry); + new JvmGcMetrics().bindTo(Metrics.globalRegistry); + new ProcessorMetrics().bindTo(Metrics.globalRegistry); + new JvmThreadMetrics().bindTo(Metrics.globalRegistry); +// new JvmThreadDeadlockMetrics().bindTo(registry); + + if (configuration.getValueAsBoolean(GlobalConfiguration.SERVER_METRICS_LOGGING)) { + LogManager.instance().log(this, Level.INFO, "- Logging metrics enabled..."); + Metrics.addRegistry(new LoggingMeterRegistry()); + } LogManager.instance().log(this, Level.INFO, "- Metrics Collection Started..."); } - security = new ServerSecurity(this, configuration, serverRootPath + "/config"); security.startService(); @@ -295,8 +321,8 @@ public synchronized void stop() { CodeUtils.executeIgnoringExceptions(() -> { LogManager.instance().log(this, Level.INFO, "- Stop JMX Metrics"); - serverMetrics.stop(); - serverMetrics = new DefaultServerMetrics(); +// serverMetrics.stop(); +// serverMetrics = new DefaultServerMetrics(); }, "Error on stopping JMX Metrics", false); LogManager.instance().log(this, Level.INFO, "ArcadeDB Server is down"); @@ -319,9 +345,9 @@ public Collection getPlugins() { return Collections.unmodifiableCollection(plugins.values()); } - public ServerMetrics getServerMetrics() { - return serverMetrics; - } +// public ServerMetrics getServerMetrics() { +// return serverMetrics; +// } public ServerDatabase getDatabase(final String databaseName) { return getDatabase(databaseName, false, true); diff --git a/server/src/main/java/com/arcadedb/server/event/FileServerEventLog.java b/server/src/main/java/com/arcadedb/server/event/FileServerEventLog.java index 4e2e03e67c..e5c188c758 100644 --- a/server/src/main/java/com/arcadedb/server/event/FileServerEventLog.java +++ b/server/src/main/java/com/arcadedb/server/event/FileServerEventLog.java @@ -28,10 +28,16 @@ import com.arcadedb.server.security.ServerSecurityException; import com.arcadedb.utility.FileUtils; -import java.io.*; -import java.text.*; -import java.util.*; -import java.util.logging.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.logging.Level; public class FileServerEventLog implements ServerEventLog { private final static String FILE_PREFIX = "server-event-log-"; @@ -108,15 +114,15 @@ public void reportEvent(final EVENT_TYPE eventType, final String component, fina if (newFileName == null) return; - final JSONObject json = new JSONObject(); try { + final JSONObject json = new JSONObject(); json.put("time", dateFormat.format(new Date())); json.put("type", eventType); json.put("component", component); json.put("db", databaseName); json.put("message", message); - FileUtils.appendContentToFile(newFileName, json.toString() + "\n"); + FileUtils.appendContentToFile(newFileName, json + "\n"); } catch (IOException e) { LogManager.instance().log(this, Level.SEVERE, "Error on writing into server event log file %s", e, newFileName); } diff --git a/server/src/main/java/com/arcadedb/server/ha/HAServer.java b/server/src/main/java/com/arcadedb/server/ha/HAServer.java index 305861bba9..38fc909361 100644 --- a/server/src/main/java/com/arcadedb/server/ha/HAServer.java +++ b/server/src/main/java/com/arcadedb/server/ha/HAServer.java @@ -144,18 +144,6 @@ public ForwardedMessage() { } } -// private static class RemovedServerInfo { -// String serverName; -// long joinedOn; -// long leftOn; -// -// public RemovedServerInfo(final String remoteServerName, final long joinedOn) { -// this.serverName = remoteServerName; -// this.joinedOn = joinedOn; -// this.leftOn = System.currentTimeMillis(); -// } -// } - public HAServer(final ArcadeDBServer server, final ContextConfiguration configuration) { if (!configuration.getValueAsBoolean(GlobalConfiguration.TX_WAL)) throw new ConfigurationException("Cannot start HA service without using WAL. Please enable the TX_WAL setting."); diff --git a/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java index 5fa024af53..86a5ba50f4 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java @@ -20,6 +20,7 @@ import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import java.util.*; @@ -48,7 +49,8 @@ public ExecutionResponse execute(final HttpServerExchange exchange, final Server if (userName == null) return new ExecutionResponse(400, "{ \"error\" : \"User name parameter is null\"}"); - httpServer.getServer().getServerMetrics().meter("http.drop-user").hit(); +// httpServer.getServer().getServerMetrics().meter("http.drop-user").hit(); + Metrics.counter("http.drop-user").increment(); ; final boolean result = httpServer.getServer().getSecurity().dropUser(userName); if (!result) diff --git a/server/src/main/java/com/arcadedb/server/http/handler/GetDatabasesHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/GetDatabasesHandler.java index 203385b479..f2c0bbca5f 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/GetDatabasesHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/GetDatabasesHandler.java @@ -22,6 +22,7 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import java.util.*; @@ -42,7 +43,8 @@ protected ExecutionResponse execute(final HttpServerExchange exchange, final Ser final JSONObject result = createResult(user, null).put("result", new JSONArray(installedDatabases)); - httpServer.getServer().getServerMetrics().meter("http.list-databases").hit(); +// httpServer.getServer().getServerMetrics().meter("http.list-databases").hit(); + Metrics.counter("http.list-databases").increment(); ; return new ExecutionResponse(200, result.toString()); } diff --git a/server/src/main/java/com/arcadedb/server/http/handler/GetDynamicContentHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/GetDynamicContentHandler.java index 93456a9cd1..59370e9a0b 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/GetDynamicContentHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/GetDynamicContentHandler.java @@ -25,6 +25,7 @@ import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.security.ServerSecurityUser; import com.arcadedb.utility.FileUtils; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import io.undertow.util.Headers; @@ -90,7 +91,8 @@ else if (uri.endsWith(".svg")) { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, contentType); - httpServer.getServer().getServerMetrics().meter("http.static-content").hit(); +// httpServer.getServer().getServerMetrics().meter("http.static-content").hit(); + Metrics.counter("http.static-content").increment(); ; LogManager.instance().log(this, Level.FINE, "Loading file %s ", "/static" + uri); diff --git a/server/src/main/java/com/arcadedb/server/http/handler/GetExistsDatabaseHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/GetExistsDatabaseHandler.java index db2cebba26..c7836d8c5a 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/GetExistsDatabaseHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/GetExistsDatabaseHandler.java @@ -22,6 +22,7 @@ import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import java.util.*; @@ -38,7 +39,8 @@ public ExecutionResponse execute(final HttpServerExchange exchange, final Server return new ExecutionResponse(400, "{ \"error\" : \"Database parameter is null\"}"); final ArcadeDBServer server = httpServer.getServer(); - server.getServerMetrics().meter("http.exists-database").hit(); +// server.getServerMetrics().meter("http.exists-database").hit(); + Metrics.counter("http.exists-database").increment(); ; final Set installedDatabases = new HashSet<>(server.getDatabaseNames()); final Set allowedDatabases = user.getAuthorizedDatabases(); diff --git a/server/src/main/java/com/arcadedb/server/http/handler/GetQueryHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/GetQueryHandler.java index 4d944b1444..13ac50e2bb 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/GetQueryHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/GetQueryHandler.java @@ -23,6 +23,7 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import java.io.*; @@ -63,7 +64,9 @@ public ExecutionResponse execute(final HttpServerExchange exchange, final Server serializeResultSet(database, serializer, limit, response, qResult); } finally { - httpServer.getServer().getServerMetrics().meter("http.query").hit(); +// httpServer.getServer().getServerMetrics().meter("http.query").hit(); + Metrics.counter("http.query").increment(); ; + } return new ExecutionResponse(200, response.toString()); diff --git a/server/src/main/java/com/arcadedb/server/http/handler/GetReadyHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/GetReadyHandler.java index 8ccddf64ec..4f0c354862 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/GetReadyHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/GetReadyHandler.java @@ -21,6 +21,7 @@ import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; public class GetReadyHandler extends AbstractServerHttpHandler { @@ -30,7 +31,8 @@ public GetReadyHandler(final HttpServer httpServer) { @Override public ExecutionResponse execute(final HttpServerExchange exchange, final ServerSecurityUser user) { - httpServer.getServer().getServerMetrics().meter("http.ready").hit(); +// httpServer.getServer().getServerMetrics().meter("http.ready").hit(); + Metrics.counter("http.ready").increment(); ; if (httpServer.getServer().getStatus() == ArcadeDBServer.STATUS.ONLINE) return new ExecutionResponse(204, ""); diff --git a/server/src/main/java/com/arcadedb/server/http/handler/GetServerHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/GetServerHandler.java index 5aa9b9ad1b..52d246bdb3 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/GetServerHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/GetServerHandler.java @@ -30,6 +30,8 @@ import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.monitor.ServerMetrics; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import java.io.*; @@ -57,7 +59,8 @@ public ExecutionResponse execute(final HttpServerExchange exchange, final Server exportCluster(exchange, response); } - httpServer.getServer().getServerMetrics().meter("http.server-info").hit(); +// httpServer.getServer().getServerMetrics().meter("http.server-info").hit(); + Metrics.counter("http.server-info").increment(); ; return new ExecutionResponse(200, response.toString()); } @@ -139,14 +142,14 @@ private void exportMetrics(final JSONObject response) { final JSONObject metersJSON = new JSONObject(); metricsJSON.put("meters", metersJSON); - for (Map.Entry entry : httpServer.getServer().getServerMetrics().getMeters().entrySet()) { - final ServerMetrics.Meter meter = entry.getValue(); - - metersJSON.put(entry.getKey(), new JSONObject().put("count", meter.getTotalCounter())// - .put("reqPerSecLastMinute", meter.getRequestsPerSecondInLastMinute())// - .put("reqPerSecSinceLastTime", meter.getRequestsPerSecondSinceLastAsked())// - ); - } +// for (Map.Entry entry : httpServer.getServer().getServerMetrics().getMeters().entrySet()) { +// final ServerMetrics.Meter meter = entry.getValue(); +// +// metersJSON.put(entry.getKey(), new JSONObject().put("count", meter.getTotalCounter())// +// .put("reqPerSecLastMinute", meter.getRequestsPerSecondInLastMinute())// +// .put("reqPerSecSinceLastTime", meter.getRequestsPerSecondSinceLastAsked())// +// ); +// } int serverEventsSummaryErrors = 0; int serverEventsSummaryWarnings = 0; diff --git a/server/src/main/java/com/arcadedb/server/http/handler/PostBeginHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/PostBeginHandler.java index 351cf44c81..0ce2851122 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/PostBeginHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/PostBeginHandler.java @@ -27,6 +27,7 @@ import com.arcadedb.server.http.HttpSession; import com.arcadedb.server.http.HttpSessionManager; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import io.undertow.util.HeaderValues; import io.undertow.util.HttpString; @@ -72,7 +73,8 @@ public ExecutionResponse execute(final HttpServerExchange exchange, final Server exchange.getResponseHeaders().put(new HttpString(HttpSessionManager.ARCADEDB_SESSION_ID), session.id); - httpServer.getServer().getServerMetrics().meter("http.begin").hit(); +// httpServer.getServer().getServerMetrics().meter("http.begin").hit(); + Metrics.counter("http.begin").increment(); ; return new ExecutionResponse(204, ""); } diff --git a/server/src/main/java/com/arcadedb/server/http/handler/PostCommandHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/PostCommandHandler.java index 5c5f04ea11..83779e9832 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/PostCommandHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/PostCommandHandler.java @@ -25,6 +25,7 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import java.io.*; @@ -119,7 +120,8 @@ public ExecutionResponse execute(final HttpServerExchange exchange, final Server if (qResult != null && profileExecution != null && qResult.getExecutionPlan().isPresent()) qResult.getExecutionPlan().ifPresent(x -> response.put("explain", qResult.getExecutionPlan().get().prettyPrint(0, 2))); - httpServer.getServer().getServerMetrics().meter("http.command").hit(); +// httpServer.getServer().getServerMetrics().meter("http.command").hit(); + Metrics.counter("http.comand").increment(); ; return new ExecutionResponse(200, response.toString()); } diff --git a/server/src/main/java/com/arcadedb/server/http/handler/PostCommitHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/PostCommitHandler.java index 671a14bc28..ad9cc29ace 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/PostCommitHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/PostCommitHandler.java @@ -22,6 +22,7 @@ import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.http.HttpSessionManager; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import java.io.*; @@ -36,7 +37,9 @@ public PostCommitHandler(final HttpServer httpServer) { public ExecutionResponse execute(final HttpServerExchange exchange, final ServerSecurityUser user, final Database database) throws IOException { database.commit(); exchange.getResponseHeaders().remove(HttpSessionManager.ARCADEDB_SESSION_ID); - httpServer.getServer().getServerMetrics().meter("http.commit").hit(); +// httpServer.getServer().getServerMetrics().meter("http.commit").hit(); + Metrics.counter("http.commit").increment(); ; + return new ExecutionResponse(204, ""); } diff --git a/server/src/main/java/com/arcadedb/server/http/handler/PostRollbackHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/PostRollbackHandler.java index 0e3bf36689..7bf3f4fef3 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/PostRollbackHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/PostRollbackHandler.java @@ -22,6 +22,7 @@ import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.http.HttpSessionManager; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import java.io.*; @@ -36,7 +37,9 @@ public PostRollbackHandler(final HttpServer httpServer) { public ExecutionResponse execute(final HttpServerExchange exchange, final ServerSecurityUser user, final Database database) throws IOException { database.rollback(); exchange.getResponseHeaders().remove(HttpSessionManager.ARCADEDB_SESSION_ID); - httpServer.getServer().getServerMetrics().meter("http.rollback").hit(); +// httpServer.getServer().getServerMetrics().meter("http.rollback").hit(); + Metrics.counter("http.rollback").increment(); ; + return new ExecutionResponse(204, ""); } diff --git a/server/src/main/java/com/arcadedb/server/http/handler/PostServerCommandHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/PostServerCommandHandler.java index 877cf4f188..afe07fd6e9 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/PostServerCommandHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/PostServerCommandHandler.java @@ -37,6 +37,7 @@ import com.arcadedb.server.http.HttpServer; import com.arcadedb.server.security.ServerSecurityException; import com.arcadedb.server.security.ServerSecurityUser; +import io.micrometer.core.instrument.Metrics; import io.undertow.server.HttpServerExchange; import io.undertow.util.StatusCodes; @@ -115,7 +116,9 @@ else if (command_lc.startsWith(GET_SERVER_EVENTS)) else if (command_lc.startsWith(ALIGN_DATABASE)) alignDatabase(command.substring(ALIGN_DATABASE.length()).trim()); else { - httpServer.getServer().getServerMetrics().meter("http.server-command.invalid").hit(); +// httpServer.getServer().getServerMetrics().meter("http.server-command.invalid").hit(); + Metrics.counter("http.server-command.invalid").increment(); ; + return new ExecutionResponse(400, "{ \"error\" : \"Server command not valid\"}"); } @@ -124,7 +127,8 @@ else if (command_lc.startsWith(ALIGN_DATABASE)) private ExecutionResponse listDatabases(final ServerSecurityUser user) { final ArcadeDBServer server = httpServer.getServer(); - server.getServerMetrics().meter("http.list-databases").hit(); +// server.getServerMetrics().meter("http.list-databases").hit(); + Metrics.counter("http.list-databases").increment(); ; final Set installedDatabases = new HashSet<>(server.getDatabaseNames()); final Set allowedDatabases = user.getAuthorizedDatabases(); @@ -138,7 +142,8 @@ private ExecutionResponse listDatabases(final ServerSecurityUser user) { } private void shutdownServer(final String serverName) throws IOException { - httpServer.getServer().getServerMetrics().meter("http.server-shutdown").hit(); +// httpServer.getServer().getServerMetrics().meter("http.server-shutdown").hit(); + Metrics.counter("http.server-shutdown").increment(); ; if (serverName.isEmpty()) { // SHUTDOWN CURRENT SERVER @@ -168,7 +173,8 @@ private void createDatabase(final String databaseName) { checkServerIsLeaderIfInHA(); final ArcadeDBServer server = httpServer.getServer(); - server.getServerMetrics().meter("http.create-database").hit(); +// server.getServerMetrics().meter("http.create-database").hit(); + Metrics.counter("http.create-database").increment(); ; final ServerDatabase db = server.createDatabase(databaseName, ComponentFile.MODE.READ_WRITE); @@ -184,7 +190,8 @@ private void dropDatabase(final String databaseName) { final ServerDatabase database = httpServer.getServer().getDatabase(databaseName); - httpServer.getServer().getServerMetrics().meter("http.drop-database").hit(); +// httpServer.getServer().getServerMetrics().meter("http.drop-database").hit(); + Metrics.counter("http.drop-database").increment(); ; database.getEmbedded().drop(); httpServer.getServer().removeDatabase(database.getName()); @@ -197,7 +204,8 @@ private void closeDatabase(final String databaseName) { final ServerDatabase database = httpServer.getServer().getDatabase(databaseName); database.getEmbedded().close(); - httpServer.getServer().getServerMetrics().meter("http.close-database").hit(); +// httpServer.getServer().getServerMetrics().meter("http.close-database").hit(); + Metrics.counter("http.close-database").increment(); ; httpServer.getServer().removeDatabase(database.getName()); } @@ -206,7 +214,8 @@ private void openDatabase(final String databaseName) { throw new IllegalArgumentException("Database name empty"); httpServer.getServer().getDatabase(databaseName); - httpServer.getServer().getServerMetrics().meter("http.open-database").hit(); +// httpServer.getServer().getServerMetrics().meter("http.open-database").hit(); + Metrics.counter("http.open-database").increment(); ; } private void createUser(final String payload) { @@ -223,7 +232,8 @@ private void createUser(final String payload) { json.put("password", httpServer.getServer().getSecurity().encodePassword(userPassword)); - httpServer.getServer().getServerMetrics().meter("http.create-user").hit(); +// httpServer.getServer().getServerMetrics().meter("http.create-user").hit(); + Metrics.counter("http.create-user").increment(); ; httpServer.getServer().getSecurity().createUser(json); } @@ -232,7 +242,8 @@ private void dropUser(final String userName) { if (userName.isEmpty()) throw new IllegalArgumentException("User name was missing"); - httpServer.getServer().getServerMetrics().meter("http.drop-user").hit(); +// httpServer.getServer().getServerMetrics().meter("http.drop-user").hit(); + Metrics.counter("http.drop-user").increment(); ; final boolean result = httpServer.getServer().getSecurity().dropUser(userName); if (!result) @@ -242,7 +253,8 @@ private void dropUser(final String userName) { private boolean connectCluster(final String serverAddress, final HttpServerExchange exchange) { final HAServer ha = getHA(); - httpServer.getServer().getServerMetrics().meter("http.connect-cluster").hit(); +// httpServer.getServer().getServerMetrics().meter("http.connect-cluster").hit(); + Metrics.counter("http.connect-cluster").increment(); ; return ha.connectToLeader(serverAddress, exception -> { exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); @@ -252,7 +264,9 @@ private boolean connectCluster(final String serverAddress, final HttpServerExcha } private void disconnectCluster() { - httpServer.getServer().getServerMetrics().meter("http.server-disconnect").hit(); +// httpServer.getServer().getServerMetrics().meter("http.server-disconnect").hit(); + Metrics.counter("http.server-disconnect").increment(); ; + final HAServer ha = getHA(); final Replica2LeaderNetworkExecutor leader = ha.getLeader(); @@ -282,7 +296,8 @@ private void setServerSetting(final String pair) { private String getServerEvents(final String fileName) { final ArcadeDBServer server = httpServer.getServer(); - server.getServerMetrics().meter("http.get-server-events").hit(); +// server.getServerMetrics().meter("http.get-server-events").hit(); + Metrics.counter("http.get-server-events").increment(); ; final JSONArray events = fileName.isEmpty() ? server.getEventLog().getCurrentEvents() : @@ -298,7 +313,8 @@ private void alignDatabase(final String databaseName) { final Database database = httpServer.getServer().getDatabase(databaseName); - httpServer.getServer().getServerMetrics().meter("http.align-database").hit(); +// httpServer.getServer().getServerMetrics().meter("http.align-database").hit(); + Metrics.counter("http.align-database").increment(); ; database.command("sql", "align database"); }