# Idea for a statistics module

**URL:** <https://www.ruby-forum.com/t/idea-for-a-statistics-module/176935>\
**Category:** NGINX\
**Created:** [October 8, 2009, 4:53pm UTC](https://www.ruby-forum.com/t/idea-for-a-statistics-module/176935 "2009-10-08T16:53:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tommie\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@Tommie\_G](https://www.ruby-forum.com/u/Tommie_G)\
**Post date:** [October 8, 2009, 4:53pm UTC](https://www.ruby-forum.com/t/idea-for-a-statistics-module/176935/1 "2009-10-08T16:53:59Z")

</div>

Hi!

We felt the stub status module was a bit too non-modular for our  
internal services  
and created a statistics module where each module can allocate their  
stat counters  
more dynamically.

It does have a hardcoded limit of around 64 counters currently, and  
any suggestion  
on how to make it dynamical is highly appreciated.

Apart from adding another “increment the counter”, it also requires  
the event and core  
modules to allocate the counters, why they have been given module init  
functions.

You use it by adding

location /server-status {  
statistics on;  
}

and requesting

[http://example.com/sever-status](http://example.com/sever-status)

for RFC822 formatted output or

[http://example.com/sever-status?type=text/html](http://example.com/sever-status?type=text/html)

for more human friendly text.

The module adds the ability to use histograms of fixed bucket counts,  
but note that  
the counters will never be reset, so it is nowhere near a snapshot  
value. For that we use  
a monitoring/graphing system fed with the RFC822 output. This is also  
the reason why the  
default MIME type is text/plain, rather than text/html. The histograms  
are quite useful for plotting  
file sizes or request delays.

Hope you find it useful. The original code contained in the patch is  
MIT licensed.  
Documentation of the code… in the future.

---

<div class="post-metadata">

**Author:** ![Tommie\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@Tommie\_G](https://www.ruby-forum.com/u/Tommie_G)\
**Post date:** [October 9, 2009, 2:48am UTC](https://www.ruby-forum.com/t/idea-for-a-statistics-module/176935/2 "2009-10-09T02:48:52Z")

</div>

It doesn’t seem to be tracking the request time properly, the counts  
remain at 0 for all ranges.

Event-Accepted: 365  
Event-Active: 160  
Event-Handled: 365  
Http-Requests-Reading: 0  
Http-Requests-Writing: 1  
Http-Requests-Total: 1754  
Http-Time-Request:  
-0=0  
1-1=0  
2-4=0  
5-9=0  
10-19=0  
20-49=0  
50-99=0  
100-199=0  
200-499=0  
500-999=0  
1000-1999=0  
2000-4999=0  
5000-9999=0  
10000-19999=0  
20000-=0  
Http-Requests-Active: 1  
Http-Requests-Writing-File: 0  
Http-Upstreams-Total: 1700  
Http-Upstreams-Active: 0  
Http-Cached: 0

2009/10/8 Tommie G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Tommie\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@Tommie\_G](https://www.ruby-forum.com/u/Tommie_G)\
**Post date:** [October 9, 2009, 9:56am UTC](https://www.ruby-forum.com/t/idea-for-a-statistics-module/176935/3 "2009-10-09T09:56:09Z")

</div>

2009/10/9 zepolen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> It doesn’t seem to be tracking the request time properly, the counts  
> remain at 0 for all ranges.

Oops. I never intended to include the request time counter in the patch.  
Attached is an updated patch which adds the required \_add\_int() call.
