I want to create a new endpoint that extends the existing jhimetrics
endpoint (or extend the results of the existing jhimetrics
). The application is generated with JHipster.
So what I have done is:
- add the new endpoint to the array in
application.yml
file, specifically:
management:
endpoints:
web:
base-path: /management
exposure:
include: [ ..., "health", "info", "jhimetrics", "roxhens"]
- created the
ExtendedMetricsEndpoint.java
with the following content:
// imports, etc...
@Endpoint(id = "roxhens")
public class ExtendedMetricsEndpoint {
private final JHipsterMetricsEndpoint delegate;
private final SimpUserRegistry simpUserRegistry;
public ExtendedMetricsEndpoint(
JHipsterMetricsEndpoint delegate,
SimpUserRegistry simpUserRegistry
) {
this.delegate = delegate;
this.simpUserRegistry = simpUserRegistry;
}
@ReadOperation
public Map<String, Map> getMetrics() {
Map<String, Map> metrics = this.delegate.allMetrics();
HashMap<String, Integer> activeUsers = new HashMap<>();
activeUsers.put("activeUsers", this.simpUserRegistry.getUserCount());
metrics.put("customMetrics", new HashMap(activeUsers));
return metrics;
}
}
- created the configuration file for this endpoint:
// imports etc...
@Configuration
@ConditionalOnClass(Timed.class)
@AutoConfigureAfter(JHipsterMetricsEndpointConfiguration.class)
public class ExtendedMetricsEndpointConfiguration {
@Bean
@ConditionalOnBean({JHipsterMetricsEndpoint.class, SimpUserRegistry.class})
@ConditionalOnMissingBean
@ConditionalOnAvailableEndpoint
public ExtendedMetricsEndpoint extendedMetricsEndpoint(JHipsterMetricsEndpoint jHipsterMetricsEndpoint, SimpUserRegistry simpUserRegistry) {
return new ExtendedMetricsEndpoint(jHipsterMetricsEndpoint, simpUserRegistry);
}
}
What step am I missing here, or what am I doing wrong?