-
-
Save suhaasprasad/97c309a9dc0af014223daefb53fa904b to your computer and use it in GitHub Desktop.
SAMPLE API INTERFACE
This file contains 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
MEASURE_DEMO_TASK_NAMESPACE = 'manage.project.demo_task' | |
MEASURE_DEMO_TASK_PROFILE_DOCUMENTATION = 'Measure throughput, latency and errors for demo task' | |
MEASURE_DEMO_TASK_STRIPE_CALL = 'stripe_call' | |
MEASURE_DEMO_TASK = Profile( | |
documentation = MEASURE_DEMO_TASK_PROFILE_DOCUMENTATION, | |
namespace = MEASURE_DEMO_TASK_NAMESPACE | |
) |
This file contains 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 | |
class DemoTaskHandler(TaskHandler): | |
@MEASURE_DEMO_TASK.profile() | |
def post(self): | |
MEASURE_DEMO_TASK.increment(MEASURE_DEMO_TASK_STRIPE_CALL, | |
10, | |
label='status_code', | |
value='200') | |
MEASURE_DEMO_TASK.guage(MEASURE_DEMO_TASK_STRIPE_CALL, | |
10, | |
label='status_code', | |
value='200') | |
MEASURE_DEMO_TASK.time(MEASURE_DEMO_TASK_STRIPE_CALL, | |
10, | |
label='status_code', | |
value='200') | |
MEASURE_DEMO_TASK.count_exceptions(MEASURE_DEMO_TASK_STRIPE_CALL, | |
10, | |
label='status_code', | |
value='200') | |
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