forked from wavefrontHQ/wavefront-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
212 lines (171 loc) · 7.84 KB
/
example.py
File metadata and controls
212 lines (171 loc) · 7.84 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
"""Wavefront SDK Usage Example."""
import sys
import time
import uuid
from wavefront_sdk.client_factory import WavefrontClientFactory
from wavefront_sdk.direct import WavefrontDirectClient
from wavefront_sdk.entities.histogram import histogram_granularity
from wavefront_sdk.proxy import WavefrontProxyClient
def send_metrics_via_proxy(proxy_client):
"""Send a distribution using proxy client."""
proxy_client.send_metric(
'python' + str(sys.version_info[0]) + '.proxy.new york.power.usage',
42422.0, None, 'localhost', None)
def send_delta_counter_via_proxy(proxy_client):
"""Send a delta counter using proxy client."""
proxy_client.send_delta_counter(
'python' + str(sys.version_info[0]) + '.delta.proxy.counter',
1.0, 'localhost', None)
def send_histogram_via_proxy(proxy_client):
"""Send a histogram using proxy client."""
proxy_client.send_distribution(
'python' + str(sys.version_info[0]) + '.proxy.request.latency',
[(30, 20), (5.1, 10)], {histogram_granularity.DAY,
histogram_granularity.HOUR,
histogram_granularity.MINUTE},
None, 'appServer1', {'region': 'us-west'})
def send_tracing_span_via_proxy(proxy_client):
"""Send a tracing span using proxy client."""
proxy_client.send_span(
'getAllUsersFromPythonProxy', 1533529977, 343500, 'localhost',
uuid.UUID('7b3bf470-9456-11e8-9eb6-529269fb1459'),
uuid.UUID('0313bafe-9457-11e8-9eb6-529269fb1459'),
[uuid.UUID('2f64e538-9457-11e8-9eb6-529269fb1459')], None,
[('application', 'Wavefront'),
('http.method', 'GET')], None)
def send_metrics_via_direct_ingestion(direct_ingestion_client):
"""Send a metric through direct ingestion."""
direct_ingestion_client.send_metric(
'python' + str(sys.version_info[0]) + '.direct.new york.power.usage',
42422.0, None, 'localhost', None)
def send_delta_counter_via_direct_ingestion(direct_ingestion_client):
"""Send a delta counter through direct ingestion."""
direct_ingestion_client.send_delta_counter(
'python' + str(sys.version_info[0]) + '.delta.direct.counter',
1.0, 'localhost', None)
def send_histogram_via_direct_ingestion(direct_ingestion_client):
"""Send a histogram through direct ingestion."""
direct_ingestion_client.send_distribution(
'python' + str(sys.version_info[0]) + '.direct.request.latency',
[(30, 20), (5.1, 10)], {histogram_granularity.DAY,
histogram_granularity.HOUR,
histogram_granularity.MINUTE},
None, 'appServer1',
{'region': 'us-west'})
def send_tracing_span_via_direct_ingestion(direct_ingestion_client):
"""Send a tracing span through direct ingestion."""
direct_ingestion_client.send_span(
'getAllUsersFromPythonDirect', 1533529977, 343500, 'localhost',
uuid.UUID('7b3bf470-9456-11e8-9eb6-529269fb1459'),
uuid.UUID('0313bafe-9457-11e8-9eb6-529269fb1459'),
[uuid.UUID('2f64e538-9457-11e8-9eb6-529269fb1459')],
None, [('application', 'Wavefront'), ('http.method', 'GET')], None)
def send_event_via_proxy(wavefront_proxy_client):
"""Send an event via proxy."""
wavefront_proxy_client.send_event(
'event_via_proxy',
1590650592,
1590650692,
"localhost",
["env:", "test"],
{"severity": "info",
"type": "backup",
"details": "broker backup"})
def send_event_via_direct_ingestion(direct_ingestion_client):
"""Send an event through direct ingestion."""
direct_ingestion_client.send_event(
'event_via_direct',
1590730937,
1590731037,
"localhost",
["env:", "test"],
{"severity": "severe",
"type": "backup",
"details": "broker backup"})
def send_metrics_multi_client(proxy_client):
"""Send a metric using multi client."""
proxy_client.send_metric(
'python' + str(sys.version_info[0])
+ '.multi.client.new york.power.usage',
42422.0, None, 'localhost', None)
def send_delta_counter_multi_client(proxy_client):
"""Send a delta counter using multi client."""
proxy_client.send_delta_counter(
'python' + str(sys.version_info[0])
+ '.delta.multi.client.counter',
1.0, 'localhost', None)
def send_histogram_multi_client(proxy_client):
"""Send a histogram using multi client."""
proxy_client.send_distribution(
'python' + str(sys.version_info[0]) + '.multi.client.request.latency',
[(30, 20), (5.1, 10)],
{histogram_granularity.DAY, histogram_granularity.HOUR,
histogram_granularity.MINUTE},
None, 'appServer1', {'region': 'us-west'})
def send_tracing_span_multi_client(proxy_client):
"""Send a tracing span using multi client."""
proxy_client.send_span(
'getAllUsersFromPythonMultiClient',
int(time.time()), 34350, 'localhost',
uuid.UUID('7b3bf470-9456-11e8-9eb6-529269fb1459'),
uuid.UUID('0313bafe-9457-11e8-9eb6-529269fb1459'),
[uuid.UUID('2f64e538-9457-11e8-9eb6-529269fb1459')], None,
[('application', 'Wavefront'), ('service', 'testService'),
('cluster', 'testCluster'), ('shard', 'testShard'),
('http.method', 'GET')], None)
def send_event_via_multi_client(direct_ingestion_client):
"""Send an event through multi ingestion."""
direct_ingestion_client.send_event(
'event_via_multi_client',
time.time(),
None,
"localhost",
["env:", "test"],
{"severity": "severe",
"type": "backup",
"details": "broker backup"})
if __name__ == '__main__':
wavefront_server = sys.argv[1]
token = sys.argv[2]
proxy_host = None if len(sys.argv) <= 3 else sys.argv[3]
metrics_port = None if len(sys.argv) <= 4 else sys.argv[4]
distribution_port = None if len(sys.argv) <= 5 else sys.argv[5]
tracing_port = None if len(sys.argv) <= 6 else sys.argv[6]
event_port = None if len(sys.argv) <= 7 else sys.argv[7]
# Proxy url: proxy://<proxy-host-ip>:2878
proxy_url = None if len(sys.argv) <= 8 else sys.argv[8]
# Direct url: https://<api-key>@<cluster-name>.wavefront.com
direct_url = None if len(sys.argv) <= 9 else sys.argv[9]
wavefront_proxy_client = WavefrontProxyClient(
host=proxy_host,
metrics_port=metrics_port,
distribution_port=distribution_port,
tracing_port=tracing_port,
event_port=event_port)
wavefront_direct_client = WavefrontDirectClient(wavefront_server, token)
multi_client_factory = WavefrontClientFactory()
multi_client_factory.add_client(proxy_url)
multi_client_factory.add_client(direct_url)
multi_client = multi_client_factory.get_client()
try:
while True:
send_metrics_via_proxy(wavefront_proxy_client)
send_histogram_via_proxy(wavefront_proxy_client)
send_tracing_span_via_proxy(wavefront_proxy_client)
send_delta_counter_via_proxy(wavefront_proxy_client)
send_event_via_proxy(wavefront_proxy_client)
send_metrics_via_direct_ingestion(wavefront_direct_client)
send_histogram_via_direct_ingestion(wavefront_direct_client)
send_tracing_span_via_direct_ingestion(wavefront_direct_client)
send_delta_counter_via_direct_ingestion(wavefront_direct_client)
send_event_via_direct_ingestion(wavefront_direct_client)
send_metrics_multi_client(multi_client)
send_histogram_multi_client(multi_client)
send_tracing_span_multi_client(multi_client)
send_delta_counter_multi_client(multi_client)
send_event_via_multi_client(multi_client)
time.sleep(1)
finally:
wavefront_proxy_client.close()
wavefront_direct_client.close()
multi_client.close()