Changeset - 45c89eb6dd4c
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 20 months ago 2023-05-31 09:16:49
drewp@bigasterisk.com
no cyclone at import time. i can't even install it now
1 file changed with 0 insertions and 10 deletions:
0 comments (0 inline, 0 general)
light9/metrics.py
Show inline comments
 
@@ -13,25 +13,24 @@ form of the call to set up the right typ
 
  def foo(): 
 

	
 
  metrics('goal_fps').set(f)           # a gauge because we called set()
 

	
 
  with metrics('recompute'): ...       # ctxmgr also makes a timer
 
     time_this_part()
 

	
 
I don't see a need for labels yet, but maybe some code will want like
 
metrics('foo', label1=one). Need histogram? Info?
 

	
 
"""
 
from typing import Dict, Tuple, Callable, Type, TypeVar, cast
 
import cyclone.web
 
from prometheus_client import Counter, Gauge, Metric, Summary
 
from prometheus_client.exposition import generate_latest
 
from prometheus_client.registry import REGISTRY
 

	
 
_created: Dict[str, Metric] = {}
 

	
 
# _process=sys.argv[0]
 
# def setProcess(name: str):
 
#   global _process
 
#   _process = name
 

	
 
MT = TypeVar("MT")
 
@@ -68,33 +67,24 @@ class _MetricsRequest:
 

	
 
    def observe(self, x: float):
 
        return self._ensure(Summary).observe(x)
 

	
 
    def __enter__(self):
 
        return self._ensure(Summary).__enter__()
 

	
 

	
 
def metrics(name: str, **labels):
 
    return _MetricsRequest(name, **labels)
 

	
 

	
 
class _CycloneMetrics(cyclone.web.RequestHandler):
 

	
 
    def get(self):
 
        self.add_header('content-type', 'text/plain')
 
        self.write(generate_latest(REGISTRY))
 

	
 

	
 
def metricsRoute() -> Tuple[str, Type[cyclone.web.RequestHandler]]:
 
    return ('/metrics', _CycloneMetrics)
 

	
 

	
 
"""
 
stuff we used to have in greplin. Might be nice to get (client-side-computed) min/max/stddev back.
 

	
 
class PmfStat(Stat):
 
  A stat that stores min, max, mean, standard deviation, and some
 
  percentiles for arbitrary floating-point data. This is potentially a
 
  bit expensive, so its child values are only updated once every
 
  twenty seconds.
 

	
 

	
0 comments (0 inline, 0 general)