forked from bmelim/zabdash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_memory.php
231 lines (175 loc) · 8.4 KB
/
group_memory.php
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
<?php
foreach( $groupID as $g ) {
$dbHosts = DBselect( 'SELECT h.hostid, h.name, h.status, h.available, h.snmp_available AS sa, h.snmp_disable_until AS sd, h.flags FROM hosts h, hosts_groups hg WHERE hg.groupid = '.$g.' AND h.hostid = hg.hostid ORDER BY h.name ASC');
//$dbHostsOk = DBselect( 'SELECT h.hostid, h.name, h.status, h.available, h.snmp_available AS sa, h.snmp_disable_until AS sd, h.flags FROM hosts h, hosts_groups hg WHERE hg.groupid = '.$g.' AND h.hostid = hg.hostid ORDER BY h.name ASC');
//get group name
$group = get_hostgroup_by_groupid($g);
$groupName = $group['name'];
echo '
<div class="col-md-12 col-sm-12">
<h3 style="color:#000 !important; margin-top: 15px; margin-bottom:15px;"> '.$groupName.'</h3>
</div> ';
$md = 12;
while ($hosts = DBFetch($dbHosts)) {
//if($hosts['status'] == 0 && $hosts['flags'] == 0) {
if($hosts['available'] == 1 ) { $keyValue = 'vm.memory.size'; }
else { $keyValue = 'inbytes'; }
// get all items
$mems = $api->itemGet(array(
'output' => 'extend',
'hostids' => $hosts['hostid'],
'search' => array('key_' => $keyValue)
));
// print Mem
foreach($mems as $mem) {
if($hosts['available'] == 1 ) {
$searchValSize = 'total';
//$searchValSize1 = 'total';
$searchValUsed = 'free';
$searchValUsed1 = 'available';
$memSize = get_item_values($mem->itemid, $searchValSize);
$memUsed = get_item_values_or($mem->itemid, $searchValUsed,$searchValUsed1);
//$memUsed = ($memSize['value_max'] - $memUsed['value_max']);
//Size
if($memSize['value_max'] != 0 || get_item_label($memSize['key_']) != '') {
$arrSizeMem[] = get_item_label($memSize['key_']).",".$memSize['value_max'];
}
if($memUsed['name'] != '') {
if($memUsed['value_max'] != 0) {
$arrUsedMem[] = get_item_label($memUsed['key_']).",". $memUsed['value_max'];
}
}
$zbx_agent = 1;
}
else {
$searchValSize = 'hrStorageSizeinBytes';
$searchValUsed = 'hrStorageUsedinBytes';
//$searchValSize = 'sysMemorySizeinBytes'; $searchValUsed = 'sysMemoryUsedinBytes';
$memSize = get_item_values($mem->itemid, $searchValSize);
$memUsed = get_item_values($mem->itemid, $searchValUsed);
//Size
if($memSize['value_max'] != 0 || get_item_label($memSize['key_']) != '') {
$label = get_item_label($memSize['key_']);
if(stripos($label,"memory") != '') {
$arrSizeMem[] = $label.",".$memSize['value_max'];
}
}
if($memUsed['name'] != '') {
if($memUsed['value_max'] != 0) {
$label = get_item_label($memUsed['key_']);
if(stripos($label,"memory") != '') {
$arrUsedMem[] = $label.",".$memUsed['value_max'];
}
}
}
$zbx_agent = 0;
}
}
sort($arrSizeMem);
sort($arrUsedMem);
//print mem size
for($n=0;$n<count($arrUsedMem);$n++) {
$u = explode(",",$arrUsedMem[$n]);
if($u[0] != 0 || $u[0] != '') {
if(strstr($u[0],":") == '') {
$arrUsedMem2[] = $u[0].",".$u[1];
}
}
}
if($arrSizeMem[0] != '') {
//hosts
if($hosts['sd'] <> 0) { $conn = "Offline"; $cor = "#E3573F"; } else { $conn = "Online"; $cor = "#4BAC64"; }
$dbIP = DBSelect('SELECT DISTINCT ip FROM interface WHERE hostid ='.$hosts['hostid']);
$IP = DBFetch($dbIP);
echo "<div class='col-md-".$md." col-sm-".$md."' style='margin-bottom:0px;'>";
echo "<table class='box table table-striped table-hover table-condensed' border='0' width='50%' style='border:1px solid #f2f2f2;'>
<thead>
<tr>
<th style='background:".$cor."; width:1%;' title='".$conn."'></th>
<th colspan='1' class='linkb' style='width:50%; font-weight:bold; text-align:left;'><a href='host_detail.php?hostid=".$hosts['hostid']."'> ".$hosts['name']." </a></th>
<th colspan='1' style='width:18%; text-align:left;'>". $labels['Used'] ."</th>
<th colspan='1' style='text-align:left;'> ". _('Total') ." </th>
<th colspan='1' style='text-align:left;'> % ". $labels['Used'] ." </th>
</tr>
</thead>
<tbody>\n";
//memory size
for($n=0;$n<count($arrSizeMem);$n++) {
$s = explode(",",$arrSizeMem[$n]);
$arrSizeMem2[] = $s[0].",".$s[1];
}
// memory used
for($n=0;$n<count($arrUsedMem);$n++) {
$u = explode(",",$arrUsedMem2[$n]);
$arrUsedMem3[] = $u[0].",".$u[1];
}
for($i=0;$i < count($arrUsedMem2);$i++) {
$s = explode(",",$arrSizeMem2[$i]);
$u = explode(",",$arrUsedMem3[$i]);
if($s[1] != 0) {
if($zbx_agent == 0) {$barra = round((100*($u[1]))/$s[1],1);}
if($zbx_agent == 1) {$barra = round((100*($s[1] - $u[1]))/$s[1],1);}
}
else { $barra = 0; }
$barraValue = $barra;
// cor barra
if($barra >= 100) { $cor = "progress-bar-danger"; $perc_cor = "#fff"; $barraValue = 100;}
if($barra >= 80 and $barra <= 100) { $cor = "progress-bar-danger"; $perc_cor = "#fff"; }
if($barra >= 61 and $barra <= 79) { $cor = "progress-bar-warning"; $perc_cor = "#fff"; }
if($barra >= 26 and $barra <= 60) { $cor = " "; $perc_cor = "#fff"; }
if($barra >= 0 and $barra <= 25) { $cor = "progress-bar-success"; $perc_cor = "#000";}
if($barra < 0) { $cor = "progress-bar-danger"; $barra = 0; }
if($s[0] != 'total') { $memName = $s[0]; }
else { $memName = "Memory"; }
if($zbx_agent == 0) {$usada = formatBytes($u[1],1);}
if($zbx_agent == 1) {$usada = formatBytes($s[1] - $u[1],1);}
echo "<tr style='text-align:left;'>\n";
echo " <td colspan='2'>". $memName ."</td>\n";
echo " <td colspan='1'>". $usada ."</td>\n";
echo " <td colspan='1'>". formatBytes($s[1],1) ."</td>\n";
echo "<td width='15%' style='padding-right:15px; '>
<div style='font-size:13px; position:absolute; vertical-align:middle; color:".$perc_cor.";'> ".$barra."%</div>
<div class='progress-bar ". $cor ." progress-bar ' role='progressbar' aria-valuenow='".$barra."' aria-valuemin='0' aria-valuemax='100' style='text-align:left; width: ".$barraValue."%;'> </div>
</td>\n";
echo "</tr>\n";
//}
//}
//}
}
unset($arrSizeMem);
unset($arrSizeMem2);
unset($arrUsedMem);
unset($arrUsedMem2);
unset($arrUsedMem3);
echo "</tbody></table>\n";
echo "</div>\n";
echo "<div style='margin-bottom:60px;'></div>\n";
}
else {
//hosts
if($hosts['sd'] <> 0) { $conn = "Offline"; $cor = "#E3573F"; } else { $conn = "Online"; $cor = "#4BAC64"; }
echo "<div class='col-md-".$md." col-sm-".$md."' style='margin-bottom:0px;'>";
echo "<table class='box table table-striped table-hover table-condensed' border='0' width='50%' style='border:1px solid #f2f2f2; '>
<thead>
<tr>
<th style='background:".$cor."; width:1%;' title='".$conn."'></th>
<th colspan='1' class='linkb' style='width:50%; font-weight:bold; text-align:left;'><a href='host_detail.php?hostid=".$hosts['hostid']."'> ".$hosts['name']." </a></th>
<th colspan='1' style='width:18%; text-align:left;'>". $labels['Used'] ."</th>
<th colspan='1' style='text-align:left;'> ". _('Total') ." </th>
<th colspan='1' style='text-align:left;'> % ". $labels['Used'] ." </th>
</tr>
</thead>
<tbody>\n";
echo "<tr style='text-align:left;'>";
echo " <td colspan='2'>No data</td>";
echo " <td colspan='1'></td>";
echo " <td colspan='1'></td>";
echo "<td width='15%' style='padding-right:15px;'></td>";
echo "</tr>\n";
echo "</tbody></table>\n";
echo "</div>\n";
echo "<div style='margin-bottom:60px;'></div>\n";
}
}
}
?>