forked from signalfx/signalfx-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect-datapoints
executable file
·36 lines (28 loc) · 1.08 KB
/
collect-datapoints
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
#!/usr/bin/env python3
# Run a fake backend and dump datapoints as json output for later processing.
# Point the agent to this backend with these settings:
#
# signalFxAccessToken: test
# ingestUrl: http://localhost:4567
# apiUrl: http://localhost:4568
# Processing examples:
#
# Get all unique metric names:
# $ scripts/collect-datapoints | jq 'unique_by(.metric)[] | .metric'
import sys
import time
from google.protobuf import json_format
from tests.helpers.fake_backend import start
def run(collect_time_seconds=30):
with start(ingest_port=4567, api_port=4568) as fake_backend:
print("Waiting for first datapoint on %s" % (fake_backend.ingest_url,), file=sys.stderr)
while True:
if fake_backend.datapoints:
break
time.sleep(1)
print("Waiting %d seconds for datapoints" % (collect_time_seconds,), file=sys.stderr)
time.sleep(collect_time_seconds)
print("[" + ",".join([json_format.MessageToJson(m) for m in fake_backend.datapoints]) + "]")
print("Done", file=sys.stderr)
if __name__ == "__main__":
run()