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

Jetty metrics for solr6 #61

Merged
merged 10 commits into from
Jan 12, 2021
Merged
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Version template:

## [0.4.0] - UNRELEASED

### Added

* Jetty metrics for alfred-telemetry-solr [#61]

[#61]: https://github.com/xenit-eu/alfred-telemetry/pull/61

## [0.3.1] - 2020-12-11

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion alfred-telemetry-platform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {
}

dependencies {
implementation enforcedPlatform("org.alfresco:acs-packaging:${alfrescoVersion}")
alfrescoProvided enforcedPlatform("org.alfresco:acs-packaging:${alfrescoVersion}")

alfrescoProvided('org.alfresco:alfresco-repository')

Expand Down
33 changes: 28 additions & 5 deletions alfred-telemetry-solr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ supports numerous monitoring systems.

This Solr extension offers:

* flexibility to setup and define custom metrics very easily.
* flexibility to setup and define custom metrics easily
* a wide range of out of the box instrumentation


Expand All @@ -15,7 +15,8 @@ At the moment Alfred Telemetry Solr extension auto-configures a CompositeRegistr
* a [`PrometheusMeterRegistry`](https://micrometer.io/docs/registry/prometheus)
* a [`GraphiteMeterRegistry`](https://micrometer.io/docs/registry/graphite)

The extension implements a MicrometerHandler which binds all available metrics to the global registry. For graphite the handler needs to be called once in the beginning, which is done via an init script added to the image.
The extension implements a MicrometerHandler which binds all available metrics to the global registry.
For graphite the handler needs to be called once in the beginning, which is done via an init script added to the image.

In order to visualize correctly the output, a DummyResponseWriter is also provided, which simply displays verbatim the output of Prometheus scraping.

Expand All @@ -28,8 +29,6 @@ See examples in integration tests.

At the moment only Prometheus and Graphite are supported as monitoring systems.

For Graphite the library offered by micrometer conflicts with the library from inside solr6 and therefore replaces that one.

Disabling and configuring the graphite registry can be done via environment variables:

| Variable | Default |
Expand Down Expand Up @@ -110,10 +109,20 @@ At the moment following metrics are included:

See metrics provided by TomcatMetrics [here](https://github.com/micrometer-metrics/micrometer/tree/master/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/tomcat).

## Jetty metrics

Jetty metrics binding provides several jetty-related metrics.
At the moment following metrics are included:

* JettyStatisticsMetrics

See metrics provided by JettyStatisticsMetrics [here](https://github.com/micrometer-metrics/micrometer/tree/master/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jetty/JettyStatisticsMetrics.java).

Note: JettyStatisticsMetrics has been deprecated in favor of TimedHandler, but that requires a newer version of jetty than the one shipped in solr artifacts.

## Custom metrics

Following custom metrics have been implemented.
Besides metrics offered by micrometer, following custom metrics have been implemented:

### Solr core stats metrics

Expand Down Expand Up @@ -236,6 +245,20 @@ and the ResponseWriter:

<lib dir="lib/" regex=".*\.jar" />
<queryResponseWriter name="dummy" class="eu.xenit.alfred.telemetry.solr.writer.DummyResponseWriter"/>

In case of solr6, add to jetty.xml loading of StatisticsHandler:

<Call name="insertHandler">
<Arg>
<New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler" />
</Arg>
</Call>

and in solr-jetty-context.xml make sure server classes are available to the webapp:

<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.server.</Arg>
</Call>

Restart solr.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.xenit.alfred.telemetry.solr.monitoring.registry;

import eu.xenit.alfred.telemetry.solr.util.Util;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
Expand All @@ -13,14 +14,22 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RegistryRegistraar {
public class RegistryRegistrar {
private static RegistryRegistrar registraar = null;
anghelutar marked this conversation as resolved.
Show resolved Hide resolved

private static final Logger logger = LoggerFactory.getLogger(RegistryRegistraar.class);
private static final Logger logger = LoggerFactory.getLogger(RegistryRegistrar.class);
CompositeMeterRegistry globalMeterRegistry = Metrics.globalRegistry;
PrometheusMeterRegistry prometheusMeterRegistry;
GraphiteMeterRegistry graphiteMeterRegistry;

public RegistryRegistraar() {

public static RegistryRegistrar getInstance() {
if(registraar == null)
registraar = new RegistryRegistrar();
return registraar;
}

private RegistryRegistrar() {
// always register the Prometheus registry
prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
prometheusMeterRegistry.config().commonTags(Tags.of("application", "solr"));
Expand Down Expand Up @@ -75,12 +84,12 @@ private String tryToRetrieveHostName() {
}
}

public CompositeMeterRegistry getGlobalMeterRegistry() {
return globalMeterRegistry;
public static MeterRegistry getGlobalMeterRegistry() {
return getInstance().globalMeterRegistry;
}

public PrometheusMeterRegistry getPrometheusMeterRegistry() {
return prometheusMeterRegistry;
public static PrometheusMeterRegistry getPrometheusMeterRegistry() {
return getInstance().prometheusMeterRegistry;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public static boolean isEnabled(String env) {
return Boolean.parseBoolean(System.getenv(env));
}

// everything is enabled by default except graphite registry and tomcat metrics
// everything is enabled by default except graphite registry, tomcat and jetty metrics
anghelutar marked this conversation as resolved.
Show resolved Hide resolved
return ("ALFRED_TELEMETRY_EXPORT_GRAPHITE_ENABLED".equals(env)?
false:
("METRICS_TOMCAT_ENABLED".equals(env) ? false:true));

false:
("METRICS_TOMCAT_ENABLED".equals(env) ? false:
("METRICS_JETTY_ENABLED".equals(env) ? false:true)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import eu.xenit.alfred.telemetry.solr.monitoring.binder.ProcessMetrics;
import eu.xenit.alfred.telemetry.solr.monitoring.binder.SolrMetrics;
import eu.xenit.alfred.telemetry.solr.monitoring.binder.SystemMetrics;
import eu.xenit.alfred.telemetry.solr.monitoring.registry.RegistryRegistraar;
import eu.xenit.alfred.telemetry.solr.monitoring.registry.RegistryRegistrar;
import eu.xenit.alfred.telemetry.solr.util.PrometheusRegistryUtil;
import eu.xenit.alfred.telemetry.solr.util.Util;
import io.micrometer.core.instrument.MeterRegistry;
Expand All @@ -21,8 +21,7 @@

public class MicrometerHandler extends RequestHandlerBase {

static RegistryRegistraar registraar = new RegistryRegistraar();
static MeterRegistry registry = registraar.getGlobalMeterRegistry();
static MeterRegistry registry = RegistryRegistrar.getInstance().getGlobalMeterRegistry();
static SolrMetrics solrMetrics = null;
static MyTomcatMetrics tomcatMetrics = null;

Expand Down Expand Up @@ -52,7 +51,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
tomcatMetrics = new MyTomcatMetrics(mbeanServer);
tomcatMetrics.bindTo(registry);
}
writeTextToResponse(PrometheusRegistryUtil.extractPrometheusScrapeData(registraar.getPrometheusMeterRegistry()),
writeTextToResponse(PrometheusRegistryUtil.extractPrometheusScrapeData(RegistryRegistrar.getInstance().getPrometheusMeterRegistry()),
rsp);
}

Expand Down
Loading