Skip to content

Commit

Permalink
add per-instance identifier (though at this point they're already dis…
Browse files Browse the repository at this point in the history
…tinguished by the use of vhm URLs)
  • Loading branch information
davisagli committed Mar 3, 2012
1 parent 478e05a commit b8eb541
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ Finally, fire up your instance and go to http://localhost:8080/firehose-stats
You should see the stats update every 5 seconds as you navigate around the
site in another window.

If you are collecting stats from multiple Zope instances, you can make it
easier to identify which instance is serving a particular request by giving
each instance a unique identifier. Add to your buildout::

[instance]
zope-conf-additional =
<product-config firehose>
instance_id my-instance-id
</product-config>

Retrieving statistics
---------------------

Expand Down
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[ ] include instance identifier
[ ] run as WSGI middleware
[ ] make 0mq and redis endpoints configurable
[ ] get rid of collective namespace
Expand Down
8 changes: 4 additions & 4 deletions collective/firehose/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def record_stats():

r = redis.StrictRedis(host='localhost', port=6379, db=0)


while True:
url, elapsed = sub.recv().rsplit(' ', 1)
instance_id, rest = sub.recv().split(' ', 1)
url, elapsed = rest.rsplit(' ', 1)
pipe = r.pipeline()

# track current requests
if elapsed == '0':
pipe.sadd('serving', url)
pipe.sadd('serving', '%s:%s' % (instance_id, url))
else:
pipe.srem('serving', url)
pipe.srem('serving', '%s:%s' % (instance_id, url))

# track top hits per hour
timeslot = time.time() // 3600
Expand Down
13 changes: 11 additions & 2 deletions collective/firehose/zope2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import time
import threading
import os
import redis
import zmq
from App.config import getConfiguration
from Products.Five import BrowserView

STATS = threading.local()
Expand All @@ -11,16 +13,23 @@
zmq_pub.connect("ipc:///tmp/collective.firehose.sock")


config = getConfiguration()
try:
instance_id = config.product_config['firehose']['instance_id']
except KeyError:
instance_id = os.getpid()


def handle_start(event):
request = event.request
STATS.start = time.time()
# XXX should include instance id
zmq_pub.send('%s %s' % (request.base + request.PATH_INFO, 0))
zmq_pub.send('%s %s %s' % (instance_id, request.base + request.PATH_INFO, 0))


def handle_end(event):
request = event.request
zmq_pub.send('%s %s' % (request.base + request.PATH_INFO, time.time() - STATS.start))
zmq_pub.send('%s %s %s' % (instance_id, request.base + request.PATH_INFO, time.time() - STATS.start))


class StatsView(BrowserView):
Expand Down

0 comments on commit b8eb541

Please sign in to comment.