TSF – Giải pháp IT toàn diện cho doanh nghiệp SMB | HCM

P22 - Monitor Performance SQL Server 2022 and Disk Space with PRTG

PRTG P22 – How to Monitor SQL Server 2022 Performance and Disk Space with PRTG

Monitoring service status is not enough in production. A running SQL Server does not always mean a healthy SQL Server.

In this tutorial, you will learn how to properly Monitor Performance SQL Server 2022 using PRTG, focusing on:

  • Critical performance counters

  • SQL internal health indicators

  • Disk capacity monitoring for MDF, LDF, and backup files

  • Intelligent alert configuration

This is the advanced layer of SQL monitoring — the part that detects performance degradation before system failure happens.


🧠 2#. SQL Performance Monitoring

Sensor Type: SSH Script Advanced

Select the most important counters:

• Database size
• Transactions/sec
• Batch Requests/sec
• Buffer Cache Hit Ratio
• Page Life Expectancy (PLE)
• Lock Waits
• Deadlocks/sec

📌 This is the “brain” sensor of SQL monitoring.

It tells you whether SQL Server is under stress, memory pressure, or experiencing locking problems.


🛠 Step 1 – Create the Performance Script

First, identify the location of the sqlcmd binary:

 
 
which sqlcmd
 

Copy the returned path and paste it into the script below.


🔐 Step 2 – Re-assign Permissions to prtg_sql User

Create the script file:

 
 
sudo nano /var/prtg/scriptsxml/sql_perfomence.sh
 

Script Content

 
💻
filename.bash
#!/bin/bash

SQLCMD="/opt/mssql-tools18/bin/sqlcmd"
USER="prtg_sql"
PASS="StrongPassword!"
SERVER="localhost"

RESULT=$($SQLCMD -S "$SERVER" -U "$USER" -P "$PASS" -C \
-h -1 -W -s "|" -Q "
SET NOCOUNT ON;

SELECT
  /* Total DB Size (MB) – per current DB */
  (SELECT SUM(size)*8/1024 FROM sys.database_files),

  /* Transactions/sec (_Total) */
  (SELECT cntr_value
   FROM sys.dm_os_performance_counters
   WHERE counter_name='Transactions/sec'
     AND instance_name='_Total'),

  /* Batch Requests/sec */
  (SELECT SUM(cntr_value)
   FROM sys.dm_os_performance_counters
   WHERE counter_name='Batch Requests/sec'),

  /* Buffer Cache Hit Ratio (%) */
  (
    SELECT
      CAST(
        100.0 *
        MAX(CASE WHEN counter_name='Buffer cache hit ratio' THEN cntr_value END) /
        NULLIF(MAX(CASE WHEN counter_name='Buffer cache hit ratio base' THEN cntr_value END),0)
      AS DECIMAL(5,2))
    FROM sys.dm_os_performance_counters
  ),

  /* Page Life Expectancy – instance rỗng */
  (SELECT cntr_value
   FROM sys.dm_os_performance_counters
   WHERE counter_name='Page life expectancy'
     AND instance_name=''),

  /* Lock Waits/sec */
  (SELECT COALESCE(SUM(cntr_value),0)
   FROM sys.dm_os_performance_counters
   WHERE counter_name='Lock Waits/sec'),

  /* Deadlocks/sec */
  (SELECT COALESCE(SUM(cntr_value),0)
   FROM sys.dm_os_performance_counters
   WHERE counter_name='Number of Deadlocks/sec');
")

IFS='|' read DBSIZE TRANS BATCH BCHR PLE LOCK DEAD <<< "$RESULT"

echo "<prtg>"

echo "<result>
  <channel>Total DB Size</channel>
  <value>${DBSIZE:-0}</value>
  <unit>MegaByte</unit>
</result>"

echo "<result>
  <channel>Transactions</channel>
  <value>${TRANS:-0}</value>
  <unit>Count</unit>
  <mode>Rate</mode>
</result>"

echo "<result>
  <channel>Batch Requests</channel>
  <value>${BATCH:-0}</value>
  <unit>Count</unit>
  <mode>Rate</mode>
</result>"

echo "<result>
  <channel>Buffer Cache Hit</channel>
  <value>${BCHR:-0}</value>
  <unit>Percent</unit>
  <float>1</float> 
</result>"

echo "<result>
  <channel>Page Life Expectancy</channel>
  <value>${PLE:-0}</value>
  <unit>Seconds</unit>
</result>"

echo "<result>
  <channel>Lock Waits</channel>
  <value>${LOCK:-0}</value>
  <unit>Count</unit>
  <mode>Rate</mode>
</result>"

echo "<result>
  <channel>Deadlocks</channel>
  <value>${DEAD:-0}</value>
  <unit>Count</unit>
  <mode>Rate</mode>
</result>"

echo "<text>SQL Performance OK</text>"
echo "</prtg>"

🔧 Delegation and Enforcement

Grant execute permission:

 
 
sudo chmod +x /var/prtg/scriptsxml/sql_perfomence.sh
 

Test the script manually:

 
 
sudo /var/prtg/scriptsxml/sql_perfomence.sh
 

If XML output appears correctly, the script is ready for PRTG.


📡 Step 2 – Add Sensor in PRTG

Add a new sensor:

  • Type: SSH Script Advanced

  • Script: sql_perfomence.sh

PRTG will automatically detect all channels from the XML output.


🚨 Step 3 – Set Alert Thresholds

Not all counters require strict thresholds.

Total DB Size (MB)

DO NOT SET threshold.
Used for observation and growth tracking only.


Transactions/sec

DO NOT SET threshold.
Value depends entirely on workload. Use trend comparison over time.


Batch Requests/sec

DO NOT SET threshold.
Used for workload monitoring.


Buffer Cache Hit %

📌 Healthy SQL is usually ≥ 98%

If consistently below 95%, memory pressure may exist.


Page Life Expectancy (PLE)

Low PLE indicates memory stress.
Watch for sudden drops rather than fixed values.


Lock Waits/sec

High values indicate blocking or poor indexing.


Deadlocks/sec

Deadlock ≠ always failure.
Only trigger alerts when deadlocks occur continuously.


💾 3#. Disk Capacity (Extremely Sensitive for SQL)

SQL Server is extremely sensitive to disk exhaustion.

Sensor Type: SSH Disk Free v2

Monitor disks containing:

 Data files (.mdf)
 Log files (.ldf)
 Backup directory

If disk becomes full:

  • SQL may stop writing

  • Transactions may fail

  • Log file growth may freeze


🛠 Step 1 – Add Disk Sensor

Add SSH Disk Free v2 sensor to the SQL Server host.

Select the correct mount point where SQL data is stored.


🚨 Step 2 – Add Alarm Threshold

Recommended configuration:

  • Warning at 20% free

  • Critical at 10% free

Disk monitoring is often more important than performance counters because a full disk causes immediate service impact.


🎯 Why Performance Monitoring Matters

When you Monitor Performance SQL Server, you are not just checking uptime.

You are monitoring:

  • Memory health

  • Transaction workload

  • Concurrency pressure

  • Lock contention

  • Storage capacity

This layered approach ensures:

  • Early detection of performance degradation

  • Prevention of unexpected downtime

  • Long-term capacity planning

  • Stable production systems


🚀 Final Thoughts

To properly Monitor Performance SQL Server 2022 with PRTG, combine:

  • Advanced performance counters

  • Service monitoring

  • Intelligent threshold configuration

  • Disk capacity tracking

This creates a complete monitoring architecture:

  • Service layer

  • Performance layer

  • Storage layer

With this setup, your SQL Server monitoring becomes proactive instead of reactive — detecting issues before users even notice them.

See also related articles

P3 – Powerful Guide 2026 Monitor WAN IP with PRTG

P3 – Powerful Guide 2026 Monitor WAN IP with PRTG PRTG – P3 Monitor Internet & WAN IP Using PRTG Network Monitor Monitoring your Internet connection is critical for any business infrastructure. If your WAN connection goes down, services such as email, VPN, remote access, and cloud applications become unavailable...

Read More

P2 – Secure PRTG Fast: Change Port PRTG & Enable SSL

P2 – Secure PRTG Fast: Change Port PRTG & Enable SSL PRTG – P2 Secure PRTG with SSL | Enable HTTPS & Change Default Port Securing your monitoring system is not optional — it is essential. In this guide, we will walk through how to secure PRTG Network Monitor by...

Read More

P1 – Complete Install PRTG Guide for Windows 10

PRTG – P1 How to Install PRTG on Windows 10 | Initial Setup & Configuration 🚀 Install PRTG on Windows 10 – Initial Setup & Configuration (P1) If you are starting your monitoring journey, learning how to Install PRTG properly is the first critical step. In this tutorial, I will...

Read More