-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflux_status.rb
99 lines (83 loc) · 1.76 KB
/
influx_status.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
require 'sys/uptime'
require 'paint'
require 'influxdb'
include Sys
@influxdb = InfluxDB::Client.new "umz_stats", :username => "root", :password => "root"
@disks = ["/dev/sdb", "/dev/sdc"]
def disk_temp
@disks.each do | dks |
temp = `hddtemp #{dks} | awk -F: '{print $3}'`
temp = temp.chomp[0..-3]
#"#{dks} = #{temp}".chomp
data = {
:temp => temp.to_f,
:disk => dks
}
@influxdb.write_point("disks", data)
end
end
def mdhealth
status = `cat /proc/mdstat`
s = status.match(/(md[0-9]+)[\w\W]+?(\[[U_]+\])/s).captures
"#{s[0]} -> #{s[1]}"
data = {
:status => s[1],
:array=> s[0]
}
@influxdb.write_point("md", data)
end
def cpu_temp
s = `sensors | grep Core | awk -F: '{print $2}'`
s.split("\n").each_with_index do |line, index|
parts = line.split(' ')
temp = parts.first
data = {
:temp => temp[0..-3].to_f,
:core => index+1
}
@influxdb.write_point("cpu", data)
end
end
def diskusage
df = `df --total 2>/dev/null`
lines = df.split("\n")
points = [lines[1], lines[lines.length-2]]
points.each do |p|
parts = p.split(" ")
"#{parts[5]} #{parts[2]} / #{parts[1]} (#{parts[4]})"
data = {
:usedp => parts[4][0..-2].to_i,
:used => parts[2].to_i,
:disk => parts[5]
}
@influxdb.write_point("space", data)
end
end
def load
l = `cat /proc/loadavg`
p = l.split(" ")
"#{p[0]} #{p[1]} #{p[2]}"
data = {
:one => p[0].to_f,
:five => p[1].to_f,
:fifteen => p[2].to_f
}
@influxdb.write_point("load", data)
end
def mem
o = `free -b`
pt = o.split(" ")
total = pt[7].to_i / 1024
used = pt[8].to_i / 1024
"#{used}mb / #{total}mb"
data = {
:value => pt[15].to_i
}
@influxdb.write_point("mem", data)
end
disk_temp
diskusage
cpu_temp
mdhealth
load
mem