Skip to content

Instantly share code, notes, and snippets.

@FSou1
Last active January 13, 2017 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FSou1/c6f61a9c0591e0ff59826b92485c2d95 to your computer and use it in GitHub Desktop.
Save FSou1/c6f61a9c0591e0ff59826b92485c2d95 to your computer and use it in GitHub Desktop.
Simple uptime monitoring owin's middleware (just for catching "<url>/uptime" requests)
public static class HttpPropertyKeys
{
public static readonly string UptimeMiddlewarePath = "/uptime";
}
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