Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to push metrics using curl on MS Windows #144

Open
cukal opened this issue Feb 12, 2018 · 6 comments
Open

Document how to push metrics using curl on MS Windows #144

cukal opened this issue Feb 12, 2018 · 6 comments

Comments

@cukal
Copy link

cukal commented Feb 12, 2018

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.

@beorn7
Copy link
Member

beorn7 commented Feb 13, 2018

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 beorn7 changed the title Pushgateway refuses metrics from windows Document how to push metrics using curl on MS Windows Feb 13, 2018
@cukal
Copy link
Author

cukal commented Feb 13, 2018

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.

@guhuajun
Copy link

guhuajun commented Sep 3, 2019

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.

@fchaxel
Copy link

fchaxel commented Nov 20, 2019

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

@Nigrimmist
Copy link

@davidzzc
Copy link

davidzzc commented Feb 2, 2024

python requests can be used for perfect solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants