1

I have a function that gets the statues of my databases and Redis instances to check that they are online:

 internal static bool IsOnline(ConnectionLocator connectionLocator)
 {
 try
 {
 connectionLocator.SessionDatabase.Ping(StackExchange.Redis.CommandFlags.None);
 using (var connect = connectionLocator.OpenSqlConnection())
 {
 var command = connect.CreateCommand();
 command.CommandText = "select 1";
 command.ExecuteScalar();
 }
 }
 }
 catch
 {
 return false;
 }
 return true;
 }

This is used to display a system status to the consumers of my application.

Currently, I have it in the MVC controller it is called from, but I don't think that is quite right.

However, it doesn't seem appropriate to put this in a repository either; I am asking about data access, NOT trying to abstract the data access details away from an entity.

Is anyone aware of patterns, or best case practices for this kind of systems interrogation code?

asked Feb 28, 2018 at 18:17
0

1 Answer 1

2

Monitoring is part of your problem domain. The routine you've shown is part of your business logic. If we use an MVC architecture, this wouldn't be part of the view nor part of the controller because it doesn't react to user input. It would be part of your model, in its widest sense.

How you structure your model/business logic is up to you. You are right that this check sits at the boundary of your system, but doesn't really belong into a repository either. I would consider an independent service that regularly schedules a check. Other parts of the system can then subscribe to this service to receive updates when the status changes (e.g. display a notification on a monitoring dashboard).

answered Mar 2, 2018 at 21:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.