diff --git a/README.md b/README.md index 9366eb9..8861628 100644 --- a/README.md +++ b/README.md @@ -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 | \ No newline at end of file diff --git a/src/prometheus-net.IdentityServer/Sinks/PrometheusEventsSink.cs b/src/prometheus-net.IdentityServer/Sinks/PrometheusEventsSink.cs index be26867..bcba0e9 100644 --- a/src/prometheus-net.IdentityServer/Sinks/PrometheusEventsSink.cs +++ b/src/prometheus-net.IdentityServer/Sinks/PrometheusEventsSink.cs @@ -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.", @@ -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."); @@ -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; @@ -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;