-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_usage.rb
47 lines (36 loc) · 1.09 KB
/
basic_usage.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
require 'bundler/setup'
require 'major_tom/client'
require 'logger'
# The MajorTom::Client uses eventmachine and expects you to start the reactor wherever is appropriate for your application.
# Example usage:
# MT_URI=wss://your.majortom.host/gateway_api/v1.0 MT_GATEWAY_TOKEN=1234567890abcdefg ruby basic_usage.rb
uri = ENV['MT_URI']
gateway_token = ENV['MT_GATEWAY_TOKEN']
default_system = ENV['MT_SYSTEM'] || 'some-satellite'
EM.run do
logger = Logger.new(STDOUT)
logger.level = Logger::DEBUG
client = MajorTom::Client.new(
uri: uri,
gateway_token: gateway_token,
logger: logger,
default_fields: { system: default_system }
)
client.on_hello do |hello_message|
p hello_message
end
client.on_command do |command|
p command
end
client.on_error do |error|
p error
end
client.on_rate_limit do |rate_limit|
p rate_limit
end
client.connect!
client.telemetry([
{ subsystem: 'some-subsystem', metric: "random_metric1", value: rand, timestamp: Time.now },
{ subsystem: nil, metric: "random_metric2", value: rand, timestamp: Time.now },
])
end