forked from signalfx/signalfx-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic_usecase.py
executable file
·48 lines (42 loc) · 1.6 KB
/
generic_usecase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# Copyright (C) 2016 SignalFx, Inc. All rights reserved.
import argparse
import os
import logging
import sys
import time
sys.path.insert(0, os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..'))
import signalfx # noqa
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='SignalFx metrics reporting demo')
parser.add_argument('token', help='Your SignalFx API access token')
options = parser.parse_args()
client = signalfx.SignalFx()
ingest = client.ingest(options.token)
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
try:
i = 0
while True:
ingest.send(gauges=[{
'metric': 'test.cpu',
'value': i % 10}],
counters=[{
'metric': 'cpu_cnt',
'value': i % 2}])
i += 1
if i % 10 == 0: # Factoring for reduced activity for events
version = '{date}-{version}'.format(
date=time.strftime('%Y-%m-%d'), version=i)
ingest.send_event(event_type='deployments',
category='USER_DEFINED',
dimensions={
'host': 'myhost',
'service': 'myservice',
'instance': 'myinstance'},
properties={'version': version},
timestamp=time.time() * 1000)
time.sleep(0.5)
except KeyboardInterrupt:
pass