EKG - Fixing Sitecore's Heartbeat


There are many mechanisms for monitoring the health of Sitecore, but Heartbeat.aspx is the simplest. It is easy to monitor with third party tools and requires no knowledge of technological underpinnings. With the release of Sitecore 9, however, things have gotten a bit more complicated. Heartbeat checks every database, even unused ones. this can lead to false negatives and problems monitoring site health in different environments. Fortunately, there is a solution!

Sitecore allows you to specify a list of excluded connections, so you can check only the required databases for a given environment. However, Sitecore does not provide a simple tool to get the status of every connection. Enter EKG: A tool that checks every connection, shows you the status of each database, and provides a pre-formatted Sitecore.Services.Heartbeat.ExcludeConnection config section to paste into a patch file in your App_Config.

 First, lets look at the important parts of the code. This is implemented as a legacy Forms page but should be easy enough to follow if you have only had exposure to MVC. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Loop through all of the Sitecore connection strings. 
foreach (ConnectionStringSettings connectionString in ConfigurationManager.ConnectionStrings)
{
    try
    {
        using (SqlConnection connection = new SqlConnection(connectionString.ConnectionString))
        {
            SqlCommand sqlCommand1 = new SqlCommand("select * from sys.tables where 1=2", connection);
            sqlCommand1.CommandTimeout = 1;
            using (SqlCommand sqlCommand2 = sqlCommand1)
            {
                connection.Open();
                sqlCommand2.ExecuteNonQuery();
                connectionStatus.Add(connectionString.Name, true);
            }
        }
    }
    catch
    {
        connectionStatus.Add(connectionString.Name, false);
    }
}

This code iterates through the available connection strings, checks each one, and returns a database status report:

In addition, it returns a formatted XML section that can be placed into a patch file in your App_Config folder to exclude the failing databases from the Heartbeat check:

1
2
3
<settings>
<setting name="Sitecore.Services.Heartbeat.ExcludeConnection" value="LocalSqlServer|sessions|xconnect.collection|xconnect.collection.certificate|xdb.marketingautomation.operations.client| xdb.marketingautomation.operations.client.certificate|xdb.marketingautomation.reporting.client| xdb.marketingautomation.reporting.client.certificate|xdb.referencedata.client|xdb.referencedata.client.certificate| solr.search|PackageManagementServiceUrl|EXM.CryptographicKey|EXM.AuthenticationKey" />
settings>

 

There are a couple of caveats:

  1. This will need to be set for each environment.
  2. You need some understanding of what each database does, and whether it is supposed to be excluded.
  3. You will need to remember to change the Exclude Connection config if you make any changes to your environment. Failing to do so will give you false positives.

You can download the EKG.aspx source code here. It should be placed in the /sitecore/service folder. 

SEARCH ARTICLES

CATEGORIES

Sitecore 146
Commerce 100
Web Development 100
Sitecore Commerce 83
Sitecore Experience Commerce 9 64
Sitecore Experience Commerce 59
Content Management 55
eCommerce 48
B2B eCommerce 42
Sitecore Experience Platform 41
Sitecore Platinum Partner 39
Architecture 34
Insite 29
User Experience 26
Strategy 22
B2B Commerce Blogs 21
B2C eCommerce 21
commerceconnect 21
CloudCraze 20
SaaS (Software as a Service) 20
Cloud 17
Commerce Server 17
Salesforce B2B Commerce Cloud 16
Mobile 13
Search 13
Analytics 12
Application Development 12
Plugins 12
Digital Transformation 11
Sitecore Symposium 11
SPEAK 10
Helix 10
DMS 8
Social 8
Business Process 7
Authentication 7
5 Reasons 7
BI and Big Data 6
Data Visualization 6
Sitecore Presentation 6
Coveo 6
NET Development 5
Microsoft Azure 5
Automation 5
Front-End Development 4
SaaS (Software as a Service) 4
Digital Strategy 4
Brightcove 4
Press Release 4
Identity 3
Avalara Tax 3
Sitecore Experience Accelerator (SXA) 3
Sitecore Layouts 3
Video 3
SPE 3
Multi-site 3
Multi-lingual 3
Accessibility 3
Habitat 3
Vault 3
Managed Services 2
CDN 2
SMB 2
Cryptocurrency 2
Sitecore Forms 2
Sitecore Experience Commerce 9 Promotions 2
Uncategorized 2
EXM 2
Conversational Commerce 2
Sitecore SaaS 2
Security 2
Unit Testing 2
Headless Architecture 2
Sitecore Experience Awards 2
Content Delivery Network 1
Configure Price Quote 1
CPQ 1
Blockchain 1
Coupons 1
Sitecore Rss 1
Google 1
Artificial Intelligence 1
Machine Learning 1
Okta 1
RFP Process 1
NoSQL 1
Flex Accelerator for Sitecore 1
Reviews 1
SEO 1
Page Labels 1