pushgateway icon indicating copy to clipboard operation
pushgateway copied to clipboard

Document how to push metrics using `curl` on MS Windows

Open cukal opened this issue 7 years ago • 6 comments

On windows using curl.exe and the example echo "some_metric 3.14" | curl ... does not work, echo sends the double quotes and pushgateway returns an error. Single quotes get echo'ed also. Getting rid of the double quotes opens another issue. Echo insists on slapping an extra \r character confusing pushgateway. Trying set /P =some_metric 1<NUL| curl returns an end-of-stream error from pushgateway.

The only way to send some_metric 3.14 was to echo it to a file, dos2unix that file so it only has a <LF> and send that using curl.exe -d "@file" to the pushgateway.

cukal avatar Feb 12 '18 22:02 cukal

The Pushgateway adheres to the protocol spec, which includes that lines are \n terminated. Pushgateway cannot solve escaping and quoting issues of MS Windows. Perhaps the easiest solution is to install a GNU (or similar) echo command (via Ubuntu for MS Windows?)? With that, you can do something like echo -ne 'foobar 3.1415\n'.

I don't have access to a current MS Windows installation. I see this mostly as a documentation issue. Help would be appreciated.

beorn7 avatar Feb 13 '18 13:02 beorn7

Your analysis is spot on. Sadly Cygwin wasn't an option for the production environment and Windows Linux Subsystem (to use Ubuntu for MS) requires at least Windows 10 / Server 2016. On the Testing environment we installed Cygwin and that worked flawlessly as it's using GNU echo. It allowed us to catch the windows echo \r using tcpdump at the Pushgateway side. Post-processing with dos2unix seemed the only rapid / valid option at that point.

cukal avatar Feb 13 '18 14:02 cukal

I wrote a PowerShell function before, https://github.com/guhuajun/prometheus_posh_client/blob/master/prometheus.psm1. With slight modification, this function can also handle typeperf data.

guhuajun avatar Sep 03 '19 06:09 guhuajun

Hi,

Open a PowerShell console, then use this kind of request

Invoke-WebRequest -Uri http://localhost:9091/metrics/job/MyJob -Method POST -Body "Some_Metric 3.14`n"

... but this is strange that nothing is done to accept \r\n and \n and none. One 'if' is at no cost.

Bye

fchaxel avatar Nov 20 '19 04:11 fchaxel

Also, you can try use Postman as described here : https://stackoverflow.com/questions/71161409/postman-to-prometheus-and-carriage-r-text-format-parsing-error-in-line-1-e/71161410

Nigrimmist avatar Feb 17 '22 21:02 Nigrimmist

python requests can be used for perfect solutions

davidzzc avatar Feb 02 '24 07:02 davidzzc