Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics POC #11990

Merged
merged 25 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c64a36d
Initial metrics implementation
skabashnyuk Nov 17, 2018
94b1f8c
fixup! Initial metrics implementation
skabashnyuk Nov 19, 2018
3df8c00
Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 20, 2018
03b1361
fixup! Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 20, 2018
ef7d63d
fixup! fixup! Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 20, 2018
3c9757e
fixup! fixup! fixup! Merge remote-tracking branch 'origin/master' int…
skabashnyuk Nov 21, 2018
c7e494a
fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/mast…
skabashnyuk Nov 21, 2018
e55245b
fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'orig…
skabashnyuk Nov 21, 2018
d7a3f95
Merge branch 'master' into metrics
skabashnyuk Nov 21, 2018
0a7724d
Merge branch 'master' into metrics
skabashnyuk Nov 22, 2018
fcf0ca7
Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 22, 2018
4cbcbf0
fixup! Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 22, 2018
9308766
Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 22, 2018
318c535
Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 23, 2018
4cb68a3
Update core/che-core-metrics-core/src/main/java/org/eclipse/che/core/…
Nov 26, 2018
8207018
Update core/che-core-metrics-core/src/main/java/org/eclipse/che/core/…
Nov 26, 2018
98bc82f
Update core/che-core-metrics-core/src/main/java/org/eclipse/che/core/…
Nov 26, 2018
298a3b1
Update core/che-core-metrics-core/src/main/java/org/eclipse/che/core/…
Nov 26, 2018
4b03bb3
Update core/che-core-metrics-core/src/main/java/org/eclipse/che/core/…
Nov 26, 2018
30dae75
Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 26, 2018
b991e32
fixup! Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 26, 2018
b91989a
Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 27, 2018
4bf526a
Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 27, 2018
ca04b11
fixup! Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 27, 2018
534c454
fixup! fixup! Merge remote-tracking branch 'origin/master' into metrics
skabashnyuk Nov 27, 2018
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 assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-stacks</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-metrics-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-sql-schema</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ protected void configure() {
if (Boolean.valueOf(System.getenv("CHE_TRACING_ENABLED"))) {
install(new org.eclipse.che.core.tracing.TracingModule());
}
if (Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) {
install(new org.eclipse.che.core.metrics.MetricsModule());
}
}

private void configureSingleUserMode(Map<String, String> persistenceProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ protected void configureServlets() {
} else {
configureSingleUserMode();
}

if (Boolean.valueOf(System.getenv("CHE_METRICS_ENABLED"))) {
install(new org.eclipse.che.core.metrics.MetricsServletModule());
}
}

private void configureSingleUserMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,7 @@ che.server.secure_exposer.jwtproxy.memory_limit=128mb
# Maximum size of the json processing pool
# in case if pool size would be exceeded message execution will be rejected
che.core.jsonrpc.processor_max_pool_size=100


## Port the the http server endpoint that would be exposed with Prometheus metrics
che.metrics.port=8087
104 changes: 104 additions & 0 deletions core/che-core-metrics-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2012-2018 Red Hat, Inc.
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

Contributors:
Red Hat, Inc. - initial API and implementation

-->
<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>
<artifactId>che-core-parent</artifactId>
<groupId>org.eclipse.che.core</groupId>
<version>6.15.0-SNAPSHOT</version>
</parent>
<artifactId>che-core-metrics-core</artifactId>
<name>Che Core :: Metrics :: Core</name>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>analyze</id>
<configuration>
<ignoredUsedUndeclaredDependencies>
<ignoredUsedUndeclaredDependency>org.apache.tomcat:tomcat-annotations-api</ignoredUsedUndeclaredDependency>
skabashnyuk marked this conversation as resolved.
Show resolved Hide resolved
</ignoredUsedUndeclaredDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.core.metrics;

import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.binder.MeterBinder;
import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.FileSystems;
import java.util.function.ToDoubleFunction;
import javax.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Bind disk usage metrics for for every {@link java.nio.file.FileStore}. */
@Singleton
public class FileStoresMeterBinder implements MeterBinder {

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

@Override
public void bindTo(MeterRegistry registry) {
for (FileStore fileStore : FileSystems.getDefault().getFileStores()) {
LOG.debug("Add gauge metric for {}", fileStore.name());
Iterable<Tag> tagsWithPath = Tags.concat(Tags.empty(), "path", fileStore.toString());

Gauge.builder("disk.free", fileStore, exceptionToNonWrapper(FileStore::getUnallocatedSpace))
.tags(tagsWithPath)
.description("Unallocated space for file store")
.baseUnit("bytes")
.strongReference(true)
.register(registry);
Gauge.builder("disk.total", fileStore, exceptionToNonWrapper(FileStore::getTotalSpace))
.tags(tagsWithPath)
.description("Total space for file store")
.baseUnit("bytes")
.strongReference(true)
.register(registry);
Gauge.builder("disk.usable", fileStore, exceptionToNonWrapper(FileStore::getUsableSpace))
.tags(tagsWithPath)
.description("Usable space for file store")
.baseUnit("bytes")
.strongReference(true)
.register(registry);
}
}

static <T> ToDoubleFunction<T> exceptionToNonWrapper(
ThrowingToDoubleFunction<T> throwingConsumer) {

return i -> {
try {
return throwingConsumer.applyAsDouble(i);
} catch (Exception ex) {
return Double.NaN;
}
};
}

@FunctionalInterface
interface ThrowingToDoubleFunction<T> {
double applyAsDouble(T t) throws IOException;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.core.metrics;

import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;

/**
* Takes all {@link io.micrometer.core.instrument.binder.MeterBinder} from guice container, binded
* with {@link com.google.inject.multibindings.Multibinder}, and bind them to {@link
* io.micrometer.prometheus.PrometheusMeterRegistry} on PostConstruct.
*/
@Singleton
public class MetricsBinder {

@Inject
public void bindToRegistry(
PrometheusMeterRegistry meterRegistry, Set<MeterBinder> meterBinderList) {
meterBinderList.forEach(e -> e.bindTo(meterRegistry));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.core.metrics;

import com.google.common.annotations.Beta;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
import io.micrometer.core.instrument.binder.MeterBinder;
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.logging.LogbackMetrics;
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.CollectorRegistry;

@Beta
public class MetricsModule extends AbstractModule {
@Override
protected void configure() {
bind(MetricsServer.class).asEagerSingleton();
bind(MetricsBinder.class).asEagerSingleton();
bind(CollectorRegistry.class).toInstance(CollectorRegistry.defaultRegistry);
bind(PrometheusMeterRegistry.class)
.toProvider(PrometheusMeterRegistryProvider.class)
.asEagerSingleton();

Multibinder<MeterBinder> meterMultibinder =
Multibinder.newSetBinder(binder(), MeterBinder.class);
meterMultibinder.addBinding().to(ClassLoaderMetrics.class);
meterMultibinder.addBinding().to(JvmMemoryMetrics.class);
meterMultibinder.addBinding().to(JvmGcMetrics.class);
meterMultibinder.addBinding().to(JvmThreadMetrics.class);
meterMultibinder.addBinding().to(LogbackMetrics.class);
meterMultibinder.addBinding().to(FileDescriptorMetrics.class);
meterMultibinder.addBinding().to(ProcessorMetrics.class);
meterMultibinder.addBinding().to(UptimeMetrics.class);
meterMultibinder.addBinding().to(FileStoresMeterBinder.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.core.metrics;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.HTTPServer;
import java.io.IOException;
import java.net.InetSocketAddress;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Bind on 8087 port http endpoint with prometheus metrics. */
@Singleton
public class MetricsServer {

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

private HTTPServer server;
private final CollectorRegistry collectorRegistry;
private final Integer metricsPort;

@Inject
public MetricsServer(
CollectorRegistry collectorRegistry, @Named("che.metrics.port") Integer metricsPort) {
this.collectorRegistry = collectorRegistry;
this.metricsPort = metricsPort;
}

public void startServer() throws IOException {
this.server = new HTTPServer(new InetSocketAddress(metricsPort), collectorRegistry, true);
LOG.info("Metrics server started at port {} successfully ", metricsPort);
}

@PreDestroy
public void stopServer() {
if (server != null) {
server.stop();
LOG.info("Metrics server suspended at port {} successfully ", metricsPort);
}
}
}
Loading