forked from eclipse-ee4j/jersey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
- Loading branch information
Showing
6 changed files
with
83 additions
and
57 deletions.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
...es/micrometer/src/main/java/org/glassfish/jersey/examples/micrometer/SummaryResource.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,73 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Distribution License v. 1.0, which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
package org.glassfish.jersey.examples.micrometer; | ||
|
||
import io.micrometer.core.instrument.Meter; | ||
import io.micrometer.core.instrument.Timer; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Path("summary") | ||
public class SummaryResource { | ||
|
||
private final MetricsStore store; | ||
|
||
public SummaryResource(MetricsStore store) { | ||
this.store = store; | ||
} | ||
|
||
@GET | ||
@Produces("text/html") | ||
public String getExtendedMeters() { | ||
final StringBuffer result = new StringBuffer(); | ||
try { | ||
result.append("<html><body>" | ||
+ "Listing available meters<br/>Many occurrences of the same name means that there are more meters" | ||
+ " which could be used with different tags," | ||
+ " but this is actually a challenge to handle all available metrics :<br/> "); | ||
for (final Meter meter : store.getRegistry().getMeters()) { | ||
result.append(meter.getId().getName()); | ||
result.append(";<br/>\n\r "); | ||
} | ||
} catch (Exception ex) { | ||
result.append("Looks like there are no proper metrics.<br/>"); | ||
result.append("\n\r"); | ||
result.append("Please visit /measure/timed first <br/>"); | ||
result.append(ex); | ||
} | ||
if (store.getRegistry().getMeters().size() > 0) { | ||
try { | ||
final Timer timer = store.getRegistry().get("http.shared.metrics") | ||
.tags("method", "GET", "status", "200", "exception", "None", "outcome", "SUCCESS", "uri", "/micro/init") | ||
.timer(); | ||
|
||
result.append(String.format("Counts to the init page: %d, time spent on requests to the init " | ||
+ "page (millis): %f <br/>\n\r", | ||
timer.count(), timer.totalTime(TimeUnit.MILLISECONDS))); | ||
|
||
final Timer annotatedTimer = store.getRegistry().timer(MeasuredTimedResource.TIMER_NAME, | ||
"method", "GET", "status", "200", "exception", "None", | ||
"outcome", "SUCCESS", "uri", "/micro/measure/timed"); | ||
|
||
result.append(String.format("Requests to 'measure/timed' counts: %d, total time (millis): %f <br/>\n\r", | ||
annotatedTimer.count(), annotatedTimer.totalTime(TimeUnit.MILLISECONDS))); | ||
|
||
} catch (Exception ex) { | ||
result.append("Exception occurred, more info is in console...<br/>"); | ||
result.append(ex); | ||
} | ||
} | ||
return result.append("</body></html>").toString(); | ||
} | ||
} |
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