Skip to content

Commit

Permalink
Merge pull request #5 from alexvaluyskiy/feature/new_identity_server_…
Browse files Browse the repository at this point in the history
…metrics

New IdentityServer metrics
  • Loading branch information
alexvaluyskiy authored Jan 13, 2020
2 parents 0690bbd + 782343b commit 2f7cf23
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,46 @@ public class Startup
| grpc_client_requests_errors_total | Counter | Total GRPC requests sent errors |

### Identity Server

```powershell
dotnet add package prometheus-net.IdentityServer
```

And then start the collectors:
```csharp
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseSuccessEvents = true;
});

services.AddPrometheusIdentityServerMetrics();
}
}
```

| Name | Type | Description |
|--|--|--|
| idsrv_api_authentication_failure_total | Counter | Gets raised for successful API authentication at the introspection endpoint |
| idsrv_api_authentication_failure_total | Counter | Gets raised for failed API authentication at the introspection endpoint |
| idsrv_client_authentication_success_total | Counter | Gets raised for successful client authentication at the token endpoint |
| idsrv_client_authentication_failure_total | Counter | Gets raised for failed client authentication at the token endpoint |
| idsrv_token_issued_success_total | Counter | Gets raised for successful attempts to request access tokens |
| idsrv_token_issued_failure_total | Counter | Gets raised for failed attempts to request access tokens |
| idsrv_token_introspection_success_total | Counter | Gets raised for successful attempts to request identity tokens, access tokens, refresh tokens and authorization codes |
| idsrv_token_introspection_failure_total | Counter | Gets raised for failed attempts to request identity tokens, access tokens, refresh tokens and authorization codes |
| idsrv_token_revoked_success_total | Counter | Gets raised for successful token revocation requests. |
| idsrv_user_login_success_total | Counter | Gets raised by the UI for successful user logins |
| idsrv_user_login_failure_total | Counter | Gets raised by the UI for failed user logins |
| idsrv_user_logout_success_total | Counter | Gets raised for successful logout requests |
| idsrv_consent_granted_total | Counter | Gets raised in the consent UI |
| idsrv_consent_denied_total | Counter | Gets raised in the consent UI |
| idsrv_unhandled_exceptions_total | Counter | Gets raised for unhandled exceptions |
| idsrv_device_authorization_success_total | Counter | Gets raised for successful device authorization requests |
| idsrv_device_authorization_success_total | Counter | Gets raised for failed device authorization requests |
72 changes: 72 additions & 0 deletions src/prometheus-net.IdentityServer/Sinks/PrometheusEventsSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ namespace Prometheus.IdentityServer.Sinks
{
public class PrometheusEventsSink : IEventSink
{
private static readonly Counter ApiAuthenticationSuccessCount = Metrics.CreateCounter(
"idsrv_api_authentication_failure_total",
"Gets raised for successful API authentication at the introspection endpoint.",
new CounterConfiguration { LabelNames = new[] { "client" } });

private static readonly Counter ApiAuthenticationFailureCount = Metrics.CreateCounter(
"idsrv_api_authentication_failure_total",
"Gets raised for failed API authentication at the introspection endpoint.",
new CounterConfiguration { LabelNames = new[] { "client" } });

private static readonly Counter ClientAuthenticationSuccessCount = Metrics.CreateCounter(
"idsrv_client_authentication_success_total",
"Gets raised for successful client authentication at the token endpoint.",
Expand All @@ -26,6 +36,18 @@ public class PrometheusEventsSink : IEventSink
"Gets raised for failed attempts to request access tokens.",
new CounterConfiguration { LabelNames = new[] { "flow", "error" } });

private static readonly Counter TokenIntrospectionSuccessCount = Metrics.CreateCounter(
"idsrv_token_introspection_success_total",
"Gets raised for successful attempts to request identity tokens, access tokens, refresh tokens and authorization codes.");

private static readonly Counter TokenIntrospectionFailureCount = Metrics.CreateCounter(
"idsrv_token_introspection_failure_total",
"Gets raised for failed attempts to request identity tokens, access tokens, refresh tokens and authorization codes.");

private static readonly Counter TokenRevokedSuccessCount = Metrics.CreateCounter(
"idsrv_token_revoked_success_total",
"Gets raised for successful token revocation requests.");

private static readonly Counter UserLoginSuccessCount = Metrics.CreateCounter(
"idsrv_user_login_success_total",
"Gets raised by the UI for successful user logins.");
Expand All @@ -34,14 +56,40 @@ public class PrometheusEventsSink : IEventSink
"idsrv_user_login_failure_total",
"Gets raised by the UI for failed user logins.");

private static readonly Counter UserLogoutSuccessCount = Metrics.CreateCounter(
"idsrv_user_logout_success_total",
"Gets raised for successful logout requests.");

private static readonly Counter ConsentGrantedCount = Metrics.CreateCounter(
"idsrv_consent_granted_total",
"Gets raised in the consent UI.");

private static readonly Counter ConsentDeniedCount = Metrics.CreateCounter(
"idsrv_consent_denied_total",
"Gets raised in the consent UI.");

private static readonly Counter UnhandledExceptionCount = Metrics.CreateCounter(
"idsrv_unhandled_exceptions_total",
"Gets raised for unhandled exceptions.");

private static readonly Counter DeviceAuthorizationSuccessCount = Metrics.CreateCounter(
"idsrv_device_authorization_success_total",
"Gets raised for successful device authorization requests.");

private static readonly Counter DeviceAuthorizationFailureCount = Metrics.CreateCounter(
"idsrv_device_authorization_success_total",
"Gets raised for failed device authorization requests.");

public Task PersistAsync(Event evt)
{
switch (evt)
{
case ApiAuthenticationFailureEvent _:
ApiAuthenticationSuccessCount.Inc();
break;
case ApiAuthenticationSuccessEvent _:
ApiAuthenticationFailureCount.Inc();
break;
case ClientAuthenticationSuccessEvent clientAuthSuccess:
ClientAuthenticationSuccessCount.WithLabels(clientAuthSuccess.ClientId).Inc();
break;
Expand All @@ -54,15 +102,39 @@ public Task PersistAsync(Event evt)
case TokenIssuedFailureEvent tokenIssuedFailure:
TokenIssuedFailureCount.WithLabels(tokenIssuedFailure.GrantType, tokenIssuedFailure.Error).Inc();
break;
case TokenIntrospectionSuccessEvent _:
TokenIntrospectionSuccessCount.Inc();
break;
case TokenIntrospectionFailureEvent _:
TokenIntrospectionFailureCount.Inc();
break;
case TokenRevokedSuccessEvent _:
TokenRevokedSuccessCount.Inc();
break;
case UserLoginSuccessEvent _:
UserLoginSuccessCount.Inc();
break;
case UserLoginFailureEvent _:
UserLoginFailureCount.Inc();
break;
case UserLogoutSuccessEvent _:
UserLogoutSuccessCount.Inc();
break;
case ConsentGrantedEvent _:
ConsentGrantedCount.Inc();
break;
case ConsentDeniedEvent _:
ConsentDeniedCount.Inc();
break;
case UnhandledExceptionEvent _:
UnhandledExceptionCount.Inc();
break;
case DeviceAuthorizationSuccessEvent _:
DeviceAuthorizationSuccessCount.Inc();
break;
case DeviceAuthorizationFailureEvent _:
DeviceAuthorizationFailureCount.Inc();
break;
}

return Task.CompletedTask;
Expand Down

0 comments on commit 2f7cf23

Please sign in to comment.