Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ingester-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@
<groupId>${project.groupId}</groupId>
<artifactId>ingester-bulk-protocol</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ingester-prometheus-metrics</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public static void main(String[] args) throws Exception {

bulkStreamWriter.completed();
}

greptimeDB.shutdownGracefully();
}

private static Object[] generateOneRow(int cardinality) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import io.greptime.BulkStreamWriter;
import io.greptime.BulkWrite;
import io.greptime.GreptimeDB;
import io.greptime.common.util.MetricsUtil;
import io.greptime.common.util.ServiceLoader;
import io.greptime.common.util.SystemPropertyUtil;
import io.greptime.metrics.MetricsExporter;
import io.greptime.models.Table;
import io.greptime.models.TableSchema;
import io.greptime.rpc.Compression;
Expand Down Expand Up @@ -52,6 +54,10 @@ public static void main(String[] args) throws Exception {
LOG.info("Using zstd compression: {}", zstdCompression);
LOG.info("Batch size: {}", batchSize);

// Start a metrics exporter
MetricsExporter metricsExporter = new MetricsExporter(8080, MetricsUtil.metricRegistry());
metricsExporter.init(null);

GreptimeDB greptimeDB = DBConnector.connectTo(new String[] {endpoint}, dbName);

BulkWrite.Config cfg = BulkWrite.Config.newBuilder()
Expand Down Expand Up @@ -111,5 +117,6 @@ public static void main(String[] args) throws Exception {
}

greptimeDB.shutdownGracefully();
metricsExporter.shutdownGracefully();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import io.greptime.GreptimeDB;
import io.greptime.StreamWriter;
import io.greptime.common.util.MetricsUtil;
import io.greptime.common.util.ServiceLoader;
import io.greptime.common.util.SystemPropertyUtil;
import io.greptime.metrics.MetricsExporter;
import io.greptime.models.Table;
import io.greptime.models.TableSchema;
import io.greptime.models.WriteOk;
Expand Down Expand Up @@ -55,6 +57,10 @@ public static void main(String[] args) throws Exception {
LOG.info("Batch size: {}", batchSize);
LOG.info("Max points per second: {}", maxPointsPerSecond);

// Start a metrics exporter
MetricsExporter metricsExporter = new MetricsExporter(8080, MetricsUtil.metricRegistry());
metricsExporter.init(null);

GreptimeDB greptimeDB = DBConnector.connectTo(new String[] {endpoint}, dbName);

Compression compression = zstdCompression ? Compression.Zstd : Compression.None;
Expand Down Expand Up @@ -100,5 +106,6 @@ public static void main(String[] args) throws Exception {

greptimeDB.shutdownGracefully();
tableDataProvider.close();
metricsExporter.shutdownGracefully();
}
}
49 changes: 49 additions & 0 deletions ingester-prometheus-metrics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2023 Greptime Team

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.

-->
<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>io.greptime</groupId>
<artifactId>greptimedb-ingester</artifactId>
<version>0.14.2</version>
</parent>
<artifactId>ingester-prometheus-metrics</artifactId>

<properties>
<prometheus.version>0.16.0</prometheus.version>
</properties>

<dependencies>
<dependency>
<groupId>io.greptime</groupId>
<artifactId>ingester-common</artifactId>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_dropwizard</artifactId>
<version>${prometheus.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>${prometheus.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2023 Greptime Team
*
* 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.
*/

package io.greptime.metrics;

import com.codahale.metrics.MetricRegistry;
import io.greptime.common.Lifecycle;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;
import io.prometheus.client.exporter.HTTPServer;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MetricsExporter implements Lifecycle<Void> {

private static final Logger LOG = LoggerFactory.getLogger(MetricsExporter.class);

private final CollectorRegistry prometheusMetricRegistry;

private final int port;
private HTTPServer server;

private final AtomicBoolean started = new AtomicBoolean(false);

public MetricsExporter(int port, MetricRegistry dropwizardMetricRegistry) {
this.port = port;
this.prometheusMetricRegistry = new CollectorRegistry();
this.prometheusMetricRegistry.register(new DropwizardExports(dropwizardMetricRegistry));
}

@Override
public boolean init(Void opts) {
if (this.started.compareAndSet(false, true)) {
try {
this.server = new HTTPServer(new InetSocketAddress(this.port), this.prometheusMetricRegistry);
LOG.info("Metrics exporter started at `http://localhost:{}/metrics`", this.port);
return true;
} catch (IOException e) {
this.started.set(false);
LOG.error("Failed to start metrics exporter", e);
throw new RuntimeException("Failed to start metrics exporter", e);
}
}
return false;
}

@Override
public void shutdownGracefully() {
if (this.started.compareAndSet(true, false)) {
if (this.server != null) {
this.server.close();
LOG.info("Metrics exporter stopped");
}
}
}
}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<module>ingester-example</module>
<module>ingester-all</module>
<module>ingester-bulk-protocol</module>
<module>ingester-prometheus-metrics</module>
</modules>

<scm>
Expand Down Expand Up @@ -122,6 +123,11 @@
<artifactId>ingester-grpc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ingester-prometheus-metrics</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ingester-protocol</artifactId>
Expand Down