Last active
March 26, 2019 18:12
-
-
Save danish1010/52c15f0593af2efc937a904c2f0d5399 to your computer and use it in GitHub Desktop.
SAMPLE API INTERFACE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from app.lib.metrics import Summary, Counter, Guage, Profile | |
MEASURE_DEMO_TASK = Profile( | |
name = 'demo_task', | |
documentation = 'Measure throughput, latency and errors for demo task', | |
namespace = 'manage.project' | |
) | |
class DemoTaskHandler(TaskHandler): | |
@MEASURE_DEMO_TASK.profile() | |
def post(self): | |
c1 = Counter( | |
name = 'count_something_unitless', | |
documentation = 'A summary', | |
labelnames = ['label1', 'label2'], | |
namespace = 'manage.project.demo_task', | |
labelvalues = ['a' 'b'] | |
) | |
c1.inc(20) | |
c.labels('value3', 'value4').inc(10) | |
c = Counter( | |
name = 'count_something_unitless', | |
documentation = 'A summary', | |
labelnames = ['label1', 'label2'], | |
namespace = 'manage.project.demo_task' | |
) | |
c.labels('value3', 'value4').inc(10) | |
# DO SOMETHING | |
c.labels('value5', 'value6').inc(10) | |
with c.labels('value7', 'value8').count_exceptions(exception = ValueError): | |
a = 1 / 0 | |
g = Guage( | |
name = 'payload_size', | |
documentation = 'measuring payload size', | |
labelnames = ['label1', 'label2'], | |
namespace = 'manage.project.demo_task', | |
unit = 'bytes', | |
labelvalues = ['X', 'Y'] | |
) | |
g.set(10) | |
s = Summary( | |
name = 'api_call_to_XYZ', | |
documentation = 'API call to XYZ', | |
labelnames = ['method'], | |
namespace = 'manage.project.demo_task', | |
labelvalues = None | |
) | |
s.labels('get').observe() | |
s.labels('post').observe(2) | |
with s.labels('post').time(): | |
pass | |
with s.labels('post').count_exceptions(): | |
#a = 1 / 0 | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment