How to Enable SQL Insights (preview) to monitor your SQL deployments

Synopsis of this post:

  1. What is SQL Insights
  2. Take note of the current limitations of SQL Insights (preview)
  3. Pricing
  4. Regional Availability
  5. Components required for SQL Insights provisioning
    • SQL backend
    • Log Analtyics Workspace
    • Ubuntu virtual machine
    • Azure Key Vault
    • Azure SQL telegraf user*
    • SQL Monitor profile
  6. Provisioning of SQL Insights

My post presumes that you already have a backend Azure SQL database in place and that you now want to enable SQL Insights. I have written this post using Azure SQL database but Azure SQL Insights can be used on Azure SQL Managed Instance and SQL Server ( Azure SQL family).

My post describes how to enable SQL Insights (preview) to monitor your SQL deployments. SQL Monitoring is performed via an Azure Ubuntu virtual machine that makes a connection to your SQL deployments to gather monitoring data. SQL Monitoring Profiles create Data Collection Rules (DCRs) that control what datasets are collected and the frequency of collection on each dedicated vm.

1. What is SQL Insights?

SQL Insights (preview) is a comprehensive solution for monitoring any product in the Azure SQL family. SQL Insights uses dynamic management views to expose the data that you need to monitor SQL health, diagnose problems, and tune performance.

SQL Insights performs all monitoring remotely. Monitoring agents are installed on dedicated (Ubuntu) virtual machines which connect to your SQL resources via DCR deployment and remotely gather data. The gathered data is stored in destination Log Analytics Workspace/s for easy aggregation, filtering, and trend analysis

The diagram below details the flow of information from the database engine and Azure resource logs, and how they can be parsed.

2. Current Limitations of SQL Insights (preview):
  • Non-Azure instances: SQL Server running on virtual machines outside Azure is not supported.
  • Azure SQL Database elastic pools: Metrics can’t be gathered for elastic pools or for databases within elastic pools.
  • Azure SQL Database low service tiers: Metrics can’t be gathered for databases on Basic, S0, S1, and S2 service tiers.
  • Azure SQL Database serverless tier: Metrics can be gathered for databases through the serverless compute tier. However, the process of gathering metrics will reset the auto-pause delay timer, preventing the database from entering an auto-paused state.
  • Secondary replicas: Metrics can be gathered for only a single secondary replica per database. If a database has more than one secondary replica, only one can be monitored.
  • Authentication with Azure Active Directory: The only supported method of authentication for monitoring is SQL authentication. For SQL Server on Azure Virtual Machines, authentication through Active Directory on a custom domain controller is not supported.
3. Pricing

There is no cost for the SQL Insights (preview) service. All costs are incurred by the virtual machines that gather the data, and the Log Analytics workspaces that store the ingested data, as well as any alert rules configured on the data.

4. Regional availability

SQL Insights (preview) is available in all Azure regions where Azure Monitor is available, with the exception of Azure Government and national clouds.

5. Components required for SQL Insights provisioning
  • SQL backend
  • Log Analtyics Workspace
  • Ubuntu virtual machine
  • Azure Key Vault
  • Azure SQL telegraf user*
  • SQL Monitor profile
6 -Provisioning of SQL Insights

Step 1 – Provision SQL database

You may be testing the SQL Insights on an existing SQL database which means that you can skip to step 2.

If you are testing the SQL Insights and want to deploy a new test Azure SQL database in a sandbox, then follow this url and deploy, https://learn.microsoft.com/en-us/azure/azure-sql/database/single-database-create-quickstart?view=azuresql&tabs=azure-portal

I followed these parameters while deploying a single database,

Using SQL authentication (AD authentication has not yet been released),

Dont deploy a SQL elastic pool,

Deploy only a Provisioned database (serverless is not yet fully functional),

Deploy General Purpose so that the db is not low service tier,

Use a public endpoint and add your devices IP,

Allow Azure services to access the server,

I chose Connection Policy = Redirect,

In the Additional settings tab, in the Data source section, I chose Use existing data, and selected the Sample database.

When you provision your new SQL Server, use the Admin name = telegraf and pick a password you will use again later in your Key Vault secret.

Once deployed > go to your SQL database > Query editor (preview) > login with telegraf > and run the following script to make sure your table is working:

SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName
FROM SalesLT.ProductCategory pc
JOIN SalesLT.Product p
ON pc.productcategoryid = p.productcategoryid;

System Assigned Managed Identity

Once the SQL server has been deployed, go to the Identity tab and enable the System Assigned Managed Identity for this SQL Server. (This MI will be used later in the Azure Key Vault Access Policy).

Step 2 – Configure Azure SQL Database Firewall settings

Firewall Rules

SQL Insights supports accessing your Azure SQL Database via its public endpoint as well as from its virtual network.

For access via the public endpoint, you would add a rule under the Firewall settings page and the IP firewall settings section. For specifying access from a virtual network, you can set virtual network firewall rules and set the service tags required by the Azure Monitor agent.

On my Azure SQL Server I have added my client IP to the SQL server firewall rules under the Public Access Tab.

Connectivity

Microsoft recommends changing the connectivity policy to Redirect for direct connectivity to the node hosting the database. (This is optional and is what I tested).

Step 3 – Provision a destination Log Analytics Workspace

SQL Insights stores its data in a destination Log Analytics workspaces. A single workspace can be used an an endpoint for multiple monitoring profiles, but the workspace and profiles and the ubuntu server must be located in the same Azure region. To enable and access the features in SQL Insights, ensure that you have the Log Analytics contributor role.

Step 4 – Provision the Data Collector Ubuntu Azure Virtual Machine

You will need to deploy one or more Azure virtual machines onto which the agents will be installed that will be used to collect data to monitor SQL.

A SQL Monitoring profile provisions a DCR under-the-hood that you will use to configure and collect data from the different types of SQL sources that you want to monitor and as such will be linked to a DCR Resource (vm) which will be an Ubuntu virtual machine.

Each SQL Monitoring Ubuntu virtual machine can only have one dedicated monitoring profile associated with it. If you have a need to provision multiple SQL monitoring profiles, then you will need to deploy a virtual machine for each.

The Azure Ubuntu virtual machine requirements:

  • Operating system: Ubuntu 18.04 using Azure Marketplace image. Custom images are not supported.
  • Recommended minimum Azure virtual machine sizes: Standard_B2s (2 CPUs, 4-GiB memory)
  • Deployed in any Azure region supported by the Azure Monitor agent and meeting all Azure Monitor agent prerequisites.

Note: The Standard_B2s (2 CPUs, 4 GiB memory) virtual machine size will support up to 100 connection strings. You shouldn’t allocate more than 100 connections to a single virtual machine.

System Assigned Managed Identity

Once the Ubuntu server has been deployed, go to the Identity tab and enable the System Assigned Managed Identity for this virtual machine. (This MI will be used later in the Azure Key Vault Access Policy).

Enable Service Endpoint “Microsoft.Sql”

Go to the Ubuntu vm subnet and enable the Service Endpoint “Microsoft.Sql” via the Portal or via Powershell.

Register-AzResourceProvider '
-ProviderNamespace "Microsoft.Sql"

Network Security Group

Create and add a new NSG to the Ubuntu vm subnet, with a service tag which represents the SQL Azure Service. Add the tag SQL and SqlManagement

https://learn.microsoft.com/en-us/azure/virtual-network/service-tags-overview

Step 5 – Provision an Azure Key Vault

As a security best practice, Microsoft strongly recommends that you store your SQL user (login) passwords in a Key Vault, rather than entering them directly into your monitoring profile connection strings.

#register the destination subscription if not registered
Register-AzResourceProvider -ProviderNamespace "Microsoft.KeyVault"

#create the new standard Key Vault with basic configurations
$kvName = "allensKeyVault01"
$rgname = "rg-allen"
$location = "southafricanorth"
$sku = "standard"
New-AzKeyVault -Name $kvName -ResourceGroupName $rgname -Location $location -sku $sku

Now that the Key Vault is configured, we need to get the Azure SQL server System Assigned MI and the Ubuntu server System Assigned MI added to the Key Vault Access Policy.

Access Policy

On the Key Vault Access Policy the following configs are required:

#1 The Data Collector Ubuntu Azure Virtual Machine System Assigned Managed Identity must be added with Get for the Secret Permissions – based on Principle of Least Privilege.

#2 The Azure SQL Database System Assigned Managed Identity must be added with only Get, List for the Secret Permissions – based on Principle of Least Privilege.

Generate Secret

A secret needs to be generated which will contain the password for the admin account = telegraf

This secret will be referenced via the connection strings each time Insights queries the Ubuntu vm to pull SQL data.

Step 6 – Create the SQL monitoring telegraf user account

You need a SQL user (login) account on the SQL instance that you want to monitor.
The steps below cover the process per Azure SQL Database.

You may connect to an Azure SQL database with SQL Server Management Studio, Query Editor (preview) in the Azure portal, or Azure Data Studio.

I ran the following script to create a new user with the required permissions from Query Editor. Replace the value ‘user’ with a username and mystrongpassword with a strong password.

(I decided to use a super strong password for simplicity during this deployment and used the telegraf account as the instance admin account since Im using a sandbox database. You will use your bespoke admin account in place of this and grant the account VIEW DATABASE permissions. This is the only part you will need to figure out on your own as per your bespoke enviroment.)

CREATE USER [telegraf] WITH PASSWORD = N'P@ssw0rd';
GO
GRANT VIEW DATABASE STATE TO [telegraf];
GO

Verify the success of the new user creation in the Messages window: Query succeeded

I then decided to test using the Azure Data Studio, where I verify that the new user was in fact created.

I used the following script: (you dont need to edit this script, run as is)

select name as username,
       create_date,
       modify_date,
       type_desc as type,
       authentication_type_desc as authentication_type
from sys.database_principals
where type not in ('A', 'G', 'R', 'X')
       and sid is not null
order by username

Step 7.1 – Create a SQL monitoring profile

Open SQL Insights (preview) by selecting Azure portal > Azure Monitor > Insights > SQL (preview). Select Create new profile.

The profile will store the information that you want to collect from either of your SQL systems by creating a DCR. Your SQL Profile name will become the DCR name.

The profile is stored as a data collection rule resource in the subscription and resource group you select. Each profile needs the following:

Name. Cannot be edited once created.

Location. This is an Azure region.

Log Analytics workspace to store the monitoring data.

Collection settings are for the frequency and type of sql monitoring data to collect. This is where the “Data Sources” component of the DCR is provisioned.

Once you have added the destination Log Analytics Workspace then select Create Monitoring Profile > Create SQL monitoring profile

Step 7.2 – Adding a monitoring machine

Upon deployment of the SQL monitoring profile you will be met with an error message “This profile does not have any associated monitoring virtual machines..”

Select Manage Profile tab > Add monitoring machine to open a context panel to choose the virtual machine from which to monitor your SQL instances and provide the connection strings.

Editing the Connection String:

Inside the Connection string block, edit and insert your bespoke values according to:

  1. Name of the secret that you created in your key vault.
  2. The full URI of your key vault where the secret is located.
  3. Update your SQL server and SQL database values.

Thats all, then select the subscription and key vault in the drop down list below and Update Monitoring Configuration

This section will populate the the “Data Sources” component of the DCR.

Verification Checks

You can run the following SQL queries to check the validity of your account (I could not get these working on any tooling). I wasnt too worried because remember that I had created the SQL server with telegraf as the SQL Server Admin account. If this server is in production, then get your SQL guys to make the magic happen.

This verification is to check your SQL Firewalls and NSG’s have been created. We have already created all the required components above.

Step 8 – Verify Collection logs

Overview Tab

Upon completion, go to SQL Monitor > Overview Tab and verify the status of your connected database.

If you click on the database link you will find the high level view of all your connected databases.

If you click on the target database link allendb01 you will find a deep dive view of more information.

Manage Profile Tab

Upon completion, go to SQL Monitor > Manage Profile Tab and verify whether the status has changed to Collecting

Then click on Collecting to deep dive the logs.

You can select All Logs or Errors and then scope down by time.

Microsoft Reference:
https://learn.microsoft.com/en-us/azure/azure-sql/database/sql-insights-enable?view=azuresq

The intention of this post is to simplify the deployment of SQL Insights after repeated deployments.

I hope the steps above simplify your deployment.

138 comments

  1. You actuаlly make it seem so easy with y᧐ur presentation but I find this topic to be гeally something that I think
    I would neveг understand. It ѕeems too complex and
    very broad for me. I’m looking forward foг your next post, I
    wilⅼ try to get the hang of it!

  2. I’m not that much of a online reader to be һonest ƅut your blogѕ
    really niⅽe, keep it up! I’ⅼl go ahead and bookmark your site to cоme back in the future.
    Many thanks

  3. It’s гealⅼy a nice and useful piece of info.
    I’m glad that you simply shared thіs useful info with us.
    Plеase keep us up to date like this. Thank you for sharing.

  4. Ӏts like you read my mind! You appear to know a lot about this,
    like you wrote the book in it or something. I think that you could
    do with some picѕ to drіve thе mеssagе home a bit, but instead of that, this is magnificent blog.

    A fantastic rеad. I’ll definitely be back.

  5. І just like the helpful information you supply to your articles.
    I’lⅼ bookmark your blog and test once moгe here regularly.
    I’m fairly sure I’ll be informed many new stuff proρer here!
    Goօd luck for the following!

  6. Its ⅼike you read my mind! You aρpear to know a lot about thiѕ, like you
    wrote the book in it or something. I think that you could do with some
    pics to drive the message homе a little bit, but
    instead of that, this is magnificent blog. An excellent read.
    I wіll certainly be back.

  7. Hello, every time i useɗ tߋ check weblog posts here in the early
    hⲟurs in the break of day, since і enjoy to gɑin knowledցe of more and more.

  8. І was suggested this web site by my cousin. I’m not
    sure whether this post is written by him as nobody elsе know such detaiⅼed about my difficᥙlty.
    You are wonderful! Thanks!

  9. Having read this I thought it wɑs extremely enlіghtening.
    I appreciate you spending some time and effort to put
    this information toɡether. I once agaіn find myseⅼf personally sрending a lot of time both
    reading and leaving comments. But so what, it
    was still worth іt!

  10. Wow that was strange. I јust wrote an very long comment but after I clicked suƄmіt my comment didn’t appear.
    Grrrr… ԝell I’m not ѡriting alⅼ that over again. Anyhow,
    just wanted to say great blog!

  11. Οh my goodness! Impreѕsive article dսde! Thanks, However I
    am having problems with youг RSS. I don’t know why I ɑm unable to jоin it.

    Is there anybody havіng idеntical RSS issues?
    Αnyone that қnows the answer will you kindly respond?
    Thanks!!

  12. І’m not that much of a online reader to be honest but your blogs
    really nice, keep it up! I’ll go ahead and bооkmark
    your website to come back down the road. Many thanks

  13. wonderfᥙl put uρ, very informative. I’m wondering why the oppoѕite exρerts of this sector do not notice this.

    You must continue yօur writing. I’m confident, you’ve ɑ hugе readers’
    base alreaⅾy!

  14. I tһink this is among the most important information for me.
    And i am glad reading үour article. But wanna remark on some general
    things, The website style is perfect, the aгticles is really great : D.
    Good job, cһeеrs

  15. I ԝanted to thank you for this good read!! I absolutely loved every little bit of it.
    I һave you bookmarkеd to check out new stuff you poѕt…

  16. Ꮋave you ever thought about adding a little bit
    more than just your articles? I mean, wһat you say
    is valuable and everything. Neverthelesѕ
    imagine if you added some gгeat visuals or videos to give your posts more, “pop”!
    Your content is excellent but with images and vіdeos, this blog could undeniably be one of
    the very best in its niche. Great blog!

  17. Hi, Neat poѕt. There is an issue along with your website in ѡeb
    explorer, might check this? IE nonetheless iѕ the maгketplace leader and a big portion of
    other people wilⅼ miss your magnificent writing due to this
    problеm.

  18. Helⅼo excеptional website! Doeѕ running a blog
    sᥙch as this taҝe a massiѵe amount work? I’ve absolutely no knowledge of coding һowever I had been һoping to start my own blog soon.
    Anyways, if you have any suggestions ᧐r techniqueѕ foг new blog owners please share.

    I know this is off topiϲ but I simply hɑd to asк.
    Thanks a lot!

  19. Ιf you deѕiгe to increase yoᥙr know-how ϳust keep visitіng this wеbsite and be սpdated with the hottest news posted
    here.

  20. you’гe truly a good webmaster. The site loading pace is amazing.
    It sort of feels that you’re doing any distinctive trick.
    Also, The contents are masterpiece. you have рerformeԀ a wonderful task on this matter!

  21. Ⅴery nice post. I sіmply stumbled upon your weblog and wisheɗ to say that I’ve truly loved
    broѡsing your weblog posts. After all І’lⅼ
    be subscribing for your feed and I hope you write agaіn very soon!

  22. Hі i am kavin, its my first occasion to commenting anywheгe, when i read this post і thought
    i could also make comment due to this brilliant article.

  23. I was rеcommеnded this website by my cousin. I’m
    not ѕure whether this рost is written by him as nobody else know such detailed abߋut my dіffіculty.

    You are incredible! Thanks!

  24. Ꭲhanks for the good writeuⲣ. It in truth was a entertainment aϲcount it.

    Look advanced to far delivered agreeable from you! By tһe way,
    how can we keep up a correspondence?

  25. Pleaѕe lеt me know if you’rе looking for a writer foг yoᥙr site.
    You have some really good posts and I ƅelieve I would Ьe
    a gߋod asset. If you eveг want to taҝe some of the load off, I’d
    really lіke to write some content for your blog
    in exchange for a link back to mine. Pleaѕе shoot me an e-maiⅼ іf
    interesteⅾ. Many thanks!

  26. Ꮋey I know this is off topіc but I was wondering
    іf you knew of any widgеts I could add to my Ƅlօg tһat automaticаlly
    tweet my newest twitter updatеs. I’ve been looking for a plug-in like this for quite
    some tіme and was hօping maybe you would have
    some experience with something like this. Please let me
    know if you run into аnything. I truly enjoy reading your
    blog and I look forward to your new updates.

  27. Sѡeet blog! Ι fⲟund it ԝhilе surfing
    around on Yahoo Nеws. Do you have any suggestiοns on how
    to get listed in Yahoo News? I’ve been tгying for
    а while but I never seem to get there! Ϲhееrs

Leave a comment

Your email address will not be published. Required fields are marked *