{"id":20668690,"url":"https://github.com/greentube/monitoring","last_synced_at":"2026-03-07T00:30:57.837Z","repository":{"id":22425828,"uuid":"96214147","full_name":"Greentube/monitoring","owner":"Greentube","description":"Generic API health check and monitoring","archived":false,"fork":false,"pushed_at":"2022-12-08T08:57:00.000Z","size":150,"stargazers_count":16,"open_issues_count":3,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-08-08T14:52:20.667Z","etag":null,"topics":["activemq","asp-net-core","health-check","middleware","mongodb","redis","sql-server"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Greentube.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-04T12:09:47.000Z","updated_at":"2025-05-08T20:37:13.000Z","dependencies_parsed_at":"2022-09-20T17:50:41.059Z","dependency_job_id":null,"html_url":"https://github.com/Greentube/monitoring","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Greentube/monitoring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmonitoring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmonitoring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmonitoring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmonitoring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Greentube","download_url":"https://codeload.github.com/Greentube/monitoring/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmonitoring/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270385016,"owners_count":24574537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activemq","asp-net-core","health-check","middleware","mongodb","redis","sql-server"],"created_at":"2024-11-16T20:10:53.446Z","updated_at":"2026-03-07T00:30:57.774Z","avatar_url":"https://github.com/Greentube.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Greentube.Monitoring [![Build Status](https://travis-ci.org/Greentube/monitoring.svg?branch=master)](https://travis-ci.org/Greentube/monitoring) [![Build status](https://ci.appveyor.com/api/projects/status/42eufhcmhwslimn5/branch/master?svg=true)](https://ci.appveyor.com/project/Greentube/monitoring/branch/master) [![codecov](https://codecov.io/gh/Greentube/monitoring/branch/master/graph/badge.svg)](https://codecov.io/gh/Greentube/monitoring)\n\nGreentube.Monitoring is a library that simplifies monitoring dependencies that affect your application's availability.\n\nIt allows you to add one or more _resource monitors_  and verify with a single call if any _critical_ resource is down, which in turn reports your application as unavailable.\n\nWith a few lines of code you get a health check endpoint to reply to a load balancer or a monitoring tool that your application is ready to take work load or not.\n\nMonitors can be simple delegates or one of the supported:\n\n* Redis\n* MongoDB\n* HTTP\n* SQL Server\n* ActiveMQ\n\nExample for monitoring both Redis and MongoDB:\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddMonitoring(options =\u003e {\n        options.AddRedisMonitor();\n        options.AddMongoDbMonitor();\n    });\n}\n```\nOr your own resource monitor:\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddMonitoring(provider =\u003e {\n        var dep = provider.GetRequiredService\u003cIMyServiceMonitor\u003e();\n        dep.StartMonitor();\n    });\n}\n```\nWith the ASP.NET Core Health Check middleware, the state can be reported like:\n```csharp\npublic void Configure(IApplicationBuilder app){\n    app.UseHealthEndpoint()\n}\n```\nVerifying the state of your service:\n```console\n$ curl -D - http://localhost:5000/health\nHTTP/1.1 200 OK\nDate: Mon, 12 Jun 2017 13:37:35 GMT\nContent-Length: 11\nContent-Type: application/json\nServer: Kestrel\n\n{\"Up\":true}\n```\nOr when a _critical_ resource is down:\n```console\n$ curl -D - http://localhost:5000/health\nHTTP/1.1 503 Service Unavailable\nDate: Mon, 12 Jun 2017 13:40:42 GMT\nContent-Length: 12\nContent-Type: application/json\nServer: Kestrel\n\n{\"Up\":false}\n```\n\nEach of those monitors is a separate NuGet package (pay for play). If you don't want use the ASP.NET Core middleware but want to use MVC to report the state in a different way:\n\n```csharp\n[Route(\"health\")]\npublic class HealthController : Controller\n{\n    private readonly IResourceStateCollector _collector;\n\n    public HealthController(IResourceStateCollector collector)\n    {\n        _collector = collector;\n    }\n\n    [HttpGet]\n    public IEnumerable\u003cobject\u003e AllResourceStates()\n    {\n        return from rm in _collector.GetStates()\n               select new\n               {\n                   rm.ResourceMonitor.ResourceName,\n                   rm.IsUp\n               };\n    }\n\n    [HttpGet]\n    [Route(\"non-critical/name\")]\n    public IEnumerable\u003cstring\u003e NonCriticalResourcesName()\n    {\n        return from rm in _collector.GetStates()\n               where !rm.ResourceMonitor.IsCritical\n               select rm.ResourceMonitor.ResourceName;\n    }\n}\n```\n\nUsually you would like to provide the possibility of application graceful shutdown\n\nThat means that application should stop receiving requests while trying to complete running requests.\n\nFor that you need to tell load balancer to take out the node\n\nYou need to call `Shutdown` method on `ILoadBalancerStatusProvider` \n\nTypical code can look like that (example is from hosting ASP.NET MVC Core application in Windows service)\n```csharp\n    public class GSSService : WebHostService\n    {\n        private readonly INrgsLogger _logger;\n        private readonly ILoadBalancerStatusProvider _loadBalancerStatusProvider;\n\n        public GSSService(IWebHost host) : base(host)\n        {\n            _logger = host.Services.GetRequiredService\u003cINrgsLogger\u003e();\n            _loadBalancerStatusProvider = host.Services.GetRequiredService\u003cStartup.ILoadBalancerStatusProvider\u003e();\n        }\n\n        protected override void OnStopping()\n        {\n            _loadBalancerStatusProvider.Shutdown \n            Thread.Sleep(30000); // waiting for LB to pickup the change\n\n            _logger.Information(LogCategory.ApplicationLifecycleLog, \"OnStopping method called.\");\n            base.OnStopping();\n        }\n    }\n\n```\n\nFor a logging, standard ILogger\u003cT\u003e is used implicitly via DI, so for example HttpMonitoringLogger will use \nILogger\u003cHttpResourceMonitor\u003e. \n\nMostly used log level is Information (or Trace for debug), but for *Monitor it's a special case:\nif *Monitor is Down and it is critical then level is ERROR, for non-critical is WARNING.\n\n# License\n\nLicensed under MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreentube%2Fmonitoring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreentube%2Fmonitoring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreentube%2Fmonitoring/lists"}