diff bin/vidref @ 2046:9aa046cc9b33

replace greplin with prometheus throughout (untested)
author drewp@bigasterisk.com
date Tue, 10 May 2022 23:01:26 -0700
parents 67575505c400
children
line wrap: on
line diff
--- a/bin/vidref	Mon May 09 23:18:39 2022 -0700
+++ b/bin/vidref	Tue May 10 23:01:26 2022 -0700
@@ -19,8 +19,8 @@
 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.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 @@
 
 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 @@
 
     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 @@
             }),
             (r'/time', Time),
             (r'/time/stream', TimeStream),
-            # (r'/stats/(.*)', StatsHandler, {
-            #     'serverName': 'vidref'
-            # }),
+            metricsRoute(),
         ],
         debug=True,
     ))