diff --git a/bin/vidref b/bin/vidref --- a/bin/vidref +++ b/bin/vidref @@ -19,8 +19,8 @@ from run_local import log from typing import cast import logging, optparse, json, base64, os, glob -# from greplin import scales -# from greplin.scales.cyclonehandler import StatsHandler +from light9.metrics import metrics, metricsRoute + from rdflib import URIRef from twisted.internet import reactor, defer import cyclone.web, cyclone.httpclient, cyclone.websocket @@ -30,7 +30,6 @@ from light9 import networking, showconfi from light9.newtypes import Song from light9.vidref import videorecorder from rdfdb.syncedgraph import SyncedGraph -# from standardservice.scalessetup import gatherProcessStats parser = optparse.OptionParser() parser.add_option("-v", "--verbose", action="store_true", help="logging.DEBUG") @@ -38,13 +37,6 @@ parser.add_option("-v", "--verbose", act log.setLevel(logging.DEBUG if options.verbose else logging.INFO) -# gatherProcessStats() -# stats = scales.collection( -# '/webServer', -# scales.RecentFpsStat('liveWebsocketFrameFps'), -# scales.IntStat('liveClients'), -# ) - class Snapshot(cyclone.web.RequestHandler): @@ -78,23 +70,21 @@ class Live(cyclone.websocket.WebSocketHa def connectionMade(self, *args, **kwargs): pipeline.liveImages.subscribe(on_next=self.onFrame) - # stats.liveClients += 1 + metrics('live_clients').offset(1) def connectionLost(self, reason): #self.subj.dispose() - # stats.liveClients -= 1 - pass + metrics('live_clients').offset(-1) def onFrame(self, cf: videorecorder.CaptureFrame): if cf is None: return - # stats.liveWebsocketFrameFps.mark() - - self.sendMessage( - json.dumps({ - 'jpeg': base64.b64encode(cf.asJpeg()).decode('ascii'), - 'description': f't={cf.t}', - })) + with metrics('live_websocket_frame_fps').time(): + self.sendMessage( + json.dumps({ + 'jpeg': base64.b64encode(cf.asJpeg()).decode('ascii'), + 'description': f't={cf.t}', + })) class SnapshotPic(cyclone.web.StaticFileHandler): @@ -189,9 +179,7 @@ reactor.listenTCP( }), (r'/time', Time), (r'/time/stream', TimeStream), - # (r'/stats/(.*)', StatsHandler, { - # 'serverName': 'vidref' - # }), + metricsRoute(), ], debug=True, ))