Simple uptime monitoring owin's middleware (just for catching "<url>/uptime" requests)
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
public static class HttpPropertyKeys | |
{ | |
public static readonly string UptimeMiddlewarePath = "/uptime"; | |
} |
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
public class UptimeMonitoringMiddleware | |
{ | |
public UptimeMonitoringMiddleware( | |
Func<IDictionary<string, object>, Task> next, string path) | |
{ | |
_next = next; | |
_path = path; | |
} | |
public async Task Invoke(IDictionary<string, object> environment) | |
{ | |
var context = new OwinContext(environment); | |
if (context.Request.Path == PathString.FromUriComponent(_path ?? HttpPropertyKeys.UptimeMiddlewarePath)) | |
{ | |
await context.Response.WriteAsync("Uptime status: OK"); | |
return; | |
} | |
await _next(environment); | |
} | |
private readonly Func<IDictionary<string, object>, Task> _next; | |
private readonly string _path; | |
} | |
public static class UptimeMiddlewareExtension | |
{ | |
public static IAppBuilder UseUptimeMonitoringMiddleware(this IAppBuilder app, string path = null) | |
{ | |
app.Use(typeof(UptimeMonitoringMiddleware), path); | |
return app; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment