Is there any exec plugin on windows that is usable? I want to collect data from the output of a powershell script?
exec plugin not work on windows? Make sure the permissions and attributes are correct if you are getting errors with it.
You mean I can specify in the config like this:
[[inputs.exec]] commands = ["get-content c:\test.txt"] name_override = "windows_test" data_format = "value" data_type = "integer"
and it can send the data? So it works the same way as linux?
Have you tried? I’m asking because you have to function to generate your config based on the inputs that you specify and if I use it on windows and generate the exec I got as an example the linux exec plugin.
So command like this:
.\telegraf -sample-config -input-filter cpu:mem:exec -output-filter influxdb
Generates this exec in the config on windows:
# Read metrics from one or more commands that can output to stdout [[inputs.exec]] ## Commands array commands = [ "/tmp/test.sh", "/usr/bin/mycollector --foo=bar", "/tmp/collect_*.sh" ]
Which doesn’t make sense right?
You can’t directly call Powershell commands. You need the command you would run from cmd.exe. Look up « How to run a PowerShell script from a batch file ». You need to put your Powershell code in a ps1 file and run a command that will execute the script. First test the command from cmd.exe yourself to make sure it works before trying to run it from Telegraf.
Yeah but how you use with exec on windows? do you see anywhere is it available?
This should work:
# Read metrics from one or more commands that can output to stdout [[inputs.exec]] ## Commands array commands = [ "c:/muhscripts/file-name.ps1" ] ## Timeout for each command to complete. timeout = "5s" ## measurement name suffix (for separating different commands) name_suffix = "_mycollector" ## Data format to consume. ## Each data format has its own unique set of configuration options, read ## more about them here: ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md data_format = "influx"
You’re best off using Invoke-RestMethod or curl from within the powershell script to insert your data when the script runs.
Put the output of the script into a $body variable then something like
Invoke-RestMethod -Uri "https://your-influx-instance:8086/write?db=database&u=username&p=passwrd" -SkipCertificateCheck -body $body -Method POST
It will probably take a bit of tweaking.
If you’re not using self signed certs then you can remove the -SkipCheck section. The tricky part is getting the contenet in body to be valid line protocl
I can’t fully remember the details.