forked from HappyFaceMonitoring/HappyFaceModules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ganglia.py
305 lines (268 loc) · 11.5 KB
/
Ganglia.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# -*- coding: utf-8 -*-
import hf
from sqlalchemy import FLOAT, Column
from lxml import etree
class Ganglia(hf.module.ModuleBase):
config_keys = {
'ganglia_xml': ('link to the source file', ''),
}
config_hint = ''
#comment unneccesary ones out
table_columns = [
# Column('machine_type', TEXT),
# Column('os_release', TEXT),
Column('bytes_out', FLOAT),
# Column('amga_state_time_wait', FLOAT),
# Column('cpu_idle', FLOAT),
# Column('mem_buffers', FLOAT),
# Column('part_max_used', FLOAT),
# Column('amga_state_time_wait_res', FLOAT),
Column('bytes_out_res', FLOAT),
Column('disk_free', FLOAT),
Column('disk_free_res', FLOAT),
# Column('cpu_nice', FLOAT),
# Column('cpu_nice_res', FLOAT),
# Column('cpu_speed', INT),
# Column('machine_type_1', TEXT),
Column('bytes_out_res_1', FLOAT),
Column('bytes_out_1', FLOAT),
# Column('cpu_speed_res', FLOAT),
# Column('cpu_idle_res', FLOAT),
Column('disk_free_1', FLOAT),
Column('disk_free_res_1', FLOAT),
# Column('cpu_nice_1', FLOAT),
# Column('cpu_nice_res_1', FLOAT),
# Column('cpu_speed_1', INT),
# Column('cpu_speed_res_1', FLOAT),
# Column('cpu_idle_1', FLOAT),
# Column('cpu_idle_res_1', FLOAT),
Column('load_fifteen', FLOAT),
Column('load_fifteen_res', FLOAT),
Column('load_fifteen_1', FLOAT),
Column('load_fifteen_res_1', FLOAT),
], []
def prepareAcquisition(self):
self.source_url = 'www.google.com'
# read configuration
if 'ganglia_xml' not in self.config: raise hf.exceptions.ConfigError('ganglia_xml option not set')
self.ganglia_xml = hf.downloadService.addDownload(self.config['ganglia_xml'])
# ..._res for results
def extractData(self):
data = {'source_url': self.ganglia_xml.getSourceUrl(),
'status': -1,
'LOCALTIME': '',
# 'machine_type': '',
'bytes_out': 0,
'bytes_out_res': 0.0,
# 'machine_type_1': '',
'bytes_out_1': 0,
'bytes_out_res_1': 0.0,
# 'amga_state_time_wait': '',
# 'amga_state_time_wait_res': 0.0,
# 'cpu_idle': '',
# 'cpu_idle_res': 0.0,
# 'mem_buffers': '',
# 'part_max_used': '',
'disk_free': 0,
'disk_free_res': 0,
# 'cpu_nice': '',
# 'cpu_nice_res': '',
# 'cpu_speed': '',
# 'cpu_speed_res': '',
'disk_free_1': 0,
'disk_free_res_1': 0,
# 'cpu_nice_1': '',
# 'cpu_nice_res_1': '',
# 'cpu_speed_1': '',
# 'cpu_speed_res_1': '',
# 'cpu_idle_1': '',
# 'cpu_idle_res_1': 0.0,
# 'aCu': '',
# 'os_release': '',
'load_fifteen': 0,
'load_fifteen_res': 0.0,
'load_fifteen_1': 0,
'load_fifteen_res_1': 0.0}
#source_tree = etree.parse(open(self.ganglia_xml.getTmpPath()))
source_tree = etree.parse(open('/home/happy/HappyFace/gangliatestdata'))
root = source_tree.getroot()
self.GRID_found = False
self.status = -1
for sec in root.findall("GRID"):
self.LOCALTIME = int(sec.get('LOCALTIME'))
#every layer with METRIC in the beginning
#test logic (status) in the if-statements where the ..._res variables are set
#can68 is AMGA Server
for fifth in root.findall(".//*[@NAME='can68.cc.kek.jp']/METRIC"):
self.GRID_found = True
# if fifth.get('NAME') == "amga.Connections.used":
# self.aCu = fifth.get('VAL')
# if fifth.get('NAME') == "os_release":
# self.os_release = fifth.get('VAL')
# if fifth.get('NAME') == "machine_type":
# self.machine_type = fifth.get('VAL')
if fifth.get('NAME') == "bytes_out":
self.bytes_out = float(fifth.get('VAL'))
if self.bytes_out <= 100000:
self.bytes_out_res = 0.5
if self.status != 0.0:
self.status = 0.5
else:
self.bytes_out_res = 1.0
# if fifth.get('NAME') == "amga-state.time_wait":
# self.amga_state_time_wait = fifth.get('VAL')
# if self.amga_state_time_wait > 0:
# self.amga_state_time_wait_res = 0.5
# if self.status != 0.0:
# self.status = 0.5
# else:
# self.amga_state_time_wait_res = 1.0
if fifth.get('NAME') == "load_fifteen":
self.load_fifteen = float(fifth.get('VAL'))
load_limit = 0.5
if self.load_fifteen >= load_limit:
self.load_fifteen_res = 0.5
if self.status != 0.0:
self.status = 0.5
elif self.load_fifteen >= 0.75:
self.load_fifteen_res = 0.0
self.status = 0.0
else:
self.load_fifteen_res = 1.0
# if fifth.get('NAME') == "cpu_idle":
# self.cpu_idle = fifth.get('VAL')
# if self.cpu_idle > 80:
# self.cpu_idle_res = 0.5
# if self.status != 0.0:
# self.status=0.5
# else:
# self.cpu_idle_res = 1.0
# if fifth.get('NAME') == "mem_buffers":
# self.mem_buffers = fifth.get('VAL')
# if fifth.get('NAME') == "part_max_used":
# self.part_max_used = fifth.get('VAL')
if fifth.get('NAME') == "disk_free":
self.disk_free = float(fifth.get('VAL'))
if self.disk_free <= 100:
self.disk_free_res = 0.5
if self.status != 0.0:
self.status = 0.5
elif self.disk_free <= 50:
self.disk_free_res = 0.0
self.status = 0.0
else:
self.disk_free_res = 1.0
# if fifth.get('NAME') == "cpu_nice":
# self.cpu_nice = fifth.get('VAL')
# if self.cpu_nice > 10:
# self.cpu_nice_res = 0.5
# if self.status != 0.0:
# elf.status = 0.5
# else:
# self.cpu_nice_res = 1.0
# if fifth.get('NAME') == "cpu_speed":
# self.cpu_speed = fifth.get('VAL')
# if self.cpu_speed < 3000:
# self.cpu_speed_res = 0.5
# if self.status != 0.0:
# self.status = 0.5
# else:
# self.cpu_speed_res = 1.0
#can61 is DIRAC Server --> variables end with ..._1
for sixth in root.findall(".//*[@NAME='can61.cc.kek.jp']/METRIC"):
self.GRID_found = True
# if sixth.get('NAME') == "machine_type":
# self.machine_type_1 = sixth.get('VAL')
if sixth.get('NAME') == "bytes_out":
self.bytes_out_1 = float(sixth.get('VAL'))
if self.bytes_out_1 <= 100000:
self.bytes_out_res_1 = 0.5
if self.status != 0.0:
self.status = 0.5
else:
self.bytes_out_res_1 = 1.0
if sixth.get('NAME') == "disk_free":
self.disk_free_1 = float(sixth.get('VAL'))
if self.disk_free_1 <= 100:
self.disk_free_res_1 = 0.5
if self.status != 0.0:
self.status = 0.5
elif self.disk_free_1 <= 50:
self.disk_free_res_1 = 0.0
self.status = 0.0
else:
self.disk_free_res_1 = 1.0
if sixth.get('NAME') == "load_fifteen":
self.load_fifteen_1 = float(sixth.get('VAL'))
if self.load_fifteen_1 >= 0.5:
self.load_fifteen_res_1 = 0.5
if self.status != 0.0:
self.status = 0.5
elif self.load_fifteen_1 >= 0.75:
self.load_fifteen_res_1 = 0.0
self.status = 0.0
else:
self.load_fifteen_res_1 = 1.0
# if sixth.get('NAME') == "cpu_nice":
# self.cpu_nice_1 = sixth.get('VAL')
# if self.cpu_nice_1 > 10:
# self.cpu_nice_res_1 = 0.5
# if self.status != 0.0:
# self.status = 0.5
# else:
# self.cpu_nice_res_1 = 1.0
# if sixth.get('NAME') == "cpu_speed":
# self.cpu_speed_1 = sixth.get('VAL')
# if self.cpu_speed_1 < 3000:
# self.cpu_speed_res_1 = 0.5
# if self.status != 0.0:
# self.status = 0.5
# else:
# self.cpu_speed_res_1 = 1.0
# if sixth.get('NAME') == "cpu_idle":
# self.cpu_idle_1 = sixth.get('VAL')
# if self.cpu_idle_1 > 80:
# self.cpu_idle_res_1 = 0.5
# if self.status != 0.0:
# self.status=0.5
# else:
# self.cpu_idle_res_1 = 1.0
if not self.GRID_found:
data['error_string'] = 'HOST was not found in data source.'
data['status'] = -1
return data
# definition of the database table values
data['LOCALTIME'] = self.LOCALTIME
# data['machine_type'] = self.machine_type
data['bytes_out'] = self.bytes_out
# data['amga_state_time_wait'] = self.amga_state_time_wait
# data['cpu_idle'] = self.cpu_idle
# data['mem_buffers'] = self.mem_buffers
# data['part_max_used'] = self.part_max_used
data['bytes_out_res'] = self.bytes_out_res
# data['amga_state_time_wait_res'] = self.amga_state_time_wait_res
# data['cpu_idle_res'] = self.cpu_idle_res
# data['os_release'] = self.os_release
data['status'] = self.status
data['disk_free'] = self.disk_free
data['disk_free_res'] = self.disk_free_res
# data['cpu_nice'] = self.cpu_nice
# data['cpu_nice_res'] = self.cpu_nice_res
# data['cpu_speed'] = self.cpu_speed
# data['cpu_speed_res'] = self.cpu_speed_res
# data['machine_type_1'] = self.machine_type_1
data['bytes_out_1'] = self.bytes_out_1
data['bytes_out_res_1'] = self.bytes_out_res_1
data['disk_free_1'] = self.disk_free_1
data['disk_free_res_1'] = self.disk_free_res_1
# data['cpu_nice_1'] = self.cpu_nice_1
# data['cpu_nice_res_1'] = self.cpu_nice_res_1
# data['cpu_speed_1'] = self.cpu_speed_1
# data['cpu_speed_res_1'] = self.cpu_speed_res_1
# data['cpu_idle_1'] = self.cpu_idle_1
# data['cpu_idle_res_1'] = self.cpu_idle_res_1
data['load_fifteen'] = self.load_fifteen
data['load_fifteen_res'] = self.load_fifteen_res
data['load_fifteen_1'] = self.load_fifteen_1
data['load_fifteen_res_1'] = self.load_fifteen_res_1
return data