-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1850 disable internal metric service, add micrometer, add Prometheus…
…MetricsPlugin
- Loading branch information
Showing
22 changed files
with
260 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright © 2021-present Arcade Data Ltd ([email protected]) | ||
Licensed 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. | ||
SPDX-FileCopyrightText: 2021-present Arcade Data Ltd ([email protected]) | ||
SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.arcadedb</groupId> | ||
<artifactId>arcadedb-parent</artifactId> | ||
<version>24.11.2-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>arcadedb-metrics</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<micrometer.version>1.13.6</micrometer.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.arcadedb</groupId> | ||
<artifactId>arcadedb-server</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-registry-prometheus</artifactId> | ||
<version>${micrometer.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
54 changes: 54 additions & 0 deletions
54
metrics/src/main/java/com/arcadedb/metrics/prometheus/PrometheusMetricsPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.