org.eclipse.microprofile.metrics.annotation.Metered Java Examples

The following examples show how to use org.eclipse.microprofile.metrics.annotation.Metered. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RoomEndpoint.java    From sample-room-java with Apache License 2.0 9 votes vote down vote up
@Timed(name = "websocket_onOpen_timer",
    reusable = true,
    tags = "label=websocket")
@Counted(name = "websocket_onOpen_count",
    monotonic = true,
    reusable = true,
    tags = "label=websocket")
@Metered(name = "websocket_onOpen_meter",
    reusable = true,
    tags = "label=websocket")
@OnOpen
public void onOpen(Session session, EndpointConfig ec) {
    Log.log(Level.FINE, this, "A new connection has been made to the room.");

    // All we have to do in onOpen is send the acknowledgement
    sendMessage(session, Message.ACK_MSG);
}
 
Example #2
Source File: RoomEndpoint.java    From sample-room-java with Apache License 2.0 6 votes vote down vote up
/**
 * Simple broadcast: loop over all mentioned sessions to send the message
 * <p>
 * We are effectively always broadcasting: a player could be connected
 * to more than one device, and that could correspond to more than one connected
 * session. Allow topic filtering on the receiving side (Mediator and browser)
 * to filter out and display messages.
 *
 * @param session Target session (used to find all related sessions)
 * @param message Message to send
 * @see #sendRemoteTextMessage(Session, Message)
 */
@Timed(name = "websocket_sendMessage_timer",
    reusable = true,
    tags = "label=websocket")
@Counted(name = "websocket_sendMessage_count",
    monotonic = true,
    reusable = true,
    tags = "label=websocket")
@Metered(name = "websocket_sendMessage_meter",
    reusable = true,
    tags = "label=websocket")
public void sendMessage(Session session, Message message) {
    for (Session s : session.getOpenSessions()) {
        sendMessageToSession(s, message);
    }
}
 
Example #3
Source File: CDIAnnotationInfo.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public String name() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).name();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).name();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).name();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).name();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).name();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).name();
    } else {
        throw new IllegalArgumentException("Unknown metric annotation type " + annotation.annotationType());
    }
}
 
Example #4
Source File: CDIAnnotationInfo.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public boolean absolute() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).absolute();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).absolute();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).absolute();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).absolute();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).absolute();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).absolute();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example #5
Source File: CDIAnnotationInfo.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public String[] tags() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).tags();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).tags();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).tags();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).tags();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).tags();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).tags();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example #6
Source File: CDIAnnotationInfo.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public String unit() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).unit();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).unit();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).unit();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).unit();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).unit();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).unit();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example #7
Source File: CDIAnnotationInfo.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public String description() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).description();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).description();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).description();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).description();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).description();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).description();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example #8
Source File: CDIAnnotationInfo.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public String displayName() {
    if (annotation instanceof Counted) {
        return ((Counted) annotation).displayName();
    } else if (annotation instanceof ConcurrentGauge) {
        return ((ConcurrentGauge) annotation).displayName();
    } else if (annotation instanceof Gauge) {
        return ((Gauge) annotation).displayName();
    } else if (annotation instanceof Metered) {
        return ((Metered) annotation).displayName();
    } else if (annotation instanceof Timed) {
        return ((Timed) annotation).displayName();
    } else if (annotation instanceof SimplyTimed) {
        return ((SimplyTimed) annotation).displayName();
    } else {
        throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
    }
}
 
Example #9
Source File: RoomEndpoint.java    From sample-room-java with Apache License 2.0 6 votes vote down vote up
@Timed(name = "websocket_onError_timer",
    reusable = true,
    tags = "label=websocket")
@Counted(name = "websocket_onError_count",
    monotonic = true,
    reusable = true,
    tags = "label=websocket")
@Metered(name = "websocket_onError_meter",
    reusable = true,
    tags = "label=websocket")
@OnError
public void onError(Session session, Throwable t) {
    Log.log(Level.FINE, this, "A problem occurred on connection", t);

    // TODO: Careful with what might revealed about implementation details!!
    // We're opting for making debug easy..
    tryToClose(session,
            new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION,
                    trimReason(t.getClass().getName())));
}
 
Example #10
Source File: WeatherService.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Path("/week/status")
@Metered(name = "weeklyStatus", unit = MetricUnits.MINUTES, description = "Metrics to weekly weather status method", absolute = true)
@GET
@Produces(MediaType.TEXT_PLAIN)
public String weekStatus() {
    return "Hi, week will be mostly sunny!";
}
 
Example #11
Source File: RestHandler.java    From Hands-On-Enterprise-Java-Microservices-with-Eclipse-MicroProfile with MIT License 5 votes vote down vote up
@GET
@Counted(name="aCounter", monotonic = true, absolute = true)
@Metered(name="aMeter", absolute = true)
@Timed(  name="aTimer", absolute = true)
public String triggerAllMetrics() {

  justACounter.inc(2);

  return "Yo!";

}
 
Example #12
Source File: RoomEndpoint.java    From sample-room-java with Apache License 2.0 5 votes vote down vote up
@Timed(name = "websocket_onClose_timer",
    reusable = true,
    tags = "label=websocket")
@Counted(name = "websocket_onClose_count",
    monotonic = true,
    reusable = true,
    tags = "label=websocket")
@Metered(name = "websocket_onClose_meter",
    reusable = true,
    tags = "label=websocket")
@OnClose
public void onClose(Session session, CloseReason r) {
    Log.log(Level.FINE, this, "A connection to the room has been closed with reason " + r);
}
 
Example #13
Source File: MultipleMetricsMethodBean.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Counted(name = "counter")
@Gauge(name = "gauge", unit = MetricUnits.NONE)
@Metered(name = "meter")
@Timed(name = "timer")
public Long metricsMethod() {
    return 1234L;
}
 
Example #14
Source File: MpMetricsResource.java    From javaee8-cookbook with Apache License 2.0 5 votes vote down vote up
@Metered(name = "getResourceMetered")
@Path("/metered")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getResourceMetered() {
    String response = getResource();

    return JSON.createObjectBuilder()
            .add("message", response)
            .build();
}
 
Example #15
Source File: QuotesResource.java    From blog-tutorials with MIT License 5 votes vote down vote up
@GET
@Metered
@Produces(MediaType.APPLICATION_JSON)
public Response getQuoteOfTheDay() {

  JsonObject quoteOfTheDay = quotesClient.getQuoteOfTheDay();
  JsonPointer quotePointer = Json.createPointer("/contents/quotes/0/quote");
  JsonObject result = Json.createObjectBuilder()
    .add("quoteOfTheDay", quotePointer.getValue(quoteOfTheDay)).build();

  return Response.ok(result).build();
}
 
Example #16
Source File: RoomEndpoint.java    From sample-room-java with Apache License 2.0 5 votes vote down vote up
/**
 * The hook into the interesting room stuff.
 * @param session
 * @param message
 * @throws IOException
 */
@Timed(name = "websocket_onMessage_timer",
    reusable = true,
    tags = "label=websocket")
@Counted(name = "websocket_onMessage_count",
    monotonic = true,
    reusable = true,
    tags = "label=websocket")
@Metered(name = "websocket_onMessage_meter",
    reusable = true,
    tags = "label=websocket")
@OnMessage
public void receiveMessage(Session session, Message message) throws IOException {
    roomImplementation.handleMessage(session, message, this);
}
 
Example #17
Source File: MetricCdiInjectionExtension.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
private <X> void findAnnotatedInterfaces(@Observes @WithAnnotations({ Counted.class, Gauge.class, Metered.class,
        SimplyTimed.class, Timed.class, ConcurrentGauge.class }) ProcessAnnotatedType<X> pat) {
    Class<X> clazz = pat.getAnnotatedType().getJavaClass();
    Package pack = clazz.getPackage();
    if (pack != null && pack.getName().equals(GaugeRegistrationInterceptor.class.getPackage().getName())) {
        return;
    }
    if (clazz.isInterface()) {
        // All declared metrics of an annotated interface are registered during AfterDeploymentValidation
        metricsInterfaces.add(clazz);
    }
}
 
Example #18
Source File: WeatherService.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Path("/day/status")

    @Metered(name = "dailyStatus", unit = MetricUnits.MINUTES, description = "Metrics to daily weather status method", absolute = true)
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String dayStatus() {
        return "Hi, today is a sunny day!";
    }
 
Example #19
Source File: BookStoreEndpoint.java    From ebook-Building-an-API-Backend-with-MicroProfile with Apache License 2.0 5 votes vote down vote up
@Metered(name = "create-books",
        unit = MetricUnits.MILLISECONDS,
        description = "Monitor the rate events occured",
        absolute = true)
@POST
public Response create(Book book) {
    bookService.create(book);
    return Response.ok().build();
}
 
Example #20
Source File: DefaultNameMetricMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Metered
public void defaultNameMeteredMethod() {
}
 
Example #21
Source File: GameRoundWebsocket.java    From liberty-bikes with Eclipse Public License 1.0 4 votes vote down vote up
@OnMessage
@Metered(name = "rate_of_websocket_calls",
         displayName = "Rate of GameRound Websocket Calls",
         description = "Rate of incoming messages to the game round websocket",
         absolute = true)
public void onMessage(@PathParam("roundId") final String roundId, String message, Session session) {
    try {
        final InboundMessage msg = jsonb.fromJson(message, InboundMessage.class);
        final GameRound round = gameSvc.getRound(roundId);
        if (round == null || round.getGameState() == State.FINISHED) {
            log(roundId, "[onMessage] Received message for round that did not exist or has completed.  Closing this websocket connection.");
            if (round == null)
                closeWithError(session, roundId, "Round " + roundId + " did not exist.");
            // don't boot out players that may keep sending messages a few seconds after the game is done
            else if (!round.isPlayer(session))
                closeWithError(session, roundId, "Round " + roundId + " has already completed.");
            return;
        }
        //log(roundId, "[onMessage] msg=" + message);

        if (GameEvent.GAME_START == msg.event) {
            round.startGame();
        } else if (msg.direction != null) {
            boolean updated = round.updatePlayerDirection(session, msg);
            if (!updated)
                closeWithError(session, roundId, "Unable to update direction because client was not joined to round");
        } else if (msg.playerJoinedId != null && !msg.playerJoinedId.isEmpty()) {
            // Call playerserver for player in DB
            org.libertybikes.restclient.Player playerResponse = getPlayer(msg.playerJoinedId);
            if (playerResponse == null)
                closeWithError(session, roundId, "Unable to add player " + msg.playerJoinedId +
                                                 " to game. This is probably because the player has not been registered yet");
            else if (!round.addPlayer(session, msg.playerJoinedId, playerResponse.name, msg.hasGameBoard == null ? true : msg.hasGameBoard))
                closeWithError(session, roundId, "Unable to add player " + playerResponse.name
                                                 + " to game. This is probably because someone else with the same id is already in the game.");
        } else if (Boolean.TRUE == msg.isSpectator) {
            round.addSpectator(session);
        } else {
            closeWithError(session, roundId, jsonb.toJson(msg));
        }
    } catch (Exception e) {
        log(roundId, "ERR: " + e.getMessage());
        e.printStackTrace();
    }
}
 
Example #22
Source File: MeteredTagMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Metered(name = "meteredMethod", tags= {"number=two"})
public void meteredMethodTwo() {
}
 
Example #23
Source File: MeteredTagMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Metered(name = "meteredMethod", tags= {"number=one"})
public void meteredMethodOne() {
}
 
Example #24
Source File: MeteredMethodBean1.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Metered(name = "meteredMethod")
public void meteredMethod() {
}
 
Example #25
Source File: MeteredConstructorBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Metered(name = "meteredConstructor", absolute = true)
public MeteredConstructorBean() {
}
 
Example #26
Source File: MultipleMetricsConstructorBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Counted(name = "counter")
@Metered(name = "meter")
@Timed(name = "timer")
public MultipleMetricsConstructorBean() {
}
 
Example #27
Source File: DefaultNameMetricMethodBean.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Metered(absolute = true)
public void absoluteDefaultNameMeteredMethod() {
}
 
Example #28
Source File: MeteredMethodBean2.java    From microprofile-metrics with Apache License 2.0 4 votes vote down vote up
@Metered(name = "meteredMethod")
public void meteredMethod() {
}
 
Example #29
Source File: MetricsResource.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/meter")
@Metered(name = "meter")
public String meter() {
    return "OK";
}
 
Example #30
Source File: MetricResolver.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
public Of<Metered> metered(BeanInfo topClass, MemberInfo element) {
    return resolverOf(topClass, element, Metered.class);
}