telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

backslash in object name of config file for windows perf counters SQL instance metrics

Open ryxx-zz opened this issue 10 years ago • 17 comments

I'm trying to enter "\hostname\MSSQL$Sqlinstance:General Statistics" in the objectname field.

When trying to start telegraf, the config file cannot be parsed.

ryxx-zz avatar May 06 '16 15:05 ryxx-zz

need more info:

  1. config file
  2. error message
  3. version

sparrc avatar May 06 '16 15:05 sparrc

Error is "Error Parsing .\telegraf.conf, toml: Line 135 parse error.

Section of config file is: [[inputs.win_perf_counter.object]] ObjectName = "\localhost\mssql$mysqlinstance:General Statistics" Counters = ["User Connections"]

Line 135 is the ObjectName one

This is running telegraf on windows V0.12.1

ryxx-zz avatar May 06 '16 15:05 ryxx-zz

If i use ObjectName = "\\localhost\mssql$mysqlinstance:General Statistics"

the config file parses but i dont get any metrics, probably because it thinks that object name is then not formatted correctly trying to actually get the win perf counter

ryxx-zz avatar May 06 '16 16:05 ryxx-zz

what is the actual object name you're trying to get?

sparrc avatar May 06 '16 17:05 sparrc

When you use an Instance name in SQL rather than the default "Instance" during install you need to specify it in the counter request. The object is called "\LOCALHOST\MSSQL$SQLINSTANCENAME:General Statistics or \LOCALHOST\MSSQL$SQLINSTANCENAME:Memory Buffer These work in powershell, but i cant specify them in the telegraf config.

The other counters are working fine "CPU" and "Memory" etc but because these counters need the full name the backslash seems to cause a problem

ryxx-zz avatar May 06 '16 17:05 ryxx-zz

Get-counter -Counter "\Servername\MSSQL$SQLInstancename:General Statistics\User connections" returns a value as expected from within powershell

ryxx-zz avatar May 06 '16 17:05 ryxx-zz

thankyou for your help looking into this :)

ryxx-zz avatar May 06 '16 17:05 ryxx-zz

i suppose the other option is to use the SQLServer plugin to read directly off the SQL server

https://github.com/influxdata/telegraf/tree/master/plugins/inputs/sqlserver

but i'm not 100% sure how to actually use the files displayed in that link to setup the telegraf.exe and telegraf.conf (the only 2 files in windows) and get it working.

I'm new to telegraf and github, so i may be asking silly questions.

ryxx-zz avatar May 06 '16 17:05 ryxx-zz

doesn't the case matter? why not keep the case consistent in your telegraf config file?

I'm not really sure you need any backslashing at all, as those might be escape characters in powershell.

sparrc avatar May 06 '16 18:05 sparrc

I've tried with different cases. I've tried with multiple quote marks and single quotes inside the double quotes, none of them work.

For those particular counters you need to have backslashes unfortunately.

OK well if its a non starter as a \ is an escape character in telegraf then i'll need to sort out the sqlserver input plugin.

Can that be installed directly on a Windows machine or will i need a linux machine running telegraf with those input files on it to pull the data from sql ?

ryxx-zz avatar May 06 '16 18:05 ryxx-zz

no, just define the plugin in your config file and it will get run:

# Read metrics from Microsoft SQL Server
[[inputs.sqlserver]]
  # Specify instances to monitor with a list of connection strings.
  # All connection parameters are optional. 
  # By default, the host is localhost, listening on default port (TCP/1433) 
  #    for Windows, the user is the currently running AD user (SSO).
  #    See https://github.com/denisenkom/go-mssqldb for detailed connection parameters.

  servers = [
    "Server=192.168.1.30;Port=1433;User Id=telegraf;Password=T$l$gr@f69*;app name=telegraf;log=1;",
    "Server=192.168.1.30;Port=2222;User Id=telegraf;Password=T$l$gr@f69*;app name=telegraf;log=1;"
    ]

sparrc avatar May 06 '16 18:05 sparrc

so just copy the sqlserver.go file into the same directory as the telegraf.exe and the telegraph.conf and then specify as above in the the conf file ?

ryxx-zz avatar May 06 '16 18:05 ryxx-zz

no, you already have the plugin in telegraf.exe, just define the above config in telegraf.conf, you do not need any .go files, this is not a scripting language ;-)

sparrc avatar May 06 '16 19:05 sparrc

oh - perfect !

Thanks for your help - i'll try it now.

ryxx-zz avatar May 06 '16 19:05 ryxx-zz

all working !

thankyou

ryxx-zz avatar May 06 '16 20:05 ryxx-zz

closing because this is available in the sqlserver plugin

sparrc avatar May 18 '16 11:05 sparrc

I have a similar problem: I just setup my telegraf.conf who run a powershell script with a path as an argument. Problem is : My argument can be a network path, and it seems like there are no way to use backslash in the exec string. commands = ['powershell ./parse_send_csv.ps1 "\blabla\a"']

Using \\ results to having 2 backslash : Not working Using only one \ results to no backslash : Not working Using single or double quote : Not working I even tried to escape with ` character (escaping character in golang) with no success. Anyone having same problem ?

EdouardNaze avatar Jan 04 '17 14:01 EdouardNaze