You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is caused by the database_id column in sys.databases becoming out of sync with DB_ID() within Azure SQL.
Expected behavior:
This query from code line referenced above should return the property information for the server.
SELECT TOP(1)
(SELECTcount(*) FROMsys.dm_os_schedulersWHERE status ='VISIBLE ONLINE') AS cpu_count,
(SELECT process_memory_limit_mb FROMsys.dm_os_job_object) AS server_memory,
slo.editionas sku,
cast(SERVERPROPERTY('EngineEdition') assmallint) AS engine_edition,
slo.service_objectiveAS hardware_type,
cast(DATABASEPROPERTYEX(DB_NAME(),'MaxSizeInBytes') asbigint)/(1024*1024) AS total_storage_mb,
NULLAS available_storage_mb, -- Can we find out storage?NULLas uptime
FROMsys.databases d
JOINsys.database_service_objectives slo
ONd.database_id=slo.database_id
Actual behavior:
This query works in most cases until a failover group is used to move databases to another server instance within Azure SQL Database. When a failover group is used, the database_id in master.sys.databases can become out of sync with the database_id used in most of the dynamic management views within the actual Azure SQL DB. This causes the above query to exclude results that should be included.
Additional info:
The below fix will resolve this issue and has been tested heavily.
-- sys.databases.database_id may not match current DB_ID on Azure SQL DBCROSS JOINsys.database_service_objectives slo
WHEREd.name= DB_NAME() ANDslo.database_id= DB_ID()
results in this query:
SELECT TOP(1)
(SELECTcount(*) FROMsys.dm_os_schedulersWHERE status ='VISIBLE ONLINE') AS cpu_count,
(SELECT process_memory_limit_mb FROMsys.dm_os_job_object) AS server_memory,
slo.editionas sku,
cast(SERVERPROPERTY('EngineEdition') assmallint) AS engine_edition,
slo.service_objectiveAS hardware_type,
cast(DATABASEPROPERTYEX(DB_NAME(),'MaxSizeInBytes') asbigint)/(1024*1024) AS total_storage_mb,
NULLAS available_storage_mb, -- Can we find out storage?NULLas uptime
FROMsys.databases d
-- sys.databases.database_id may not match current DB_ID on Azure SQL DBCROSS JOINsys.database_service_objectives slo
WHEREd.name= DB_NAME() ANDslo.database_id= DB_ID()
Let me know if there are questions or if it is Ok to submit a PR with this fix
The text was updated successfully, but these errors were encountered:
The pull request is #6794
This is my first open source pull request so please forgive my ignorance. It appears to me that the unit tests are missing for the SQL Server properties query. Do I need to add those for this?
Relevant telegraf.conf: inputs.sqlserver
System info:
Latest master branch as of 12/11/2019 has this bug.
Telegraf 1.12.6
Ubuntu 18.04
Steps to reproduce:
telegraf/plugins/inputs/sqlserver/sqlserver.go
Line 435 in 05cefe6
This is caused by the database_id column in sys.databases becoming out of sync with DB_ID() within Azure SQL.
Expected behavior:
This query from code line referenced above should return the property information for the server.
Actual behavior:
This query works in most cases until a failover group is used to move databases to another server instance within Azure SQL Database. When a failover group is used, the database_id in master.sys.databases can become out of sync with the database_id used in most of the dynamic management views within the actual Azure SQL DB. This causes the above query to exclude results that should be included.
Additional info:
The below fix will resolve this issue and has been tested heavily.
Adjusting this part of the query:
to this:
results in this query:
Let me know if there are questions or if it is Ok to submit a PR with this fix
The text was updated successfully, but these errors were encountered: