-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobe
executable file
·64 lines (56 loc) · 1.22 KB
/
probe
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
#!/usr/bin/env ruby
load './environment.rb'
require 'socket'
VAIRE_ENDPOINT = "#{ENV.fetch('VAIRE_URL')}/messages"
SERVICE_NAME = "#{ENV.fetch('VAIRE_SERVICE_NAME') { 'VAIRE-PROBE' }}"
BASE_PAYLOAD = {
data: {
type: :states,
attributes: {}
}
}.freeze
def cpu_from_snapshot(snap)
snap.cpus.collect do |cpu|
{
idle: cpu.idle,
system: cpu.system,
user: cpu.user,
nice: cpu.nice
}
end
end
def data_from_snapshot(snap)
{
load: [
snap.load_average.one_minute,
snap.load_average.five_minutes,
snap.load_average.fifteen_minutes
],
memory: {
free: snap.memory.free,
wired: snap.memory.wired,
active: snap.memory.active
},
cpu: cpu_from_snapshot(snap),
boot: snap.boot_time.utc
}
end
def send_telemetry(attr)
payload = BASE_PAYLOAD.dup
payload[:data][:attributes] = attr
Typhoeus.post(VAIRE_ENDPOINT,
body: payload,
headers: { 'X-VAIRE-TOKEN' => 'ainunindale' })
end
def perform
snap = Vmstat.snapshot
attrs = {
service: SERVICE_NAME,
machine: Socket.gethostname,
summary: :ok,
stats: data_from_snapshot(snap),
ocurred_at: snap.at.utc
}
send_telemetry(attrs)
end
perform