forked from yogeshprasad/wavefront-sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.rb
124 lines (107 loc) · 4.72 KB
/
example.rb
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
# Script for ad-hoc experiments
#
# @author Yogesh Prasad Kurmi ([email protected])
require 'securerandom'
require 'set'
require_relative 'proxy'
require_relative 'direct'
# Wavefront Metrics Data format
# <metricName> <metricValue> [<timestamp>] source=<source> [pointTags]
#
# Example
# "new-york.power.usage 42422 1533529977 source=localhost datacenter=dc1"
def send_metrics_via_proxy(proxy_client)
proxy_client.send_metric(
"new-york.power.usage", 42422.0, nil, "localhost", {"datacenter"=>"dc1"})
puts "Sent metric: 'new-york.power.usage' to proxy"
end
# Wavefront Histogram Data format
# {!M | !H | !D} [<timestamp>] #<count> <mean> [centroids] <histogramName> source=<source>
# [pointTags]
# Example
# "!M 1533529977 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"
def send_histogram_via_proxy(proxy_client)
proxy_client.send_distribution(
"request.latency",
[[30, 20], [5.1, 10]], Set.new([DAY, HOUR, MINUTE]), nil, "appServer1", {"region"=>"us-west"})
puts "Sent histogram: 'request.latency' to proxy"
end
# Wavefront Tracing Span Data format
# <tracingSpanName> source=<source> [pointTags] <start_millis> <duration_milli_seconds>
# Example
# "getAllProxyUsers source=localhost
# traceId=7b3bf470-9456-11e8-9eb6-529269fb1459
# spanId=0313bafe-9457-11e8-9eb6-529269fb1459
# parent=2f64e538-9457-11e8-9eb6-529269fb1459
# application=WavefrontRuby http.method=GET service=TestRuby
# 1533529977 343500"
def send_tracing_span_via_proxy(proxy_client)
proxy_client.send_span(
"getAllProxyUsers", Time.now.to_i, 343500, "localhost",
SecureRandom.uuid, SecureRandom.uuid, [SecureRandom.uuid], nil,
{"application"=>"WavefrontRuby", "http.method"=>"GET", "service"=>"TestRuby"}, nil)
puts "Sent tracing span: 'getAllProxyUsers' to proxy"
end
# Wavefront Metrics Data format
# <metricName> <metricValue> [<timestamp>] source=<source> [pointTags]
#
# Example
# "ruby.direct.new-york.power.usage 42422 1533529977 source=localhost datacenter=dc1"
def send_metrics_via_direct_ingestion(direct_ingestion_client)
direct_ingestion_client.send_metric("ruby.direct.new york.power.usage",
42422.0, nil, "localhost", nil)
puts "Sending metrics 'ruby.direct.new-york.power.usage' via direct ingestion client"
end
# Wavefront Histogram Data format
# {!M | !H | !D} [<timestamp>] #<count> <mean> [centroids] <histogramName> source=<source>
# [pointTags]
# Example
# "!M 1533529977 #20 30.0 #10 5.1 ruby.direct.request.latency source=appServer1 region=us-west"
def send_histogram_via_direct_ingestion(direct_ingestion_client)
direct_ingestion_client.send_distribution(
"ruby.direct.request.latency", [[30, 20], [5.1, 10]], Set.new([DAY, HOUR, MINUTE]),
nil, "appServer1", {"region"=>"us-west"})
puts "Sending histogram 'ruby.direct.request.latency' via direct ingestion client"
end
# Wavefront Tracing Span Data format
# <tracingSpanName> source=<source> [pointTags] <start_millis> <duration_milli_seconds>
# Example
# "getAllUsersFromRubyDirect source=localhost
# traceId=7b3bf470-9456-11e8-9eb6-529269fb1459
# spanId=0313bafe-9457-11e8-9eb6-529269fb1459
# parent=2f64e538-9457-11e8-9eb6-529269fb1459
# application=WavefrontRuby http.method=GET service=TestRuby
# 1533529977 343500"
def send_tracing_span_via_direct_ingestion(direct_ingestion_client)
direct_ingestion_client.send_span(
"getAllUsersFromRubyDirect", Time.now.to_i, 343500, "localhost",
SecureRandom.uuid, SecureRandom.uuid, [SecureRandom.uuid],
nil, {"application"=>"WavefrontRuby", "http.method"=>"GET", "service"=>"TestRuby"}, nil)
puts "Sending tracing span 'getAllUsersFromRubyDirect' via direct ingestion client"
end
if __FILE__ == $0
wavefront_server = ARGV[0]
token = ARGV[1]
proxy_host = ARGV[2] ? ARGV[2] : nil
metrics_port = ARGV[3] ? ARGV[3] : nil
distribution_port = ARGV[4] ? ARGV[4] : nil
tracing_port = ARGV[5] ? ARGV[5] : nil
# create a client to send data via proxy
wavefront_proxy_client = Wavefront::WavefrontProxyClient.new(proxy_host, metrics_port, distribution_port, tracing_port)
# create a client to send data via direct ingestion
wavefront_direct_client = Wavefront::WavefrontDirectIngestionClient.new(wavefront_server, token)
begin
while true do
send_metrics_via_proxy(wavefront_proxy_client)
send_histogram_via_proxy(wavefront_proxy_client)
send_tracing_span_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)
sleep 1
end
ensure
wavefront_proxy_client.close
wavefront_direct_client.close
end
end