If you are a developer, or DBA who manages Microsoft SQL Servers, it becames important to understand current load vs usual load when SQL Server is slow. This repository contains scripts that will help you to setup baseline on individual SQL Server instances, and then visualize the collected data using Grafana through one Inventory server with Linked Server for individual SQL Server instances.
Navigation
- Sample Live Grafana Dashboards
- Portal Credentials
- How to Setup
You can visit http://ajaydwivedi.ddns.net:3000 for live dashboard for basic real time monitoring.
Visit http://ajaydwivedi.ddns.net:3000 for live dashboard of all Perfmon counters suggested in SQL Server Perfmon Counters of Interest - Quest Software.
| Database/Grafana Portal | User Name | Password |
|---|---|---|
| http://ajaydwivedi.ddns.net:3000/ | guest | ajaydwivedi-guest |
| Sql Instance -> ajaydwivedi.ddns.net:1433 | grafana | grafana |
Setup of baselining & visualization is divided into 2 parts:-
- Part 01 - Setup Baselining of SqlServer
- Part 02 - Configure Grafana for Visualization on baselined data
-
Create [DBA] database using below script. Make sure to change the data and log files path in above script before execution. Ideally, you want to put each filegroup file in separate disk.
-
Download/Copy below files from path NonSql-Files to local directory where perfmon data collector files will be generated. Say, E:\Perfmon\ on SQL Server box. This directory should have at least 4 gb of size.
- DBA_PerfMon_NonSQL_Collector_Template.xml
- perfmon-collector-logman.ps1
- perfmon-collector-push-to-sqlserver.ps1
- perfmon-remove-imported-files.ps1
-
Create required objects in sequential order of scripts as mentioned below:-
-
Create WhoIsActive capturing using below script. Avoid running commented code that creates agent job.
-
Prepare perfmon data collection:-
- Setup Perfmon data collector using downloaded script perfmon-collector-logman.ps1. Make sure to open script and change value for variable $collector_root_directory as per Step 2). Save it.
# Original line in script $collector_root_directory = 'D:\MSSQL15.MSSQLSERVER\MSSQL\Perfmon'; # Update line as per need $collector_root_directory = 'E:\Perfmon';
- Create ODBC Data Source for SqlInstance. This should be done only once for each Windows Server box. In case of multiple SQL Server instances, choose one instance as ODBC destination.
# create dsn for Sql Server instance 'localhost' with windows authentication and default to [DBA] database Add-OdbcDsn -Name "LocalSqlServer" -DriverName "SQL Server" -DsnType "System" -SetPropertyValue @("Server=localhost", "Trusted_Connection=Yes", "Database=DBA")- Push Perform data collector data to SqlServer using relog & dsn.
-
Setup Default Mail profile
-
Create database login/user [grafana] for executing queries from Grafana portal. This user needs [db_datareader] on [DBA], and VIEW SERVER STATE permissions.
-
IMPORTANT: In case of multiple SqlInstances installed on same server, Perfmon collector data should be imported into one instance only.
For example, on SQL Server box 'SQL-A.Lab.com', I have one named instance 'SQL-A\V17' installed along side with default instance 'SQL-A'. So I import the Perfmon collector data into default instance 'SQL-A', and read same data on named instance using views created with help of Linked server of default instance.
Execute below script on NAMED instance to create these views required to read data:-
NOTE:- Make sure to create linked server for main instance in named instance, and replace the linked server name in above script code before executing.
-
Execute below script to Create Sql Agent jobs that Collect/Purge performance data. Jobs have default schedule of every 10 seconds.
This will create sql agent jobs with name like '(dba) Collect Metrics - ******'
Make sure jobs [(dba) Collect Metrics - NonSqlServer Perfmon Counters] & [(dba) Collect Metrics - Purge Perfmon Files] execute successfully. These jobs may require script path change to point to directory set in step 2, & 5.a.
This completes part 01 of setting up baselining for SQL Server
For Grafana, I am using one SqlInstance as my Inventory (central) server. What this mean is, on this server, I'll create linked servers for all the server that required monitoring using Grafana.
-
Setup Inventory server. Select one server as Inventory. Create linked Server for each instance that require monitoring through Grafana on your central server using 'Microsoft OLEDB Provider for SQL Server'. Here make sure to utilize readonly sql authenticated login [grafana] we created in part 01 step 7.
-
On grafana portal, create data source named 'Inventory' with details of above step, and [grafana] login.
-
Finally, Create dashboards by importing below *.json files
This should create the grafana dashboard according to settings of above json files.
Thanks 😃. Subscribe for updates 👍
