-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgeneric_usecase.rb
45 lines (36 loc) · 1.35 KB
/
generic_usecase.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
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require './lib/signalfx'
puts 'SignalFx metrics reporting demo:'
token = ARGV[0] # Your SignalFx API access token
if token.nil? || token.empty?
puts '
SignalFx API access token not defined. Please specify token in command line.
$ ./generic_usecase.rb YOUR_TOKEN
'
exit 0
end
#create client instance with SignalFx API access token
client = SignalFx.new token, enable_aws_unique_id: false, timeout: 3000
puts 'SignalFx metrics reporting demo:'
#run loop to send datapoints to SignalFx
counter = 0
while true do
puts "Send datapoints ##{counter}"
timestamp = (Time.now.to_i * 1000).to_i
gauges = [{:metric => 'test.cpu', :value => counter % 10, :timestamp => timestamp}]
counters = [{:metric => 'cpu_cnt', :value => counter % 2, :timestamp => timestamp}]
client.send(gauges: gauges, counters: counters)
if counter % 100 == 0
event_type = 'deployments'
version = Time.now.strftime("%Y-%m-%d") + '-' + counter.to_s
dimensions =
{host: 'myhost',
service: 'myservice',
instance: 'myinstance'}
properties = {version: version}
event_category = SignalFxClient::EVENT_CATEGORIES[:ALERT]
client.send_event(event_type, event_category: event_category, dimensions: dimensions, properties: properties)
end
counter +=1
sleep(1)
end