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?

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.