sensu-plugins / sensu-plugins-http

This plugin provides native HTTP instrumentation for monitoring and metrics collection, including: response code, JSON response, HTTP last modified, SSL expiry, and metrics via `curl`.
http://sensu-plugins.io
MIT License
30 stars 97 forks source link

Fix metrics curl #92

Closed multani closed 6 years ago

multani commented 6 years ago

Pull Request Checklist

Fixes #54

General

Purpose

The script wasn't working before:

$ bundle exec bin/metrics-curl.rb -s test -u https://www.google.com
sh: 1: Syntax error: Unterminated quoted string
test.time_total
test.time_namelookup
test.time_connect
test.time_pretransfer
test.time_redirect
test.time_starttransfer
test.http_code

The first commit fixes the syntax error, but numbers are still off (especially visible for the http_code output):

$ bundle exec bin/metrics-curl.rb -s test -u https://www.google.com
test.time_total 0 1521033690
test.time_namelookup 165517 1521033690
test.time_connect 0 1521033690
test.time_pretransfer 028433 1521033690
test.time_redirect 0 1521033690
test.time_starttransfer 052873 1521033690
test.http_code 0 1521033690

But I'm using the French locale here:

$ locale
LANG=en_US.utf8
LANGUAGE=
LC_CTYPE="en_US.utf8"
LC_NUMERIC=fr_FR.UTF-8
LC_TIME=fr_FR.UTF-8
LC_COLLATE="en_US.utf8"
LC_MONETARY=fr_FR.UTF-8
LC_MESSAGES="en_US.utf8"
LC_PAPER=fr_FR.UTF-8
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT=fr_FR.UTF-8
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
$ LC_NUMERIC=C bundle exec bin/metrics-curl.rb -s test -u https://www.google.com
test.time_total 0.132413 1521033715
test.time_namelookup 0.004269 1521033715
test.time_connect 0.028579 1521033715
test.time_pretransfer 0.100833 1521033715
test.time_redirect 0.000000 1521033715
test.time_starttransfer 0.131823 1521033715
test.http_code 302 1521033715

Second commit fixes this for good:

$ bundle exec bin/metrics-curl.rb -s test -u https://www.google.com             
test.time_total 0.138064 1521033777
test.time_namelookup 0.004124 1521033777
test.time_connect 0.028628 1521033777
test.time_pretransfer 0.111635 1521033777
test.time_redirect 0.000000 1521033777
test.time_starttransfer 0.137108 1521033777
test.http_code 302 1521033777

@majormoses I'll be happy to try to write an integration test for that but bundle exec rake default fails (cannot load such file -- spec_helper).

Known Compatibility Issues

None

majormoses commented 6 years ago

Thanks for your contribution to Sensu plugins! Without people like you submitting PRs we couldn't run the project. I will review it shortly.

majormoses commented 6 years ago

released: https://rubygems.org/gems/sensu-plugins-http/versions/2.8.3