From 5f4b7ed7c5a7fee54d0d84457ecd4ad64e922db6 Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 12 Jan 2016 13:21:46 -0500 Subject: [PATCH] Document gzip usage --- README.md | 7 ++++++- examples/rack/README.md | 16 ++-------------- examples/rack/config.ru | 2 ++ examples/rack/run | 15 +++++++++------ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 2e8d6e02..96be4d7f 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ There are two [Rack][2] middlewares available, one to expose a metrics HTTP endpoint to be scraped by a prometheus server ([Exporter][9]) and one to trace all HTTP requests ([Collector][10]). +It's highly recommended to enable gzip compression for the metrics endpoint, +for example by including the `Rack::Deflater` middleware. + ```ruby # config.ru @@ -45,9 +48,11 @@ require 'rack' require 'prometheus/client/rack/collector' require 'prometheus/client/rack/exporter' +use Rack::Deflater, if: ->(env, status, headers, body) { body.any? && body[0].length > 512 } use Prometheus::Client::Rack::Collector use Prometheus::Client::Rack::Exporter -run lambda { |env| [200, {'Content-Type' => 'text/html'}, ['OK']] } + +run ->(env) { [200, {'Content-Type' => 'text/html'}, ['OK']] } ``` Start the server and have a look at the metrics endpoint: diff --git a/examples/rack/README.md b/examples/rack/README.md index 9eed271f..2f7c3c48 100644 --- a/examples/rack/README.md +++ b/examples/rack/README.md @@ -5,20 +5,8 @@ and `Rack::Collector` rack middlwares. ## Usage -Start the Server. +Execute the provided `run` script: ```bash -unicorn -p 5000 -c unicorn.conf -``` - -Benchmark number of requests. - -```bash -ab -c 10 -n 1000 http://127.0.0.1:5000/ -``` - -View the metrics output. - -```bash -curl http://127.0.0.1:5000/metrics +./run ``` diff --git a/examples/rack/config.ru b/examples/rack/config.ru index 010d7be8..7755c5d1 100644 --- a/examples/rack/config.ru +++ b/examples/rack/config.ru @@ -4,6 +4,8 @@ require 'rack' require 'prometheus/client/rack/collector' require 'prometheus/client/rack/exporter' +use Rack::Deflater, if: ->(env, status, headers, body) { body.any? && body[0].length > 512 } use Prometheus::Client::Rack::Collector use Prometheus::Client::Rack::Exporter + run ->(_) { [200, { 'Content-Type' => 'text/html' }, ['OK']] } diff --git a/examples/rack/run b/examples/rack/run index 95e04872..31fdfc11 100755 --- a/examples/rack/run +++ b/examples/rack/run @@ -6,12 +6,15 @@ installed() { which $1 > /dev/null } -fatal() { +log() { echo >&2 $1 +} + +fatal() { + log $1 exit 1 } -# check dependencies if ! installed vegeta; then if ! installed go; then fatal "Could not find go. Either run the examples manually or install" @@ -24,15 +27,15 @@ fi PORT=5000 URL=http://127.0.0.1:${PORT}/ -# start example server +log "starting example server" bundle install --quiet bundle exec unicorn -p ${PORT} -c unicorn.conf &>> /dev/null & # wait until unicorn is available sleep 1 -# do requests -printf "GET ${URL}\nPOST ${URL}\nDELETE ${URL}" | vegeta attack &>> /dev/null +log "sending requests for 5 seconds" +printf "GET ${URL}\nPOST ${URL}\nDELETE ${URL}" | vegeta attack -duration 5s &>> /dev/null -# output the result +log "printing /metrics" curl -s "${URL}metrics"