Hi guys,
Quick question
Has anyone got any examples of text file collector usage? Is there a particular format I need to adhere to ?
Also interested to understand how people have made use of this collector to collect non standard metrics.
Cheers
Pete
We definitely should have this type of documentation. For now, I'd suggest looking at the node_exporter's examples for inspiration.
The basic concept is that you have a script/program that outputs Prometheus metrics to disk, and the collector will expose this when it is scraped.
hmmm I've had a go but doesn't seem to be working :)
Have setup a test static file to prove the concept;
# HELP test_metric_processes help
# TYPE test_metric_processes gauge
wmi_textfile_test_metric 0
# HELP test_metric help
# TYPE test_metric_processes gauge
wmi_textfile_moo_test 111111
Have enabled the collector and only see the following in the WEB UI:
# HELP wmi_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise
# TYPE wmi_textfile_scrape_error gauge
wmi_textfile_scrape_error 0
"C:\Program Files\wmi_exporter\wmi_exporter.exe" --log.format logger:eventlog?name=wmi_exporter --telemetry.addr :9182 --collectors.enabled cpu,cs,logical_disk,net,os,process,service,system,textfile --collector.textfile.directory c:\textcollector
here are the command lines used
Cheers
pete
Hm. Could you up the log level a bit? If running from a console, go with something like this: "C:\Program Files\wmi_exporter\wmi_exporter.exe" --log.level debug --collector.textfile.directory c:\textcollector (the textfile collector is enabled by default).
This will do debug logging to stdout, so you don't have to watch it in the event viewer
Will look in the morning.
I was going create a text file output for Windows scheduled tasks 👌🏻
Ah, ok yes it was my bad :)
only note is that there seems to be a cosmetic issue;
# HELP wmi_textfile_test_metric Metric read from c:\\textcollector\\test.prom
# TYPE wmi_textfile_test_metric gauge
wmi_textfile_test_metric 0
note the double slash in the path name
loosing the will to live today :)
I've now created a script to create a file but I keep getting this error:
[31mERRO[0m[0208] Error parsing "c:\\Metrics\\scheduledtasks.prom": text format parsing error in line 1: invalid metric name [31msource[0m="textfile.go:242"
Here is my output from the file that was generated....
# HELP wmi_textfile_scheduled_task_success
# TYPE wmi_textfile_scheduled_task_success gauge
wmi_textfile_scheduled_task_success{name="BankStaff Agency Costing XXXX",state="Ready"} 1
wmi_textfile_scheduled_task_success{name="BankStaff Leave Claims XXXX",state="Ready"} 1
wmi_textfile_scheduled_task_success{name="BankStaff Recalc Agency Charges XXXX",state="Ready"} 1
wmi_textfile_scheduled_task_success{name="SynchroniseReferenceData.XXXX",state="Ready"} 1
wmi_textfile_scheduled_task_success{name="RestartBackgroundTasksService.XXXX",state="Ready"} 1
wmi_textfile_scheduled_task_success{name="RestartBackgroundTasksService.XXXX",state="Ready"} 1
What does this mean ?
An error has occurred during metrics gathering:
collected metric wmi_textfile_scheduled_task_success label:
Looks like you have duplicates in your metrics? wmi_textfile_scheduled_task_success{name="RestartBackgroundTasksService.XXXX",state="Ready"} 1 occurs twice.
ahhh - I see now, I'll need to add in the "Path" attribute as is this a genuine scenario.
Additionally, I note that the file should be saved as UTF8 and not UTF8-BOM
UTF-8 with BOM is a weird thing, since the UTF-8 standard only supports one byte order anyway... What software generated such a file?
Powershell script - have got it to ouput a UTF8 and now reads the metrics OK... However ….. with the TaskPath added I now get the following error;
[31mERRO[0m[1506] Error parsing "c:\Metrics\scheduledtasks.prom": text format parsing error in line 3: invalid escape sequence '\T' [31msource[0m="textfile.go:242"
output file looks like:
wmi_textfile_scheduled_task_success{taskpath="\Tasks\BankStaff\"
How do I correctly handle \ in the matric value or do I need to strip these out before it generates the output ?
Hm, if Powershell outputs something like that we might need to hack some support for it, I guess.
As for the backslashes, you'll need to either escape them (replace \ with \\), or strip them out.
I tried the double \, expecting it to only displaly a single \ in the output but ends up displaying both backslashes ! - is this a bug given this also displays double backslash on the text file collector path too?
Here is my script, if you wish to create some textfile examples for others the use.
$taskPath = "\*\"
$output = "c:\Metrics\scheduledtasks.prom"
Function Get-Tasks ($task) {
$tasks = @()
Get-ScheduledTask -TaskPath $taskPath | % {
$tasks += @{
Name = $_.TaskName;
Status = $_.State;
TaskPath = $_.TaskPath.Replace('\', '\\')
LastResult = (Transform-Status-Code (Get-ScheduledTaskInfo $_).LastTaskResult)
}
}
return $tasks
}
Function Transform-Status-Code($LastResult) {
If ($LastResult -eq 0) { return 1 }
return 0
}
Function Build-Metrics-Output($tasks) {
New-Item -ItemType File $output -Force | Out-Null
Clear-Content $output -Force
$obj1 = @"
# HELP wmi_textfile_scheduled_task_success help
# TYPE wmi_textfile_scheduled_task_success gauge
"@
$obj1 | Out-File -Force -Encoding utf8 $output
ForEach ($task in $tasks) {
$obj2 ="wmi_textfile_scheduled_task_success{taskpath=`"$($task.TaskPath)`",name=`"$($task.Name)`",state=`"$($task.Status)`"} $($task.LastResult)" | Out-File -Encoding utf8 $output -Append
$MyFile = Get-Content $output
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($output, $MyFile, $Utf8NoBomEncoding)
}
}
$out = Get-Tasks
Build-Metrics-Output $out
loosing the will to live today :)
powershell can be cruel, I believe in you!
Will close this issue as now working. Hopefully this will give others enough info to get going with this too.
I've run into this as well - since wmi_exporter strips CRLFs (as of #200), I wonder if it'd make sense to _also_ discard BOMs...
I just spend 2 hours to figure out the reason for a similar problem.
I created a test.prom file in my textfile_inputs folder using a simple echo "something" > test.prom
That created the file in UCS-2 LE-BOM coding. After 2 hours experimenting with the file content I realized that wrong coding and converted it to UTF-8.
Afterwards everything was working like expected.
Is it possible to check the coding to generate a better error message?
The error was always something like ".. text format parsing error in line 2: invalid metric name ..."
@MichaelHellmann I wondered if anyone would try to use non-UTF8 when I worked on #285 😉 - checking and giving a better error message is pretty easy - I can take this on 👍
@MichaelHellmann I've fixed made the error message cleaner in #293
Most helpful comment
powershell can be cruel, I believe in you!