Telegraf's [sqlserver_performance] outputs query instead of formatted results

Hi, I used the same .conf file for two SQL Server Developer machines and they display different results.

Example of the expected result after using .\telegraf --test:
> sqlserver_performance,counter=Data\ File(s)\ Size\ (KB),counter_type=65792,host=host,hostgroup=hostgroup,instance=model,measurement_db_type=SQLServer,object=SQLServer:Databases,sql_instance=SQLDEV, value=8192 1682344161000000000

Now for the machine that does not output values:

>sqlserver_requests,command=EXECUTE,host=hostname,host_name=hostname,hostgroup=hostgroup,login_name=telegraf,measurement_db_type=SQLServer,program_name=telegraf,session_db_name=tempdb,sql_instance=name:instance,statement_text=\nSET\
ADLOCK_PRIORITY\ -10;\nIF\ SERVERPROPERTY('EngineEdition')\ NOT\ IN\ (2\,3\,4)\ BEGIN\ /*NOT\ IN\ Standard\,Enterpris\,Express*/\n\tDECLARE\ @ErrorMessage\ AS\ nvarchar(500)\ \=\ 'Telegraf\ -\ Connection\ string\ Server:'+\ @@ServerName\ +\ '\,Database:'\ +\ DB_NAME()\ +'\ is\ not\ a\ SQL\ Server\
andard\,Enterprise\ or\ Express.\ Check\ the\ database_type\ parameter\ in\ the\ telegraf\ configuration.';\n\tRAISERROR\ (@ErrorMessage\,11\,1)\n\tRETURN\nEND\n\nDECLARE\n\t\ @SqlStatement\ AS\ nvarchar(max)\n\t\,@MajorMinorVersion\ AS\ int\ \=\ CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion')\ AS\
archar)\,4)\ AS\ int)*100\ +\ CAST(PARSENAME(CAST(SERVERPROPERTY('ProductVersion')\ AS\ nvarchar)\,3)\ AS\ int)\n\nDECLARE\ @PCounters\ TABLE\n(\n\t\ [object_name]\ nvarchar(128)\n\t\,[counter_name]\ nvarchar(128)\n\t\,[instance_name]\ nvarchar(128)\n\t\,[cntr_value]\ bigint\n\t\,[cntr_type]\
t\n\tPRIMARY\ KEY([object_name]\,\ [counter_name]\,\ [instance_name])\n);\n\nWITH\ PerfCounters\ AS\ (\nSELECT\ DISTINCT\n\t\ RTRIM(spi.[object_name])\ [object_name]\n\t\,RTRIM(spi.[counter_name])\ [counter_name]\n\t\,RTRIM(spi.[instance_name])\ AS\ [instance_name]\n\t\,CAST(spi.[cntr_value]\ AS\
gint)\ AS\ [cntr_value]\n\t\,spi.[cntr_type]\n\tFROM\ sys.dm_os_performance_counters\ AS\ spi\n\tWHERE\n\t\tcounter_name\ IN\ (\n\t\t\t\ 'SQL\ Compilations/sec'\n\t\t\t\,'SQL\ Re-Compilations/sec'\n\t\t\t\,'User\ Connections'\n\t\t\t\,'Batch\
quests/sec'\n\t\t\t\,'Logouts/sec'\n\t\t\t\,'Logins/sec'\n\t\t\t\,'Processes\ blocked'\n\t\t\t\,'Latch\ Waits/sec'\n\t\t\t\,'Average\ Latch\ Wait\ Time\ (ms)'\n\t\t\t\,'Full\ Scans/sec'\n\t\t\t\,'Index\ Searches/sec'\n\t\t\t\,'Page\ Splits/sec'\n\t\t\t\,'Page\ lookups/sec'\n\t\t\t\,'Page\
ads/sec'\n\t\t\t\,'Page\ writes/sec'\n\t\t\t\,'Readahead\ pages/sec'\n\t\t\t\,'Lazy\ writes/sec'\n\t\t\t\,'Checkpoint\ pages/sec'\n\t\t\t\,'Table\ Lock\ Escalations/sec'\n\t\t\t\,'Page\ life\ expectancy'\n\t\t\t\,'Log\ File(s)\ Size\ (KB)'\n\t\t\t\,'Log\ File(s)\ Used\ Size\ (KB)'\n\t\t\t\,'Data\
le(s)\ Size\ (KB)'\n\t\t\t\,'Transactions/sec'\n\t\t\t\,'Write\ Transactions/sec'\n\t\t\t\,'Active\ Transactions'\n\t\t\t\,'Log\ Growths'\n\t\t\t\,'Active\ Temp\ Tables'\n\t\t\t\,'Logical\ Connections'\n\t\t\t\,'Temp\ Tables\ Creation\ Rate'\n\t\t\t\,'Temp\ Tables\ For\ Destruction'\n\t\t\t\,'Free\
ace\ in\ tempdb\ (KB)'\n\t\t\t\,'Version\ Store\ Size\ (KB)'\n\t\t\t\,'Memory\ Grants\ Pending'\n\t\t\t\,'Memory\ Grants\ Outstanding'\n\t\t\t\,'Free\ list\ stalls/sec'\n\t\t\t\,'Buffer\ cache\ hit\ ratio'\n\t\t\t\,'Buffer\ cache\ hit\ ratio\ base'\n\t\t\t\,'Backup/Restore\
roughput/sec'\n\t\t\t\,'Total\ Server\ Memory\ (KB)'\n\t\t\t\,'Target\ Server\ Memory\ (KB)'\n\t\t\t\,'Log\ Flushes/sec'\n\t\t\t\,'Log\ Flush\ Wait\ Time'\n\t\t\t\,'Memory\ broker\ clerk\ size'\n\t\t\t\,'Log\ Bytes\ Flushed/sec'\n\t\t\t\,'Bytes\ Sent\ to\ Replica/sec'\n\t\t\t\,'Log\ Send\
eue'\n\t\t\t\,'Bytes\ Sent\ to\ Transport/sec'\n\t\t\t\,'Sends\ to\ Replica/sec'\n\t\t\t\,'Bytes\ Sent\ to\ Transport/sec'\n\t\t\t\,'Sends\ to\ Transport/sec'\n\t\t\t\,'Bytes\ Received\ from\ Replica/sec'\n\t\t\t\,'Receives\ from\ Replica/sec'\n\t\t\t\,'Flow\ Control\ Time\ (ms/sec)'\n\t\t\t\,'Flow\
ntrol/sec'\n\t\t\t\,'Resent\ Messages/sec'\n\t\t\t\,'Redone\ Bytes/sec'\n\t\t\t\,'XTP\ Memory\ Used\ (KB)'\n\t\t\t\,'Transaction\ Delay'\n\t\t\t\,'Log\ Bytes\ Received/sec'\n\t\t\t\,'Log\ Apply\ Pending\ Queue'\n\t\t\t\,'Redone\ Bytes/sec'\n\t\t\t\,'Recovery\ Queue'\n\t\t\t\,'Log\ Apply\ Ready\
eue'\n\t\t\t\,'CPU\ usage\ %'\n\t\t\t\,'CPU\ usage\ %\ base'\n\t\t\t\,'Queued\ requests'\n\t\t\t\,'Requests\ completed/sec'\n\t\t\t\,'Blocked\ tasks'\n\t\t\t\,'Active\ memory\ grant\ amount\ (KB)'\n\t\t\t\,'Disk\ Read\ Bytes/sec'\n\t\t\t\,'Disk\ Read\ IO\ Throttled/sec'\n\t\t\t\,'Disk\ Read\
/sec'\n\t\t\t\,'Disk\ Write\ Bytes/sec'\n\t\t\t\,'Disk\ Write\ IO\ Throttled/sec'\n\t\t\t\,'Disk\ Write\ IO/sec'\n\t\t\t\,'Used\ memory\ (KB)'\n\t\t\t\,'Forwarded\ Records/sec'\n\t\t\t\,'Background\ Writer\ pages/sec'\n\t\t\t\,'Percent\ Log\ Used'\n\t\t\t\,'Log\ Send\ Queue\ KB'\n\t\t\t\,'Redo\ Queue\
'\n\t\t\t\,'Mirrored\ Write\ Transactions/sec'\n\t\t\t\,'Group\ Commit\ Time'\n\t\t\t\,'Group\ Commits/Sec'\n\t\t\t\,'Workfiles\ Created/sec'\n\t\t\t\,'Worktables\ Created/sec'\n\t\t\t\,'Distributed\ Query'\n\t\t\t\,'DTC\ calls'\n\t\t\t\,'Query\ Store\ CPU\ usage'\n\t\t\t\,'Query\ Store\ physical\
ads'\n\t\t\t\,'Query\ Store\ logical\ reads'\n\t\t\t\,'Query\ Store\ logical\ writes'\n\t\t)\ OR\ (\n\t\t\tspi.[object_name]\ LIKE\ '%User\ Settable%'\n\t\t\tOR\ spi.[object_name]\ LIKE\ '%SQL\ Errors%'\n\t\t\tOR\ spi.[object_name]\ LIKE\ '%Batch\ Resp\ Statistics%'\n\t\t)\ OR\
n\t\t\tspi.[instance_name]\ IN\ ('_Total')\n\t\t\tAND\ spi.[counter_name]\ IN\ (\n\t\t\t\t\ 'Lock\ Timeouts/sec'\n\t\t\t\t\,'Lock\ Timeouts\ (timeout\ >\ 0)/sec'\n\t\t\t\t\,'Number\ of\ Deadlocks/sec'\n\t\t\t\t\,'Lock\ Waits/sec'\n\t\t\t\t\,'Latch\ Waits/sec'\n\t\t\t)\n\t\t)\n)\n\nINSERT\ INTO\
Counters\ SELECT\ *\ FROM\ PerfCounters;\n\nSELECT\n\t\ 'sqlserver_performance'\ AS\ [measurement]\n\t\,REPLACE(@@SERVERNAME\,'\'\,':')\ AS\ [sql_instance]\n\t\,pc.[object_name]\ AS\ [object]\n\t\,pc.[counter_name]\ AS\ [counter]\n\t\,CASE\ pc.[instance_name]\ WHEN\ '_Total'\ THEN\ 'Total'\ ELSE\
NULL(pc.[instance_name]\,'')\ END\ AS\ [instance]\n\t\,CAST(CASE\ WHEN\ pc.[cntr_type]\ \=\ 537003264\ AND\ pc1.[cntr_value]\ >\ 0\ THEN\ (pc.[cntr_value]\ *\ 1.0)\ /\ (pc1.[cntr_value]\ *\ 1.0)\ *\ 100\ ELSE\ pc.[cntr_value]\ END\ AS\ float(10))\ AS\ [value]\n\t\,CAST(pc.[cntr_type]\ AS\ varchar(25))\
\ [counter_type]\nFROM\ @PCounters\ AS\ pc\nLEFT\ OUTER\ JOIN\ @PCounters\ AS\ pc1\n\tON\ (\n\t\tpc.[counter_name]\ \=\ REPLACE(pc1.[counter_name]\,'\ base'\,'')\n\t\tOR\ pc.[counter_name]\ \=\ REPLACE(pc1.[counter_name]\,'\ base'\,'\ (ms)')\n\t)\n\tAND\ pc.[object_name]\ \=\ pc1.[object_name]\n\tAND\
.[instance_name]\ \=\ pc1.[instance_name]\n\tAND\ pc1.[counter_name]\ LIKE\ '%base'\nWHERE\n\tpc.[counter_name]\ NOT\ LIKE\ '%\ base'\nOPTION(RECOMPILE)\n,status=running,transaction_isolation_level=2-Read\ Committed
u_time_ms=2i,granted_query_memory_pages=0i,logical_reads=26i,open_transaction=0i,percent_complete=0,request_id=0i,session_id=61i,total_elapsed_time_ms=2i,wait_time_ms=0i,writes=0i 1682343401000000000

The odd part is that the module outputs data for other queries, for instance the sqlserver_waitstats, but it just outputs this giant SQL Query for the sqlserver_performance one. Any hints please? Cheers.

That query output belongs to the “sqlserver_requests” part of the plugin, and I highly suggest you convert the “statement_text” tag to a field in order to avoid issues (or avoid using the if not necessary).

I suggest you to isolate the config and get only the perf counters of that instance in order to check if something is returned or not, then you can also run the query manually on SQL Server to see if something is wrong.

1 Like