A light-weight framework for creating an application to monitor your systems. You to write checks for your systems in C#, and the framework takes care of (nearly all) the rest.
You are looking at a very early version of this codebase. Even though we are dogfooding this code, please consider it as pre-alpha code at this moment.
There's a plethora of monitoring and alerting tools (both commercial and open source) out there already: Nagios, Bosun, ElasticSearch Marvel, and many, many more. So why create a new one?
Nimator is meant to be a light-weight framework for creating small monitoring tools, where you can write the code for checking parts of your system using C# (or VB.NET, if that's your thing). It is not meant to be competitive with the bigger, fully-fledged tools: if you have a large organization you're probably better off with one of the alternatives. However, if you are a small .NET shop, fluent in C#, and want to write a few system-monitoring checks in your favorite language: Nimator might be useful to you.
We mostly wrote this because we needed it ourselves (so you can count on this code being run in production in at least one place). We open sourced it because it's not so much our core business, and it might be of use to someone else too.
So, want to write a few lines of C# to periodically monitor your systems, and not have to worry about aggregating, exception handling, distribution, etc? Read on!
Additional documentation is a work in progress, to be found in the wiki. But you can also read on here, with the Getting Started section.
- Create a new Console Application project
- Run
Install-Package Nimator
in the Package Manager Console - Copy the contents of the example
class Program {...}
over your blankProgram
- Create an file
config.json
next toProgram.cs
- Set
config.json
to be an embedded resource - Copy the contents of the example
config.json
into that file - Either configure
log4net
analogous to the exampleApp.config
, or comment out theConfigure()
call. - Compile and run!
You should now see something along these lines:
Creating Nimator. Nimator created. Starting timer for cycle every 15 seconds. Press any key to exit. ERROR between 21:25:56.114 and 21:25:56.140 (on 2016-09-26) Failure in [Demo Layer 2], checks [AlwaysError]. - Warning: after running 2 check(s) in Demo Layer 1 - - Okay in AlwaysOkay: no details provided - - Warning in AlwaysWarning: no details provided - Error: after running 1 check(s) in Demo Layer 2 - - Error in AlwaysError: no details provided
Congratulations! You've successfully run a meaningless moninitoring cycle!
Writing checks is quite easy. You have to do three things to get up and running:
-
Create an instance of
ICheck
. Here's a trivial example:class ImportantFileCheck : ICheck { private readonly string folder; public string ShortName { get; } = nameof(ImportantFileCheck); public ImportantFileCheck(string folder) { this.folder = folder; } public Task<ICheckResult> RunAsync() { var level = File.Exists($"{folder}/important-file-{DateTime.Now.ToString("yyyy-MM-dd")}.txt") ? NotificationLevel.Okay : NotificationLevel.Error; return Task.FromResult<ICheckResult>(new CheckResult(ShortName, level)); } }
Note that even though the
ICheck
interface asks you to try and beasync
, you can just as well return synchronously withTask.FromResult<T>(...)
. -
Create a corresponding instance of
ICheckSettings
:class ImportantFileCheckSettings : ICheckSettings { public string Folder { get; set; } public ICheck ToCheck() { return new ImportantFileCheck(Folder); } }
-
Add configuration for your check to the
config.json
file (to any of theChecks
arrays in a layer):{ "$type": "ConsoleApplication1.ImportantFileCheckSettings, ConsoleApplication1", "Folder": "c:/some/important/folder/" }
Note that you should replace
ConsoleApplication1
with your application's Namespace.
That's it! If you now run the application again, the check will periodically look if the important log file is available on disk.
Okay, the above example is moderately useful at best. But you can do better. Here's a few ideas to get you started with other checks:
- Ping a certain host to see if it's available
- Try to do a
WebRequest
or two to check up on your application - Run a query in your database to check for simple anomalies
- Query your logs for recent spikes in errors, etc.
Careful: the most interesting checks are often the ones that would fail on a timeout. Be sure to set a proper timeout when using third party libraries (e.g. a Connection Timeout when querying your database) and fail your ICheck
on a timeout.
Nimator is listed on NuGet as a package. Again, note that this is a very early version, use at your own risk.
Install-Package Nimator
The above command will get you the latest version. Please note that we will not move to SemVer until a "version 1" has crystallized, and until then any new package versions might include breaking changes.
Code in this repository is available under the MIT license, except when explicitly noted otherwise (e.g. when the source code includes a method that has a comment linking to Stack Overflow source post, which entails CC-BY-SA 3.0 with attribution required).
If you have an issue (bug, feature request, etc), please report it on GitHub. If you have a question about this project or its use, please contact the main committer on nimator-at-jeroenheijmans-dot-nl or via Twitter @jeroenheijmans.