Skip to content
Browse files

add per-instance identifier (though at this point they're already dis…

…tinguished by the use of vhm URLs)
  • Loading branch information...
1 parent 478e05a commit b8eb54192a9a37126b87acd0214f6ac8cda1f4ea @davisagli committed Mar 2, 2012
Showing with 25 additions and 7 deletions.
  1. +10 −0 README.rst
  2. +0 −1 TODO.txt
  3. +4 −4 collective/firehose/recorder.py
  4. +11 −2 collective/firehose/zope2.py
View
10 README.rst
@@ -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
---------------------
View
1 TODO.txt
@@ -1,4 +1,3 @@
-[ ] include instance identifier
[ ] run as WSGI middleware
[ ] make 0mq and redis endpoints configurable
[ ] get rid of collective namespace
View
8 collective/firehose/recorder.py
@@ -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
View
13 collective/firehose/zope2.py
@@ -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()
@@ -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):

0 comments on commit b8eb541

Please sign in to comment.
Something went wrong with that request. Please try again.