`# Global
[global_tags]
ksid = "servers"
ttl = "1"
[agent]
interval = "60s"
round_interval = false
metric_batch_size = 1000
metric_buffer_limit = 10
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
debug = true
quiet = false
logfile = "C:/Program Files/Telegraf_storage/telegraf.log"
hostname = ""
omit_hostname = false
[[outputs.opentsdb]]
host = "tcp://monit.intranet"
port = 8080
httpBatchSize = 50
debug = true
separator = ":"
[[inputs.exec]]
commands = ['powershell "C:\scripts\share.ps1"',]
interval = "1m"
timeout = "5s"
data_format = "influx"
name_suffix = "_colletor"
`
`#$share = "\10.0.0.100\myshare"
$drive=get-psdrive O
$free=($drive.Free)
Write-Output "example value2=$free"
IsPublic IsSerial Name BaseType
True True UInt64 System.ValueType
C:\Program Files\telegraf_storage>telegraf.exe --config "c:\Program Files\telegraf_storage\telegraf.conf" -test
2020-09-16T15:43:05Z I! Starting Telegraf 1.15.3
example_colletor,host=server,ksid=servers,ttl=1 value2=642416435200 1600270986000000000
Telegraf.log:
2020-09-16T15:28:53Z E! [inputs.exec] Error in plugin: metric parse error: expected field at 1:46: "example value2="
C:\Program Files\telegraf_storage>telegraf.exe --config "c:\Program Files\telegraf_storage\telegraf.conf" --debug
2020-09-16T16:00:11Z I! Starting Telegraf 1.15.3
2020-09-16T15:42:06Z D! [outputs.opentsdb] Buffer fullness: 0 / 10 metrics
2020-09-16T15:42:16Z D! [outputs.opentsdb] Wrote batch of 1 metrics in 1.2258ms
It looks like you're not writing out valid line protocol. Try running your script and see what it outputs.
Hi Steven,
when I run the script manually in a powershell terminal it brings the result below:
PS C:\scripts> .share.ps1
example value2=484178841600
PS C:\scripts>
tks
Sorry for the delayed response. that looks like valid line protocol. Is it possible that $free isn't set when it's run by Telegraf?
Hello andretmfarias,
There are 2 issues that are causing the metrics to not be sent in Telegraf Windows:
1) As Steven said in the above comment, the value for $free isn't set when it's run by Telegraf. You will need to surround the $free variable with $()
Here's a share.ps1 script that I was able to run on my machine:
#$share = "\10.0.0.100\myshare"
#$nwobj = new-object -comobject WScript.Network
#$status=$nwobj.mapnetworkdrive("O:",$share)
$drive=get-psdrive C
$free=($drive.Free)
Write-Output "example value2=$($free)"
2) Within [[inputs.exec]], you will need to use forward slashes (instead of backslashes) so that the slashes won't be interpreted as escape characters.
Here's my inputs plugin:
[[inputs.exec]]
commands = ['powershell "C:/Users/me/win-telegraf/telegraf-1.16.1/scripts/share.ps1"',]
interval = "10s"
timeout = "5s"
data_format = "influx"
name_suffix = "_colletor"
I confirmed that I can send the metrics through Telegraf Windows while not using debug mode:
C:\Users\me\win-telegraf\telegraf-1.16.1>telegraf --config ./telegraf.conf -test
2020-11-03T18:59:08Z I! Starting Telegraf 1.16.1
> example_colletor,host=server,ksid=servers,ttl=1 value2=230007169024 1604429949000000000
with no errors in telegraf.log:
2020-11-03T18:59:08Z D! [agent] Initializing plugins
2020-11-03T18:59:08Z D! [agent] Starting service inputs
2020-11-03T18:59:08Z D! [agent] Stopping service inputs
2020-11-03T18:59:08Z D! [agent] Input channel closed
2020-11-03T18:59:08Z D! [agent] Stopped Successfully
and I'm able to view the data in InfluxDB.
I will close this issue, but please feel free to reopen it if this solution isn't working.
I applied the settings mentioned here, everything works now. Thanks a lot for the help!
Most helpful comment
I applied the settings mentioned here, everything works now. Thanks a lot for the help!