Skip to content

Commit

Permalink
Document gzip usage
Browse files Browse the repository at this point in the history
  • Loading branch information
grobie committed Jan 12, 2016
1 parent 088f91e commit 5f4b7ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ 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

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:
Expand Down
16 changes: 2 additions & 14 deletions examples/rack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 2 additions & 0 deletions examples/rack/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -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']] }
15 changes: 9 additions & 6 deletions examples/rack/run
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

0 comments on commit 5f4b7ed

Please sign in to comment.