Monitor your Azure SQL Database performance with database metrics, query analysis, and system health data using the New Relic Distribution of OpenTelemetry (NRDOT) collector on Linux.
팁
To run the collector on Windows, refer to Azure SQL Database on Windows.
Prerequisites
- A New Relic account with a valid license key.
- Network connectivity to the New Relic OTLP endpoint for your region.
- Azure SQL Database requirements:
- An Azure SQL logical server and database.
- The server admin login and password (or another account that can create logins and manage server roles in
master). - Network access from the collector host to the server on port
1433, through a server firewall rule, a virtual network rule, or a private endpoint. If the server uses a private endpoint, the server name must resolve to the private IP address from the collector host.
- Collector host requirements: a host (for example, an Azure VM) with the
sqlcmdutility installed.
Install NRDOT Collector
Install the NRDOT Collector on a host that can reach your Azure SQL server.
For Debian/Ubuntu on AMD64:
$NRDOT_VERSION=$(curl -s https://api.github.com/repos/newrelic/nrdot-collector-releases/releases/latest | grep '"tag_name":' | awk -F'"' '{print $4}') && curl -L "https://github.com/newrelic/nrdot-collector-releases/releases/download/${NRDOT_VERSION}/nrdot-collector_${NRDOT_VERSION}_linux_amd64.deb" --output nrdot-collector.deb && sudo dpkg -i nrdot-collector.debFor other distributions and architectures, refer to the Linux RDS installation step and the nrdot-collector-releases page.
Create monitoring user and grant permissions
Azure SQL Database doesn't allow GRANT VIEW SERVER STATE and similar instance-level grants. Instead, you add the login to built-in server roles in master, then create a user in each database you want to monitor.
Create a file named
nr-grant-permission-master.sqland replace<YOUR_PASSWORD>with your desired password:CREATE LOGIN [newrelic] WITH PASSWORD = '<YOUR_PASSWORD>';GOALTER SERVER ROLE [##MS_ServerStateReader##] ADD MEMBER [newrelic];ALTER SERVER ROLE [##MS_DefinitionReader##] ADD MEMBER [newrelic];ALTER SERVER ROLE [##MS_DatabaseConnector##] ADD MEMBER [newrelic];GORun it against the
masterdatabase as the server admin. Replace<YOUR-SERVER>with your server name (for example,myserver.database.windows.net):bash$sqlcmd -S <YOUR-SERVER> -d master -U <YOUR_ADMIN_USER> -P '<YOUR_ADMIN_PASSWORD>' -C -i nr-grant-permission-master.sqlCreate a file named
nr-grant-permission-db.sql:CREATE USER [newrelic] FOR LOGIN [newrelic];GOGRANT VIEW DATABASE STATE TO [newrelic];GORun it against each database you want to monitor. Replace
<YOUR_DATABASE>with the database name:bash$sqlcmd -S <YOUR-SERVER> -d <YOUR_DATABASE> -U <YOUR_ADMIN_USER> -P '<YOUR_ADMIN_PASSWORD>' -C -i nr-grant-permission-db.sqlThe following table shows why each role is needed:
Role or permission Used for ##MS_ServerStateReader##Server-level dynamic management views, such as sys.dm_exec_query_statsandsys.dm_exec_procedure_stats##MS_DefinitionReader##Resolving object and schema names for top procedures and index statistics ##MS_DatabaseConnector##Connecting to databases to collect index physical statistics VIEW DATABASE STATEDatabase-scoped dynamic management views, such as sys.dm_db_resource_stats(Optional) Verify the server roles from the
masterdatabase:bash$sqlcmd -S <YOUR-SERVER> -d master -U <YOUR_ADMIN_USER> -P '<YOUR_ADMIN_PASSWORD>' -C -Q "SELECT r.name AS [Role], l.name AS [Login] FROM sys.server_role_members rm JOIN sys.server_principals r ON rm.role_principal_id = r.principal_id JOIN sys.sql_logins l ON rm.member_principal_id = l.principal_id WHERE l.name = 'newrelic';"The output lists all three roles.
(Optional) Verify the database permissions by connecting as the monitoring user:
bash$sqlcmd -S <YOUR-SERVER> -d <YOUR_DATABASE> -U newrelic -P '<YOUR_PASSWORD>' -C -Q "SELECT TOP 1 * FROM sys.dm_db_resource_stats; SELECT TOP 1 * FROM sys.dm_exec_query_stats;"A permission error means a grant is missing.
팁
To securely manage sensitive information, such as database credentials, store them in secret management tools.
Configure NRDOT Collector
Create the configuration file:
bash$sudo nano /etc/nrdot-collector/mssql-config.yamlAdd the following configuration. Replace
<YOUR_PASSWORD>,<YOUR-SERVER>,<YOUR_DATABASE>,<YOUR_LICENSE_KEY>, and the OTLP endpoint with your values:receivers:nrsqlserver:collection_interval: 15s# datasource replaces username, password, server, and port.datasource: "sqlserver://newrelic:<YOUR_PASSWORD>@<YOUR-SERVER>:1433?database=<YOUR_DATABASE>"metrics:sqlserver.database.io:enabled: truesqlserver.database.latency:enabled: truesqlserver.database.operations:enabled: truesqlserver.database.tempdb.space:enabled: truesqlserver.database.tempdb.version_store.size:enabled: truesqlserver.deadlock.rate:enabled: truesqlserver.os.wait.duration:enabled: truesqlserver.processes.blocked:enabled: truesqlserver.memory.grants.pending.count:enabled: truesqlserver.database.file.size:enabled: truesqlserver.memory.area:enabled: trueevents:db.server.query_sample:enabled: truedb.server.top_query:enabled: truedb.server.query_plan:enabled: truedb.server.top_procedure:enabled: truetop_query_collection:lookback_time: 60smax_query_sample_count: 1000top_query_count: 250collection_interval: 60scollect_full_query_text: trueallowed_comment_keys:- nr_service_guidquery_sample_collection:max_rows_per_query: 100collect_full_query_text: trueallowed_comment_keys:- nr_service_guidtop_procedure_collection:max_procedure_sample_count: 1000top_procedure_count: 250collection_interval: 60sresource_attributes:db.system.version:enabled: truesqlserver.db.edition:enabled: trueprocessors:memory_limiter:check_interval: ${env:NR_MEM_LIMITER_CHECK_INTERVAL:-1s}limit_mib: ${env:NR_MEM_LIMITER_LIMIT_MIB:-200}spike_limit_mib: ${env:NR_MEM_LIMITER_SPIKE_MIB:-50}exporters:otlp:endpoint: https://otlp.nr-data.net:4318headers:api-key: <YOUR_LICENSE_KEY>tls:insecure: falsecompression: gzipsending_queue:enabled: truesizer: bytesqueue_size: 100_000_000num_consumers: 10batch:sizer: bytesmax_size: 1_000_000min_size: 0flush_timeout: 5sservice:telemetry:metrics:level: nonepipelines:metrics:receivers: [nrsqlserver]processors: [memory_limiter]exporters: [otlp]logs:receivers: [nrsqlserver]processors: [memory_limiter]exporters: [otlp]
팁
- The
datasourcevalue is a connection URL. If your password contains characters other than letters, digits, and- . _ ~ ! $ * + ,, URL-encode them. - The collector connects to the single database named in
database=. To monitor several databases on the same server, use a separate receiver for each, as described in Multi-receiver configuration. - Always-On, failover-cluster, and some latch and tempdb metrics aren't available on Azure SQL Database and return no data.
- The
logspipeline carries SQL Server query telemetry (query text, execution plans, and samples), not collector debug logs.
Update NRDOT Collector configuration
Edit the service configuration file:
bash$sudo nano /etc/nrdot-collector/nrdot-collector.confPoint the configuration path to your new file:
bash$OTELCOL_CONFIG="/etc/nrdot-collector/mssql-config.yaml"(Optional) Validate the configuration:
bash$sudo /usr/bin/nrdot-collector validate --config=/etc/nrdot-collector/mssql-config.yaml
Restart NRDOT Collector
$sudo systemctl restart nrdot-collectorCheck the collector log for permission or connection errors:
$sudo journalctl -u nrdot-collector -n 50 --no-pagerFind and use your data
- Go to one.newrelic.com > All capabilities > Databases.
- From the Entity type dropdown, select MSSQL instance, then click Apply.
- Select your Azure SQL Database from the list of entities.