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

P21 - Monitor SQL Server 2022 with PRTG (Setup & SQL Service Sensors)

PRTG P21 – How to Monitor SQL Server 2022 with PRTG (Setup & SQL Service Sensors)

In production environments, SQL Server is one of the most critical infrastructure components. If SQL stops running, applications fail immediately — from ERP systems to internal tools like Snipe-IT.

In this tutorial, you will learn how to properly Monitor SQL Server 2022 with PRTG, including:

  • Creating a secure monitoring login

  • Granting minimum required permissions

  • Monitoring SQL services using SSH Script Advanced

  • Detecting SQL Agent failures

  • Setting proper alert thresholds

The goal is simple: detect SQL service failures before users report system downtime.


🛠 Step 1 – Create Monitoring User for SQL Server

We will create a dedicated monitoring account with minimum privileges.

Create Admin User for Initial Configuration

SQL Server admin:

  • User: admin_sql

  • Pass: Abc@1234


View SQL Version

 
 
sqlcmd -S localhost -U admin_sql -P ‘Abc@1234’ -C

SELECT @@VERSION;
GO
 

Create Monitoring Login

 
💻
filename.bash
sqlcmd -S localhost -U admin_sql -P 'Abc@1234' -C
SELECT @@VERSION;
GO

USE master;
GO
CREATE LOGIN prtg_sql WITH PASSWORD = 'StrongPassword!';
GRANT VIEW SERVER STATE TO prtg_sql;
GRANT VIEW ANY DATABASE TO prtg_sql;
GO

This configuration is enough to:

• Read performance
• Do not destroy DB
• VIEW SERVER STATE → enough for all databases

The monitoring account cannot modify or delete databases, ensuring security.


🖥 Step 2 – Add Device in PRTG and Configure Credentials

Add the SQL Server host into PRTG.


Enable SSH

Make sure SSH is enabled on the SQL Server host (Linux-based SQL Server).

PRTG will use SSH Script Advanced to monitor services.


Enable SQL Credential

Inside PRTG device settings:

  • User: prtg_sql

  • Pass: StrongPassword!

This allows PRTG to query SQL performance safely.


📡 Step 3 – Add Sensors

We now configure service monitoring.


🟢 #1 SQL Service Monitoring

👉 Use SSH Script Advanced

Monitor services:

• MSSQLSERVER: mssql-server
• SQLSERVERAGENT (if using job /backup): mssql-server-agent


📌 Why This Is Critical

• SQL fails → Snipe-IT crashes
• SQL Agent fails → backup doesn’t run

Monitoring both services ensures:

  • Database availability

  • Scheduled job execution

  • Backup integrity


Command to Check Service Status

 
 
systemctl is-active mssql-server
systemctl is-active mssql-server-agent
 

🧩 Step 1 – Create the Monitoring Script

Create a folder for PRTG scripts:

 
 
sudo mkdir -p /var/prtg/scriptsxml
 

Create the script file:

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

Script Content

💻
filename.bash
#!/bin/bash

FAILED=0
FAILED_LIST=""

# Default values
SQL_STATUS=1
AGENT_STATUS=2   # 2 = not installed

# Check SQL Server
if systemctl list-unit-files | grep -q "^mssql-server"; then
  if systemctl is-active --quiet mssql-server; then
    SQL_STATUS=0
  else
    SQL_STATUS=1
    FAILED=$((FAILED+1))
    FAILED_LIST="$FAILED_LIST mssql-server"
  fi
else
  SQL_STATUS=2
fi

# Check SQL Server Agent
if systemctl list-unit-files | grep -q "^mssql-server-agent"; then
  if systemctl is-active --quiet mssql-server-agent; then
    AGENT_STATUS=0
  else
    AGENT_STATUS=1
    FAILED=$((FAILED+1))
    FAILED_LIST="$FAILED_LIST mssql-server-agent"
  fi
else
  AGENT_STATUS=2
fi

# Message
if [ "$FAILED" -eq 0 ]; then
  MSG="SQL services are running"
else
  MSG="Service down:$FAILED_LIST"
fi

cat <<EOF
<prtg>
  <result>
    <channel>SQL Server Service</channel>
    <value>$SQL_STATUS</value>
    <unit>Custom</unit>
    <valuelookup>prtg.standardlookups.yesno.stateyesok</valuelookup>
  </result>

  <result>
    <channel>SQL Server Agent</channel>
    <value>$AGENT_STATUS</value>
    <unit>Custom</unit>
    <valuelookup>prtg.standardlookups.yesno.stateyesok</valuelookup>
  </result>

  <text>$MSG</text>
</prtg>
EOF

exit 0

🔐 Access Control and Testing

Grant execution permission:

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

Test manually:

 
 
sudo /var/prtg/scriptsxml/check_mssql_services.sh
 

🔍 Meaning of Each Channel

ChannelValueMeaning
SQL Server Service0OK
SQL Server Service1DOWN
SQL Server Agent0OK
SQL Server Agent1DOWN
SQL Server Agent2Agent does not exist

This logic ensures accurate monitoring without false alarms.


🖥 Step 2 – Add Sensor in PRTG

Add a new sensor:

  • Type: SSH Script Advanced

  • Script: check_mssql_services.sh

PRTG will automatically read XML output and create channels.


🚨 Step 3 – Set Alarm Threshold

Configure alert thresholds carefully.

If SQL Agent is enabled:

  • Set threshold to trigger when value > 0.5

If SQL Agent is not enabled and not monitored:

  • Set threshold to 3

This prevents unnecessary alerts in environments without SQL Agent.


🎯 Why This Monitoring Design Works

When you properly Monitor SQL Server, you must detect:

  • SQL service failure

  • Agent failure

  • Backup interruption

  • Application crash risk

This approach provides:

  • Lightweight monitoring

  • Clear service state visibility

  • Immediate failure detection

  • Minimal resource usage

Instead of monitoring every internal metric, this focuses on what truly matters: service availability.


🚀 Final Thoughts

To effectively Monitor SQL Server 2022 with PRTG, you need:

  • Secure monitoring login

  • Minimum required permissions

  • SSH Script Advanced service monitoring

  • Proper threshold configuration

With this setup, your SQL Server monitoring becomes:

  • Secure

  • Efficient

  • Production-ready

  • Enterprise-grade

You now have a reliable method to detect SQL service failures before they impact your applications.

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