Skip to content

SQL Server over WinRM (win_sqlserver) ​

Reads the default instance of Microsoft SQL Server over WinRM from the engine's own performance counters: whether the service runs, how much work it is doing, whether its memory is keeping up, whether queries are deadlocking or blocked, and whether the databases you expect are online. It needs no login to the database engine, no password for SQL Server and no open SQL port: the account only has to be allowed to read performance counters on the machine.

Transport. Under a Windows probe the device can be set to read this sensor over native WMI instead of WinRM; the queries and the result are the same. The target is then set up as in the WMI setup guide instead.

What it looks like ​

The page of a win_sqlserver sensor in the light theme

The sensor's page after a few polls, watching SQL Server on a Windows Server domain controller reached over WinRM. In the dark theme: the sensor's page. The form for adding it, with its parameters filled in: light, dark.

Channels ​

KeyNameUnitDefault limits
service_stateService (MSSQLSERVER)Running is Up, Stopped is Down, anything else is Warning
batch_requests_psBatch requestsreq/snone
connectionsUser connectionsnone
buffer_cache_hit_pctBuffer cache hit ratio%warning below 90, error below 80
page_life_expectancy_sPage life expectancyswarning below 300
deadlocks_psDeadlocks/swarning above 0
blocked_processesBlocked processesnone
databasesDatabases onlinenone
databases_missingExpected databases not onlineerror above 0

The state channel uses the same numbers and labels as win_service.

Parameters ​

ParameterDefaultMeaning
databasesnoneNames of databases that must be online (up to 100). A name that is missing from the engine's counters raises databases_missing and is named in the message. Case does not matter.
port5985, or 5986 with httpsTCP port of the WinRM listener.
httpsfalseUse the HTTPS listener instead of HTTP with message encryption.
accept_self_signedfalseAccept an HTTPS certificate that cannot be verified. The credential has the same switch; either one is enough.

Suggested interval: 60 seconds. Credential: Windows. Discovery proposes one on a host whose MSSQLSERVER service is installed and set to start automatically. Only the default instance is read.

Why these channels ​

  • Batch requests per second is the engine's own measure of how much work arrives, and the first number to look at when everything is slow. It is a cumulative counter, so it is the difference between two polls over the time between them on the target's clock (how rates are worked out).
  • User connections is the count of logins in use now.
  • Buffer cache hit ratio is the share of page requests served from memory. It is read as the fraction the counter holds (its value over its base), not as a difference between polls. It is a weak signal on its own, and a healthy server sits near 100, so the limits are loose: warning below 90, error below 80.
  • Page life expectancy is how many seconds a page stays in memory untouched. A server short of memory throws pages out quickly and this falls. The old rule of 300 seconds is the warning limit because it is still the floor below which something is wrong on any size of server; a machine with a lot of memory should have much more, and its limits can be raised.
  • Deadlocks per second is a rate between two polls, so a deadlock shows for the poll interval in which it happened. Any deadlock is a warning: it is rare in a well-written application and worth a look.
  • Blocked processes is how many sessions wait on a lock held by another. It is a gauge, and a brief nonzero value is normal, so it has no limit.
  • Databases online counts the databases in the engine's counters except the hidden resource database.

What the counters cannot say about a database ​

The performance counters have one instance for each database that is online. Taking a database offline makes its instance disappear, which was seen on the lab server, so a database you listed in databases and that is missing is reported. A database in any other state (restoring, recovering, suspect, emergency) keeps its instance, so the sensor cannot tell it from a healthy one. Reading sys.databases.state_desc needs a login to the engine and an SQL query, which is what a database query sensor does; use one for it.

While the service is stopped ​

No counters exist while the service is stopped. The poll then reports the service state alone, as Down, and leaves everything else unknown.

On the target ​

WinRM enabled and an account set up as in the WinRM setup guide, including membership of Performance Monitor Users. Nothing is needed in SQL Server.

If the sensor fails with an SQL Server counter class has no instance, WMI has the classes but lists no instances in them, because it built its list of counters before SQL Server was installed. Restart the Windows Management Instrumentation service on the target (Restart-Service Winmgmt -Force) or run winmgmt /resyncperf. This was seen on the lab server.

A named instance has its own service (MSSQL$NAME) and its own counter classes, and is not read: the sensor fails with no default instance of SQL Server is installed (a named instance is not read by this sensor).

Failures ​

The WinRM failures every Windows sensor shares are listed in the setup guide. Specific to this sensor:

MessageMeaning
there is no service MSSQLSERVER on the target (kind config)No default instance.
an SQL Server counter class has no instance (kind protocol)See above: restart WMI.
the WMI class does not exist (kind config)The counter classes of SQL Server are not registered, which can follow a repair of the performance counter library (lodctr /R and winmgmt /resyncperf).

Verification ​

Checked against WS-Man responses recorded from a real Windows Server 2022 domain controller running SQL Server 2022 Developer (default instance, the system databases only), read about eight seconds apart for the rates, and against that machine live over NTLM with message encryption. The server was idle between the readings, so the recorded rates are zero; the rate arithmetic, the two clocks it uses and the thresholds are tested with counters written in the test. An offline database was made on the lab server and its counter instance was seen to disappear, while one in the emergency state kept it; the test for a missing database uses an answer taken from the recording. Not seen: a busy server, a deadlock, blocking, user databases, named instances, clusters and availability groups, a server with more than one buffer pool node, and native WMI over DCOM.

Live tests: PROBEWARD_TEST_WINRM_HOST, _USER and _PASSWORD as for the other Windows sensors, and PROBEWARD_TEST_WINRM_ROLES containing sql to say the machine runs a default SQL Server instance.

AGPL-3.0-only