This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #578 from zalando/aruha-592-subscription-metrics
ARUHA-592: faceted metrics
- Loading branch information
Showing
17 changed files
with
385 additions
and
190 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/main/java/org/zalando/nakadi/config/MetricsConfig.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,87 @@ | ||
package org.zalando.nakadi.config; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
import com.codahale.metrics.jvm.BufferPoolMetricSet; | ||
import com.codahale.metrics.jvm.GarbageCollectorMetricSet; | ||
import com.codahale.metrics.jvm.MemoryUsageGaugeSet; | ||
import com.codahale.metrics.jvm.ThreadStatesGaugeSet; | ||
import com.codahale.metrics.servlets.MetricsServlet; | ||
import com.ryantenney.metrics.spring.config.annotation.EnableMetrics; | ||
import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.context.embedded.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.lang.management.ManagementFactory; | ||
|
||
@Configuration | ||
@EnableMetrics | ||
public class MetricsConfig { | ||
@Bean | ||
public ServletRegistrationBean servletRegistrationBean(final MetricRegistry metricRegistry) { | ||
return new ServletRegistrationBean(new MetricsServlet(metricRegistry), "/metrics/*"); | ||
} | ||
|
||
class SubscriptionMetricsServlet extends MetricsServlet { | ||
public SubscriptionMetricsServlet(final MetricRegistry metricRegistry) { | ||
super(metricRegistry); | ||
} | ||
} | ||
|
||
class StreamMetricsServlet extends MetricsServlet { | ||
public StreamMetricsServlet(final MetricRegistry metricRegistry) { | ||
super(metricRegistry); | ||
} | ||
} | ||
|
||
@Bean | ||
public ServletRegistrationBean subscriptionsServletRegistrationBean( | ||
@Qualifier("perPathMetricRegistry") final MetricRegistry metricRegistry) { | ||
return new ServletRegistrationBean(new SubscriptionMetricsServlet(metricRegistry), "/request-metrics/*"); | ||
} | ||
|
||
@Bean | ||
public ServletRegistrationBean streamMetricsServletRegistrationBean( | ||
@Qualifier("streamMetricsRegistry") final MetricRegistry metricRegistry) { | ||
return new ServletRegistrationBean(new StreamMetricsServlet(metricRegistry), "/stream-metrics/*"); | ||
} | ||
|
||
@Bean | ||
public MetricsConfigurerAdapter metricsConfigurerAdapter(final MetricRegistry metricRegistry) { | ||
return new MetricsConfigurerAdapter() { | ||
@Override | ||
public MetricRegistry getMetricRegistry() { | ||
return metricRegistry; | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
@Qualifier("perPathMetricRegistry") | ||
public MetricRegistry perPathMetricRegistry() { | ||
final MetricRegistry metricRegistry = new MetricRegistry(); | ||
|
||
return metricRegistry; | ||
} | ||
|
||
@Bean | ||
@Qualifier("streamMetricsRegistry") | ||
public MetricRegistry streamMetricRegistry() { | ||
final MetricRegistry metricRegistry = new MetricRegistry(); | ||
|
||
return metricRegistry; | ||
} | ||
|
||
@Bean | ||
public MetricRegistry metricRegistry() { | ||
final MetricRegistry metricRegistry = new MetricRegistry(); | ||
|
||
metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet()); | ||
metricRegistry.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); | ||
metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet()); | ||
metricRegistry.register("jvm.threads", new ThreadStatesGaugeSet()); | ||
|
||
return metricRegistry; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
package org.zalando.nakadi.metrics; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
|
||
public class MetricUtils { | ||
|
||
public static final String NAKADI_PREFIX = "nakadi."; | ||
public static final String EVENTTYPES_PREFIX = NAKADI_PREFIX + "eventtypes."; | ||
public static final String EVENTTYPES_PREFIX = NAKADI_PREFIX + "eventtypes"; | ||
public static final String SUBSCRIPTION_PREFIX = NAKADI_PREFIX + "subscriptions"; | ||
private static final String LOW_LEVEL_STREAM = "lola"; | ||
private static final String HIGH_LEVEL_STREAM = "hila"; | ||
private static final String BYTES_FLUSHED = "bytes-flushed"; | ||
|
||
public static String metricNameFor(final String eventTypeName, final String metricName) { | ||
return EVENTTYPES_PREFIX + eventTypeName.replace('.', '#') + "." + metricName; | ||
return MetricRegistry.name(EVENTTYPES_PREFIX, eventTypeName.replace('.', '#'), metricName); | ||
} | ||
|
||
public static String metricNameForSubscription(final String subscriptionId, final String metricName) { | ||
return MetricRegistry.name(SUBSCRIPTION_PREFIX, subscriptionId, metricName); | ||
} | ||
|
||
public static String metricNameForLoLAStream(final String applicationId, final String eventTypeName) { | ||
return MetricRegistry.name( | ||
LOW_LEVEL_STREAM, | ||
applicationId.replace(".", "#"), | ||
eventTypeName.replace(".", "#"), | ||
BYTES_FLUSHED); | ||
} | ||
|
||
public static String metricNameForHiLAStream(final String applicationId, final String subscriptionId) { | ||
return MetricRegistry.name( | ||
HIGH_LEVEL_STREAM, | ||
applicationId.replace(".", "#"), | ||
subscriptionId, | ||
BYTES_FLUSHED); | ||
} | ||
} |
Oops, something went wrong.