use of org.eclipse.microprofile.metrics.MetricRegistry.Type in project Payara by payara.
the class MetricsServiceImpl method processMetadataToAnnotations.
private static void processMetadataToAnnotations(MetricsContextImpl context, MonitoringDataCollector collector) {
RegisteredMetric metric = context.pollNewlyRegistered();
while (metric != null) {
MetricID metricID = metric.id;
Type scope = metric.scope;
MetricRegistry registry = context.getRegistry(scope);
MonitoringDataCollector metricCollector = tagCollector(context.getName(), metricID, collector);
Metadata metadata = registry.getMetadata(metricID.getName());
String suffix = "Count";
String property = "Count";
boolean isGauge = metadata.getTypeRaw() == MetricType.GAUGE;
if (isGauge) {
suffix = getMetricUnitSuffix(metadata.unit());
property = "Value";
}
// Note that by convention an annotation with value 0 done before the series collected any value is considered permanent
metricCollector.annotate(toName(metricID, suffix), 0, false, metadataToAnnotations(context.getName(), scope, metadata, property));
metric = context.pollNewlyRegistered();
}
}
use of org.eclipse.microprofile.metrics.MetricRegistry.Type in project Payara by payara.
the class MetricsResource method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>OPTIONS</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MetricsService metricsService = Globals.getDefaultBaseServiceLocator().getService(MetricsService.class);
if (!metricsService.isEnabled()) {
response.sendError(SC_FORBIDDEN, "MicroProfile Metrics Service is disabled");
return;
}
metricsService.refresh();
String pathInfo = request.getPathInfo() != null ? request.getPathInfo().substring(1) : EMPTY_STRING;
String[] pathInfos = pathInfo.split("/");
String registryName = pathInfos.length > 0 ? pathInfos[0] : null;
String metricName = pathInfos.length > 1 ? pathInfos[1] : null;
try {
String contentType = getContentType(request, response);
if (contentType != null) {
response.setContentType(contentType);
response.setCharacterEncoding(UTF_8.name());
MetricsWriter outputWriter = getOutputWriter(request, response, metricsService, contentType);
if (outputWriter != null) {
if (registryName != null && !registryName.isEmpty()) {
Type scope;
try {
scope = Type.valueOf(registryName.toUpperCase());
} catch (RuntimeException ex) {
throw new NoSuchRegistryException(registryName);
}
if (metricName != null && !metricName.isEmpty()) {
outputWriter.write(scope, metricName);
} else {
outputWriter.write(scope);
}
} else {
outputWriter.write();
}
}
}
} catch (NoSuchRegistryException ex) {
response.sendError(SC_NOT_FOUND, String.format("[%s] registry not found", registryName));
} catch (NoSuchMetricException ex) {
response.sendError(SC_NOT_FOUND, String.format("[%s] metric not found", metricName));
}
}
Aggregations