-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5d9b7b
commit a836b2e
Showing
8 changed files
with
79 additions
and
31 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
31 changes: 15 additions & 16 deletions
31
mangooio-core/src/main/java/io/mangoo/routing/listeners/MetricsListener.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 |
---|---|---|
@@ -1,35 +1,34 @@ | ||
package io.mangoo.routing.listeners; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
|
||
import io.mangoo.core.Application; | ||
import io.mangoo.models.Metrics; | ||
import io.undertow.server.ExchangeCompletionListener; | ||
import io.undertow.server.HttpServerExchange; | ||
import io.undertow.server.ResponseCommitListener; | ||
|
||
/** | ||
* Listener that is invoked for counting metrics of HTTP response codes | ||
* | ||
* @author Kubiak | ||
* | ||
* @author svenkubiak | ||
* | ||
*/ | ||
@Singleton | ||
public class MetricsListener implements ResponseCommitListener { | ||
private final Metrics metrics; | ||
public class MetricsListener implements ExchangeCompletionListener { | ||
private long start; | ||
|
||
@Inject | ||
public MetricsListener(Metrics metrics) { | ||
this.metrics = Objects.requireNonNull(metrics, "metrics can not be null"); | ||
public MetricsListener(long start) { | ||
this.start = start; | ||
} | ||
|
||
@Override | ||
public void beforeCommit(HttpServerExchange exchange) { | ||
public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) { | ||
Metrics metrics = Application.getInstance(Metrics.class); | ||
metrics.update((int) (System.currentTimeMillis() - this.start)); | ||
|
||
String uri = Optional.ofNullable(exchange.getRequestURI()).orElse("").replace("/", "").toLowerCase(); | ||
if (!uri.contains("@admin")) { | ||
this.metrics.inc(exchange.getStatusCode()); | ||
metrics.inc(exchange.getStatusCode()); | ||
} | ||
|
||
nextListener.proceed(); | ||
} | ||
} |
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