This repository has been archived by the owner on Jun 30, 2018. It is now read-only.
/
check.py
201 lines (179 loc) · 5.27 KB
/
check.py
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/python
# Copyright 2012 Peter Hultqvist, phq@silentorbit.com
# Distributed under the terms of the GNU Affero General Public License
#
# This file is called to make sure the rrd-files exists and create them if not
#
# Configuration:
# The variables in the begining can be modified to change interval for logging
import os, rrdtool, sys
# Minutes per month
month=44640
# minutes per year
year=35040*15
step = 60
heartbeat = 120
rra_month = "RRA:AVERAGE:0.5:1:%i" % month
rra_month_min = "RRA:MIN:0.5:1:%i" % month
rra_month_max = "RRA:MAX:0.5:1:%i" % month
rra_year = "RRA:AVERAGE:0.5:15:%i" % (year/15)
rra_year_min = "RRA:MIN:0.5:15:%i" % (year/15)
rra_year_max = "RRA:MAX:0.5:15:%i" % (year/15)
if __name__ == "__main__":
print("\nThese checks are done automatically when update.py is run\n")
sys.exit(-1)
def process_check(user):
path = "rrd/user-"+user+".rrd"
if os.path.exists(path):
return
print("Creating process rrd for user "+user)
rrdtool.create(path, "--step", str(step),
"DS:rss:GAUGE:%i:0:U" % heartbeat,
"DS:vsz:GAUGE:%i:0:U" % heartbeat,
"DS:pcpu:GAUGE:%i:0:U" % heartbeat,
rra_month,
rra_month_min,
rra_month_max,
rra_year,
rra_year_min,
rra_year_max
)
def bean_check():
path = "rrd/beancounters.rrd"
if os.path.exists(path):
return
print("Creating process rrd for beancounters")
rrdtool.create(path, "--step", str(step),
"DS:kmemsize:GAUGE:%i:0:U" % heartbeat,
"DS:kmemsize_fail:COUNTER:%i:0:U" % heartbeat,
"DS:lockedpages:GAUGE:%i:0:U" % heartbeat,
"DS:lockedpages_fail:COUNTER:%i:0:U" % heartbeat,
"DS:privvmpages:GAUGE:%i:0:U" % heartbeat,
"DS:privvmpages_fail:COUNTER:%i:0:U" % heartbeat,
"DS:shmpages:GAUGE:%i:0:U" % heartbeat,
"DS:shmpages_fail:COUNTER:%i:0:U" % heartbeat,
"DS:numproc:GAUGE:%i:0:U" % heartbeat,
"DS:numproc_fail:COUNTER:%i:0:U" % heartbeat,
"DS:physpages:GAUGE:%i:0:U" % heartbeat,
"DS:physpages_fail:COUNTER:%i:0:U" % heartbeat,
"DS:vmguarpages:GAUGE:%i:0:U" % heartbeat,
"DS:vmguarpages_fail:COUNTER:%i:0:U" % heartbeat,
"DS:oomguarpages:GAUGE:%i:0:U" % heartbeat,
"DS:oomguarpages_fail:COUNTER:%i:0:U" % heartbeat,
"DS:numtcpsock:GAUGE:%i:0:U" % heartbeat,
"DS:numtcpsock_fail:COUNTER:%i:0:U" % heartbeat,
"DS:numflock:GAUGE:%i:0:U" % heartbeat,
"DS:numflock_fail:COUNTER:%i:0:U" % heartbeat,
"DS:numpty:GAUGE:%i:0:U" % heartbeat,
"DS:numpty_fail:COUNTER:%i:0:U" % heartbeat,
"DS:numsiginfo:GAUGE:%i:0:U" % heartbeat,
"DS:numsiginfo_fail:COUNTER:%i:0:U" % heartbeat,
"DS:tcpsndbuf:GAUGE:%i:0:U" % heartbeat,
"DS:tcpsndbuf_fail:COUNTER:%i:0:U" % heartbeat,
"DS:tcprcvbuf:GAUGE:%i:0:U" % heartbeat,
"DS:tcprcvbuf_fail:COUNTER:%i:0:U" % heartbeat,
"DS:othersockbuf:GAUGE:%i:0:U" % heartbeat,
"DS:othersockbuf_fail:COUNTER:%i:0:U" % heartbeat,
"DS:dgramrcvbuf:GAUGE:%i:0:U" % heartbeat,
"DS:dgramrcvbuf_fail:COUNTER:%i:0:U" % heartbeat,
"DS:numothersock:GAUGE:%i:0:U" % heartbeat,
"DS:numothersock_fail:COUNTER:%i:0:U" % heartbeat,
"DS:dcachesize:GAUGE:%i:0:U" % heartbeat,
"DS:dcachesize_fail:COUNTER:%i:0:U" % heartbeat,
"DS:numfile:GAUGE:%i:0:U" % heartbeat,
"DS:numfile_fail:COUNTER:%i:0:U" % heartbeat,
"DS:numiptent:GAUGE:%i:0:U" % heartbeat,
"DS:numiptent_fail:COUNTER:%i:0:U" % heartbeat,
rra_month,
rra_month_min,
rra_month_max,
rra_year,
rra_year_min,
rra_year_max
)
def cpu_check():
path = "rrd/cpu.rrd"
if os.path.exists(path):
return
print("Creating cpu rrd")
rrdtool.create(path, "--step", str(step),
"DS:user:COUNTER:%i:0:U" % heartbeat,
"DS:nice:COUNTER:%i:0:U" % heartbeat,
"DS:sys:COUNTER:%i:0:U" % heartbeat,
"DS:idle:COUNTER:%i:0:U" % heartbeat,
"DS:iowait:COUNTER:%i:0:U" % heartbeat,
"DS:irq:COUNTER:%i:0:U" % heartbeat,
"DS:softirq:COUNTER:%i:0:U" % heartbeat,
rra_month,
rra_month_min,
rra_month_max,
rra_year,
rra_year_min,
rra_year_max
)
def net_check(interface):
path = "rrd/net-%s.rrd" % interface
if os.path.exists(path):
return
print("Creating net rrd")
rrdtool.create(path, "--step", str(step),
"DS:in:DERIVE:%i:0:U" % heartbeat,
"DS:out:DERIVE:%i:0:U" % heartbeat,
rra_month,
rra_month_min,
rra_month_max,
rra_year,
rra_year_min,
rra_year_max
)
def disk_check(device):
path = "rrd/disk-"+device+".rrd"
if os.path.exists(path):
return
print("Creating disk rrd")
rrdtool.create(path, "--step", str(step),
"DS:size:GAUGE:%i:0:U" % heartbeat,
"DS:used:GAUGE:%i:0:U" % heartbeat,
rra_month,
rra_year
)
def ping_check(host):
path = "rrd/ping-"+host+".rrd"
if os.path.exists(path):
return
rrdtool.create(path, "--step", str(step),
"DS:rtt:GAUGE:%i:0:U" % heartbeat,
rra_month,
rra_month_min,
rra_month_max,
rra_year,
rra_year_min,
rra_year_max
)
def mem_check():
path = "rrd/mem.rrd"
swap = "rrd/swap.rrd"
if os.path.exists(path) == False:
rrdtool.create(path, "--step", str(step),
"DS:used:GAUGE:%i:0:U" % heartbeat,
"DS:buffers:GAUGE:%i:0:U" % heartbeat,
"DS:cached:GAUGE:%i:0:U" % heartbeat,
"DS:swap:GAUGE:%i:0:U" % heartbeat,
rra_month,
rra_month_min,
rra_month_max,
rra_year,
rra_year_min,
rra_year_max
)
if os.path.exists(swap) == False:
rrdtool.create(swap, "--step", str(step),
"DS:swap:GAUGE:%i:0:U" % heartbeat,
rra_month,
rra_month_min,
rra_month_max,
rra_year,
rra_year_min,
rra_year_max
)
return