-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathqs_get_list.php
executable file
·160 lines (157 loc) · 8.36 KB
/
qs_get_list.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
#!/usr/bin/env php
<?php
require_once(dirname(__FILE__).'/xml2array.php');
/**
* get_qs_list()
*
* @return
*/
function get_qs_list()
{
$dir = __DIR__;
$url = 'https://my-web-3.interserver.net/qs_queue.php';
if (!file_exists('/usr/sbin/vzctl')) {
$out = trim(`export PATH="/usr/local/bin:/usr/local/sbin:\$PATH:/bin:/usr/bin:/sbin:/usr/sbin";virsh list --all | grep -v -e "State\$" -e "------\$" -e "^\$" | awk "{ print \\\$2 \" \" \\\$3 }"`);
$lines = explode("\n", $out);
$servers = array();
$cmd = '';
foreach ($lines as $serverline) {
if (trim($serverline) != '') {
$parts = explode(' ', $serverline);
$name = $parts[0];
$veid = $name;
//$veid = str_replace(array('windows', 'linux', 'qs'), array('', ''), $veid);
$status = $parts[1];
$out = `export PATH="/usr/local/bin:/usr/local/sbin:\$PATH:/bin:/usr/bin:/sbin:/usr/sbin";virsh dumpxml $name`;
$xml = xml2array($out, 1, 'attribute');
$server = array(
'type' => 'kvm',
'veid' => $veid,
'status' => $status,
'hostname' => $name,
'kmemsize' => $xml['domain']['memory']['value'],
);
if (isset($xml['domain']['devices']['interface'])) {
if (isset($xml['domain']['devices']['interface']['mac']['attr']['address'])) {
$server['mac'] = $xml['domain']['devices']['interface']['mac']['attr']['address'];
} elseif (isset($xml['domain']['devices']['interface'][0]['mac']['attr'])) {
$server['mac'] = $xml['domain']['devices']['interface'][0]['mac']['attr']['address'];
}
}
if (isset($xml['domain']['devices']['graphics']['attr']['port'])) {
$server['vnc'] = (int)$xml['domain']['devices']['graphics']['attr']['port'];
} elseif (isset($xml['domain']['devices']['graphics'][0]['attr']['port'])) {
foreach ($xml['domain']['devices']['graphics'] as $idx => $graphics) {
if (isset($graphics['attr']['port'])) {
$server[$graphics['attr']['type']] = (int)$graphics['attr']['port'];
}
}
}
if ($status == 'running') {
/*
$disk = trim(`{$dir}/vps_kvm_disk_usage.sh $name`);
if ($disk != '')
{
$dparts = explode(':', $disk);
$server['diskused'] = $dparts[2];
$server['diskmax'] = $dparts[1];
}
*/
if (isset($server['vnc'])) {
$port = $server['vnc'];
if ($port >= 5900) {
// vncsnapshot Encodings: raw copyrect tight hextile zlib corre rre zrle
/*
$cmd .= "if [ -e /usr/bin/timeout ]; then
timeout 30s ./vncsnapshot -dieblank -compresslevel 0 -quality 70 -vncQuality 7 -jpeg -fps 5 -count 1 -quiet -encodings raw :\$(($port - 5900)) shot_{$port}.jpg >/dev/null 2>&1;
else
./vncsnapshot -dieblank -compresslevel 0 -quality 70 -vncQuality 7 -jpeg -fps 5 -count 1 -quiet -encodings raw :\$(($port - 5900)) shot_{$port}.jpg >/dev/null 2>&1;
fi;\n";
*/
}
}
}
$servers[$veid] = $server;
}
}
//echo "CMD:$cmd\n";
//echo `$cmd`;
} else {
$out = `export PATH="/usr/local/bin:/usr/local/sbin:\$PATH:/bin:/usr/bin:/sbin:/usr/sbin";vzlist -a -o veid,numproc,status,ip,hostname,kmemsize,kmemsize.f,lockedpages,lockedpages.f,privvmpages,privvmpages.f,shmpages,shmpages.f,numproc.f,physpages,physpages.f,vmguarpages,vmguarpages.f,oomguarpages,oomguarpages.f,numtcpsock,numtcpsock.f,numflock,numflock.f,numpty,numpty.f,numsiginfo,numsiginfo.f,tcpsndbuf,tcpsndbuf.f,tcprcvbuf,tcprcvbuf.f,othersockbuf,othersockbuf.f,dgramrcvbuf,dgramrcvbuf.f,numothersock,numothersock.f,dcachesize,dcachesize.f,numfile,numfile.f,numiptent,numiptent.f,diskspace,diskspace.s,diskspace.h,diskinodes,diskinodes.s,diskinodes.h,laverage,cpulimit,cpuunits -H`;
preg_match_all('/\s+(?P<veid>[^\s]+)\s+(?P<numproc>[^\s]+)\s+(?P<status>[^\s]+)\s+(?P<ip>[^\s]+)\s+(?P<hostname>[^\s]+)\s+(?P<kmemsize>[^\s]+)\s+(?P<kmemsize_f>[^\s]+)\s+(?P<lockedpages>[^\s]+)\s+(?P<lockedpages_f>[^\s]+)\s+(?P<privvmpages>[^\s]+)\s+(?P<privvmpages_f>[^\s]+)\s+(?P<shmpages>[^\s]+)\s+(?P<shmpages_f>[^\s]+)\s+(?P<numproc_f>[^\s]+)\s+(?P<physpages>[^\s]+)\s+(?P<physpages_f>[^\s]+)\s+(?P<vmguarpages>[^\s]+)\s+(?P<vmguarpages_f>[^\s]+)\s+(?P<oomguarpages>[^\s]+)\s+(?P<oomguarpages_f>[^\s]+)\s+(?P<numtcpsock>[^\s]+)\s+(?P<numtcpsock_f>[^\s]+)\s+(?P<numflock>[^\s]+)\s+(?P<numflock_f>[^\s]+)\s+(?P<numpty>[^\s]+)\s+(?P<numpty_f>[^\s]+)\s+(?P<numsiginfo>[^\s]+)\s+(?P<numsiginfo_f>[^\s]+)\s+(?P<tcpsndbuf>[^\s]+)\s+(?P<tcpsndbuf_f>[^\s]+)\s+(?P<tcprcvbuf>[^\s]+)\s+(?P<tcprcvbuf_f>[^\s]+)\s+(?P<othersockbuf>[^\s]+)\s+(?P<othersockbuf_f>[^\s]+)\s+(?P<dgramrcvbuf>[^\s]+)\s+(?P<dgramrcvbuf_f>[^\s]+)\s+(?P<numothersock>[^\s]+)\s+(?P<numothersock_f>[^\s]+)\s+(?P<dcachesize>[^\s]+)\s+(?P<dcachesize_f>[^\s]+)\s+(?P<numfile>[^\s]+)\s+(?P<numfile_f>[^\s]+)\s+(?P<numiptent>[^\s]+)\s+(?P<numiptent_f>[^\s]+)\s+(?P<diskspace>[^\s]+)\s+(?P<diskspace_s>[^\s]+)\s+(?P<diskspace_h>[^\s]+)\s+(?P<diskinodes>[^\s]+)\s+(?P<diskinodes_s>[^\s]+)\s+(?P<diskinodes_h>[^\s]+)\s+(?P<laverage>[^\s]+)\s+(?P<cpulimit>[^\s]+)\s+(?P<cpuunits>[^\s]+)/', $out, $matches);
//print_r($matches);
$servers = array();
// build a list of servers, and then send an update command to make usre that the server has information on all servers
foreach ($matches['veid'] as $key => $id) {
$server = array(
'veid' => $id,
'numproc' => $matches['numproc'][$key],
'status' => $matches['status'][$key],
'ip' => $matches['ip'][$key],
'hostname' => $matches['hostname'][$key],
'kmemsize' => $matches['kmemsize'][$key],
'kmemsize_f' => $matches['kmemsize_f'][$key],
'lockedpages' => $matches['lockedpages'][$key],
'lockedpages_f' => $matches['lockedpages_f'][$key],
'privvmpages' => $matches['privvmpages'][$key],
'privvmpages_f' => $matches['privvmpages_f'][$key],
'shmpages' => $matches['shmpages'][$key],
'shmpages_f' => $matches['shmpages_f'][$key],
'numproc_f' => $matches['numproc_f'][$key],
'physpages' => $matches['physpages'][$key],
'physpages_f' => $matches['physpages_f'][$key],
'vmguarpages' => $matches['vmguarpages'][$key],
'vmguarpages_f' => $matches['vmguarpages_f'][$key],
'oomguarpages' => $matches['oomguarpages'][$key],
'oomguarpages_f' => $matches['oomguarpages_f'][$key],
'numtcpsock' => $matches['numtcpsock'][$key],
'numtcpsock_f' => $matches['numtcpsock_f'][$key],
'numflock' => $matches['numflock'][$key],
'numflock_f' => $matches['numflock_f'][$key],
'numpty' => $matches['numpty'][$key],
'numpty_f' => $matches['numpty_f'][$key],
'numsiginfo' => $matches['numsiginfo'][$key],
'numsiginfo_f' => $matches['numsiginfo_f'][$key],
'tcpsndbuf' => $matches['tcpsndbuf'][$key],
'tcpsndbuf_f' => $matches['tcpsndbuf_f'][$key],
'tcprcvbuf' => $matches['tcprcvbuf'][$key],
'tcprcvbuf_f' => $matches['tcprcvbuf_f'][$key],
'othersockbuf' => $matches['othersockbuf'][$key],
'othersockbuf_f' => $matches['othersockbuf_f'][$key],
'dgramrcvbuf' => $matches['dgramrcvbuf'][$key],
'dgramrcvbuf_f' => $matches['dgramrcvbuf_f'][$key],
'numothersock' => $matches['numothersock'][$key],
'numothersock_f' => $matches['numothersock_f'][$key],
'dcachesize' => $matches['dcachesize'][$key],
'dcachesize_f' => $matches['dcachesize_f'][$key],
'numfile' => $matches['numfile'][$key],
'numfile_f' => $matches['numfile_f'][$key],
'numiptent' => $matches['numiptent'][$key],
'numiptent_f' => $matches['numiptent_f'][$key],
'diskspace' => $matches['diskspace'][$key],
'diskspace_s' => $matches['diskspace_s'][$key],
'diskspace_h' => $matches['diskspace_h'][$key],
'diskinodes' => $matches['diskinodes'][$key],
'diskinodes_s' => $matches['diskinodes_s'][$key],
'diskinodes_h' => $matches['diskinodes_h'][$key],
'laverage' => $matches['laverage'][$key],
'cpulimit' => $matches['cpulimit'][$key],
'cpuunits' => $matches['cpuunits'][$key]
);
$servers[$id] = $server;
}
foreach ($servers as $id => $server) {
$out = trim(`export PATH="/usr/local/bin:/usr/local/sbin:\$PATH:/bin:/usr/bin:/sbin:/usr/sbin";vzquota stat $id 2>/dev/null | grep blocks | awk '{ print $2 " " $3 }'`);
if ($out != '') {
$disk = explode(' ', $out);
$servers[$id]['diskused'] = $disk[0];
$servers[$id]['diskmax'] = $disk[1];
}
}
}
//print_r($servers);
$cmd = 'curl --connect-timeout 60 --max-time 600 -k -d action=server_list -d servers="'.urlencode(base64_encode(gzcompress(json_encode($servers), 9))).'" "'.$url.'" 2>/dev/null;';
//echo "CMD: $cmd\n";
echo trim(`$cmd`);
}
get_qs_list();