-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvpsinfo.php
More file actions
1154 lines (1044 loc) · 37.9 KB
/
Copy pathvpsinfo.php
File metadata and controls
1154 lines (1044 loc) · 37.9 KB
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// vpsinfo by Douglas Robbins
// Email: drobbins [at] labradordata.ca
// Website: http://www.labradordata.ca/vpsinfo/
$version = '2.3.3 (18 October 2008)';
// This script is intended as a general information/monitoring page for a Linux
// Virtuozza or OpenVZ VPS (Virtual Private Server). It also runs fine on a
// dedicated Linux machine.
// Acknowledgements:
//
// 'vpsstat' output is based on a perl script by the same name developed by
// ServInt technical staff.
//
// This script may utilize third party software if installed:
// * MyTop by Jeremy D. Zawodny, GNU General Public License.
// http://jeremy.zawodny.com/mysql/mytop/
// * mysqlreport by ?
// http://hackmysql.com/mysqlreport
// * vnstat by Teemu Toivola, GNU General Public License.
// http://humdi.net/vnstat/
// Thanks to the ServInt VPS forum members & staff for testing and suggestions.
// Terms & Conditions:
//
// * This script is an original work and is copyright Douglas T. Robbins;
// * This script is provided to you for use free of charge;
// * You are permitted to modify the script for your own use;
// * You may redistribute the script in its original form;
// * You may not modify the script and publicly redistribute it, unless you
// make fundamental changes to the script to the extent that it may be
// considered a new work. In that case you should give your script a new name
// (i.e., do not use "vpsinfo" in the script name). An acknowledgement of the
// original vpsinfo in your release would be appreciated.
// Liability:
//
// The author assumes no liability for damage or loss that might be associated
// with the use of this script.
// == START CONFIGURATION =====================================================
// Mysql monitoring: 0 = none; 1 = mytop; 2 = mysqlreport
$mysql_mon = 0;
// Enable or disable vnstat. 0 = disable 1 = enable:
$vnstat = 0;
// MyTop/mysqlreport needs MySQL access to read the processlist.
// You may use any MySQL database.
// If you don't use MyTop or mysqlreport just ignore this.
$my_db = "database_name";
$my_user = "database_user";
$my_pass = "database_password";
// The account home directory for this mysql user:
$userhome = "/home/username";
// Processes to monitor. Include any process that should normally appear in the
// COMMAND column of the 'top' output. You can match a partial name, eg. 'ftpd'
// matches 'pure-ftpd' or 'proftpd'. Possible additions include: 'cppop',
// 'cpsrvd', 'exim', 'named'. This is a space-delimited list:
$processes = "ftpd mysqld sshd";
// Width of the left column in page display. You can adjust this if the
// leftside boxes are too wide or too narrow:
$leftcol = 590;
// Difference in hours between your local time and server time:
$timeoffset = 0;
// Auto-refresh of the main page.
// Set to 0 to disable, or specify a number of minutes:
$refresh = 3;
// Auto-refresh of command windows.
// Set to 0 to disable, or specify a number of minutes:
$top_refresh = 5;
$vpsstat_refresh = 5;
$netstat_refresh = 5;
$mysql_refresh = 5;
$vnstat_refresh = 15;
// Bandwidth alert. When the daily data transfer is greater than this, it is
// highlighted in red. In MB:
$bw_alert = 1000;
// Enable gzip compression for page output. 0 = disabled 1 = enabled
$gzip = 0;
// == END CONFIGURATION =======================================================
$mtime = explode (" ", microtime());
$tstart = $mtime[0] + $mtime[1];
$scriptname = $_SERVER['SCRIPT_NAME'];
$timestamp = time() + ($timeoffset * 3600);
$localtime = date("g:i a, M j", $timestamp);
$shorttime = date("g:i a", $timestamp);
// Shell commands for main windows display ------------------------------------
$netstat_com = "netstat -nt";
$vnstat_com = "vnstat";
$top_com = "top -n 1 -b";
$pstree_com = "env LANG=C pstree -c";
$df_com = "df -h --exclude-type=tmpfs";
$tmp_com = "ls -a --ignore=sess_* /tmp";
if ($mysql_mon == 1)
$mysql_com = "env HOME=$userhome env TERM=xterm mytop -u $my_user -p $my_pass -d $my_db -b --nocolor";
elseif ($mysql_mon == 2) {
$mysql_com = "./mysqlreport --user $my_user --password $my_pass --no-mycnf 2>&1";
$mysql_com2 = "./mysqlreport --all --tab --user $my_user --password $my_pass --no-mycnf";
}
$allps_com = "ps -e | awk '{ print $4;}' | uniq";
// GET and POST requests to this page -----------------------------------------
// 'Sample current traffic' (vnstat):
if ($_GET["traffic"]) {
$io = trim(`vnstat -tr | grep --after-context=3 Traffic`);
echo "<html>\n<body bgcolor='#000000' text='#CCCCCC' style='margin:10px 0 0 4px;padding:0'>\n<pre style='font-family:vt7X13,\"Courier New\";font-size:11px;line-height:14px'>$io</pre>\n</body>\n</html>";
exit;
}
// 'Ports List':
if ($_GET["showports"]) {
$porttext = "Port What Is It?
---- -----------------------
21 FTP server
25 Exim - SMTP
53 Bind nameserver
80 Apache webserver
110 POP mail server
143 IMAP mail server
443 Secure Apache webserver
465 Secure SMTP
993 Secure IMAP
2082 cPanel
2083 Secure cPanel (https)
2086 WHM
2087 Secure WHM (https)
2095 Webmail
2096 Secure webmail (https)
3306 MySQL
8888 Secure shell - SSHD";
echo "<html>\n<body bgcolor='#000000' text='#CCCCCC' style='margin:10px 0 0 30px;padding:0'>\n<pre style='font-family:vt7X13,\"Courier New\";font-size:11px;line-height:14px'>$porttext</pre>\n</body>\n</html>";
exit;
}
// Show logged-in shell users:
if ($_GET["users"]) {
$users = trim(`w`);
echo "<html>\n<body bgcolor='#000000' text='#CCCCCC' style='margin:10px 0 0 6px;padding:0'>\n<pre style='font-family:vt7X13,\"Courier New\";font-size:11px;line-height:14px'>Logged-in Users\n---------------\n$users</pre>\n</body>\n</html>";
exit;
}
// Whois lookup:
if ($_POST['whois']) {
$whois = trim($_POST['whois']);
}
elseif ($_GET['whois']) {
$whois = trim($_GET['whois']);
}
if ($whois) {
$whois = preg_replace("/[^a-z0-9-.]/", "", $whois);
$lookup = `whois $whois`;
echo "<html>\n<body bgcolor='#000000' text='#CCCCCC' style='margin:10px 0 0 30px;padding:0'>\n<pre style='font-family:vt7X13,\"Courier New\";font-size:11px;line-height:14px'>$lookup</pre>\n</body>\n</html>";
exit;
}
// ls -al /tmp:
if ($_GET['lsal']) {
$lsout = "Command: ls -al /tmp\n\n";
$lsout .= `ls -al /tmp`;
echo "<html>\n<body bgcolor='#000000' text='#CCCCCC' style='margin:10px 0 0 6px;padding:0'>\n<pre style='font-family:vt7X13,\"Courier New\";font-size:11px;line-height:14px'>$lsout</pre>\n</body>\n</html>";
exit;
}
// ps -aux (and mem):
if ($_GET['psaux']) {
$psout = "Command: ps -aux\n\n";
$psout .= `ps -aux`;
$psout = str_replace("<","<",$psout);
echo "<html>\n<body bgcolor='#000000' text='#CCCCCC' style='margin:10px 0 0 6px;padding:0'>\n<pre style='font-family:vt7X13,\"Courier New\";font-size:11px;line-height:14px'>$psout</pre>\n</body>\n</html>";
exit;
}
if ($_GET['psmem']) {
$psout = "Command: ps -auxh --sort=size | tac\n\n";
$psout .= "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\n";
$psout .= `ps -auxh --sort=size | tac`;
$psout = str_replace("<","<",$psout);
echo "<html>\n<body bgcolor='#000000' text='#CCCCCC' style='margin:10px 0 0 6px;padding:0'>\n<pre style='font-family:vt7X13,\"Courier New\";font-size:11px;line-height:14px'>$psout</pre>\n</body>\n</html>";
exit;
}
// Command windows:
if ($_GET['cmd']) {
$cmd = $_GET['cmd'];
if ($cmd == "top") {
$out = trim(`top -n 1 -b`);
$meta = "<meta http-equiv=\"refresh\" content=\"".($top_refresh*60)."\">";
}
elseif ($cmd == "vpsstat") {
list($out,$opages,$ppages) = vpsstat();
$meta = "<meta http-equiv=\"refresh\" content=\"".($vpsstat_refresh*60)."\">";
}
elseif ($cmd == "netstat") {
$out = netstat($netstat_com);
$meta = "<meta http-equiv=\"refresh\" content=\"".($netstat_refresh*60)."\">";
$buttons = "<input type='button' value='Listening' onClick=\"window.location.replace('$scriptname?cmd=netstat2');\" class='button' title='show listening ports'>\n";
$title = "netstat -nt (TCP connections)";
}
elseif ($cmd == "netstat2") {
$out = trim(`netstat -ntl`);
$meta = "<meta http-equiv=\"refresh\" content=\"".($netstat_refresh*60)."\">";
$buttons = "<input type='button' value='Active' onClick=\"window.location.replace('$scriptname?cmd=netstat');\" class='button' title='show active connections'>\n";
$title = "netstat -ntl (listening TCP ports)";
}
elseif ($cmd == "mytop") {
$out = trim(`$mysql_com`);
$meta = "<meta http-equiv=\"refresh\" content=\"".($mysql_refresh*60)."\">";
}
elseif ($cmd == "mysqlreport") {
$out = trim(`$mysql_com2`);
$out = str_replace('_','-',$out);
$meta = "<meta http-equiv=\"refresh\" content=\"".($mysql_refresh*60)."\">";
}
elseif ($cmd == "vnstat") {
$out = trim(`vnstat`);
$meta = "<meta http-equiv=\"refresh\" content=\"".($vnstat_refresh*60)."\">";
}
elseif ($cmd == "vnstat2") {
$out = trim(`vnstat -d`);
$meta = "<meta http-equiv=\"refresh\" content=\"".($vnstat_refresh*60)."\">";
$title = "vnstat -d";
}
elseif ($cmd == "vnstat3") {
$out = trim(`vnstat -m`);
$meta = "<meta http-equiv=\"refresh\" content=\"".($vnstat_refresh*60)."\">";
$title = "vnstat -m";
}
elseif ($cmd == "vnstat4") {
$out = trim(`vnstat -tr | grep --after-context=3 Traffic`);
$meta = "";
$title = "vnstat -tr";
}
$reload = "$scriptname?cmd=$cmd";
if (stristr($cmd,"vnstat")) {
$buttons = "<input type='button' value='Sample' onClick=\"window.location.replace('$scriptname?cmd=vnstat4');\" class='button' title='sample current traffic - 5 second delay'>
<input type='button' value='Today' onClick=\"window.location.replace('$scriptname?cmd=vnstat');\" class='button' title='today & yesterday'>
<input type='button' value='Days' onClick=\"window.location.replace('$scriptname?cmd=vnstat2');\" class='button' title='daily totals'>
<input type='button' value='Months' onClick=\"window.location.replace('$scriptname?cmd=vnstat3');\" class='button' title='monthly totals'>
<input type='button' value='Close' onClick='javascript:window.close();' class='button' title='close window'>";
}
else {
$buttons .= "<input type='button' value='Reload' onClick='javascript:window.location.reload();' class='button' title='reload $cmd'> <input type='button' value='Close' onClick='javascript:window.close();' class='button' title='close window'>";
}
if (!$title) {
$title = $cmd;
}
poppage($cmd,$out,$meta,$reload,$shorttime,$buttons,$title);
exit;
}
// Run the commands now (except vnstat & mysql) -------------------------------
$top = trim(`$top_com`);
$hostname = trim(`hostname`);
$netstat = netstat($netstat_com);
$pstree = trim(`$pstree_com`);
$df_full = trim(`$df_com`);
$tmp_full = trim(`$tmp_com`);
$allps = trim(`$allps_com`);
// Clean up / prep output -----------------------------------------------------
$netstat = preg_replace("/ {1,99}\n/", "\n", $netstat);
$tmp_full = preg_replace("/ {1,99}/", "\n", $tmp_full);
// df - Disk Usage:
$lines = explode("\n", $df_full);
for ($i=0; $i<count($lines); $i++) {
$line = preg_replace("/ {1,99}/", "|", $lines[$i]);
$parts = explode("|",$line);
if ($parts[0] !== $prev) {
$mnt = $parts[5];
$actual = " ($parts[2])";
if (!stristr($line,"Filesystem")) {
$per = substr($parts[4],0,-1);
if ($per > 90) {
$allfs .= "<span class='warn'>$mnt $parts[4]$actual</span>, ";
}
else {
$allfs .= "$mnt $parts[4]$actual, ";
}
}
}
$prev = $parts[0];;
}
if (substr($allfs, -7) == ", ") {
$allfs = substr($allfs, 0, -7);
}
// Other summary stats:
$num_mysql = substr_count($pstree,'mysqld');
$num_httpd = substr_count($pstree,'httpd');
$num_tcp = substr_count($netstat,'tcp');
//Main page buttons:
// Box buttons to command windows:
$topcmdlink = "<a href='$scriptname?cmd=top' onClick=\"window.open('$scriptname?cmd=top', 'top', 'width=600, height=480, resizable'); return false\" title='open a top window' class='open'> + </a>";
$vpscmdlink = "<a href='$scriptname?cmd=vpsstat' onClick=\"window.open('$scriptname?cmd=vpsstat', 'vpsstat', 'width=540, height=180, resizable'); return false\" title='open a vpsstat window' class='open'> + </a>";
$netcmdlink = "<a href='$scriptname?cmd=netstat' onClick=\"window.open('$scriptname?cmd=netstat', 'netstat', 'width=600, height=480, resizable'); return false\" title='open a netstat window' class='open'> + </a>";
if ($mysql_mon == 1)
$mycmdlink = "<a href='$scriptname?cmd=mytop' onClick=\"window.open('$scriptname?cmd=mytop', 'mytop', 'width=600, height=345, resizable'); return false\" title='open a mytop window' class='open'> + </a>";
elseif ($mysql_mon == 2)
$mycmdlink = "<a href='$scriptname?cmd=mysqlreport' onClick=\"window.open('$scriptname?cmd=mysqlreport', 'mysqlreport', 'width=600, height=480, resizable'); return false\" title='open a mysqlreport window' class='open'> + </a>";
$vncmdlink = "<a href='$scriptname?cmd=vnstat' onClick=\"window.open('$scriptname?cmd=vnstat', 'vnstat', 'width=525, height=345, resizable'); return false\" title='open a vnstat window' class='open'> + </a>";
// Button for 'ls -al /tmp':
$lsal = "<input type='button' value='ls -al /tmp' onClick=\"window.open('$scriptname?lsal=1', 'lsal', 'width=730, height=400, scrollbars, resizable'); return false\" title='show detailed list' class='button' style='width:75px'>\n";
// Button for 'ps -aux':
$psaux = "<input type='button' value='ps -aux' onClick=\"window.open('$scriptname?psaux=1', 'psaux', 'width=730, height=480, scrollbars, resizable'); return false\" title='show process list' class='button' style='width:85px;'>\n";
// Button for 'ps -aux --sort=size | tac' :)
$psmem = "<input type='button' value='ps -aux (mem)' onClick=\"window.open('$scriptname?psmem=1', 'psmem', 'width=730, height=480, scrollbars, resizable'); return false\" title='show process list, sorted by memory usage' class='button' style='width:85px;'>\n";
// Buttons for vnstat:
$vn_sampl = "<input type='button' value='Sample' onClick=\"window.open('$scriptname?cmd=vnstat4', 'vnstat', 'width=525, height=380, resizable'); return false\" class='button' title='sample current traffic - 5 second delay'>";
$vn_days = "<input type='button' value='Days' onClick=\"window.open('$scriptname?cmd=vnstat2', 'vnstat', 'width=525, height=380, resizable'); return false\" class='button' title='show daily totals'>";
$vn_mons = "<input type='button' value='Months' onClick=\"window.open('$scriptname?cmd=vnstat3', 'vnstat', 'width=525, height=380, resizable'); return false\" class='button' title='show monthly totals'>";
// Buttons for netstat:
$netstat_ntl = "<input type='button' value='Listening' onClick=\"window.open('$scriptname?cmd=netstat2', 'netstat', 'width=600, height=480, resizable'); return false\" class='button' title='show listening ports'>";
$portslink = "<input type='button' value='Port List' onClick=\"window.open('$scriptname?showports=1', 'portlist', 'width=300, height=330'); return false\" class='button' title='show explanatory list of ports'>";
// Button for mysqlreport:
$mysqlrep_det = "<input type='button' value='Full Report' onClick=\"window.open('$scriptname?cmd=mysqlreport', 'mysqlreport', 'width=600, height=480, resizable'); return false\" class='button' title='show detailed mysqlreport'>";
// Auto-refresh meta tag:
if ($refresh) {
if ($refresh < 1) {
$refresh = 1;
}
$refresh = ($refresh * 60);
$meta_refresh = "<meta http-equiv=\"refresh\" content=\"$refresh\">\n";
}
// Load bar indicators:
$pattern = "/^.*\b(average)\b.*$/mi";
preg_match($pattern, $top, $hits);
$loadline = $hits[0];
$load_bits = explode("average:",$loadline);
$load_parts = explode(",",$load_bits[1]);
$load1 = trim($load_parts[0]);
$loadlabel1 = $load1;
$load5 = trim($load_parts[1]);
$loadlabel5 = $load5;
$load15 = trim($load_parts[2]);
$loadlabel15 = $load15;
if ($load1 > 10) {
$load1 = 10;
}
if ($load5 > 10) {
$load5 = 10;
}
if ($load15 > 10) {
$load15 = 10;
}
if ($load1 > 1) {
$load1_width = round(($load1 - 1) * 22.22);
$bgcolor1 = "#82826E";
$fgcolor1 = "#CC0000";
}
else {
$load1_width = round($load1 * 200);
$bgcolor1 = "#222222";
$fgcolor1 = "#82826E";
}
if ($load5 > 1) {
$load5_width = round(($load5 - 1) * 22.22);
$bgcolor5 = "#82826E";
$fgcolor5 = "#CC0000";
}
else {
$load5_width = round($load5 * 200);
$bgcolor5 = "#222222";
$fgcolor5 = "#82826E";
}
if ($load15 > 1) {
$load15_width = round(($load15 - 1) * 22.22);
$bgcolor15 = "#82826E";
$fgcolor15 = "#CC0000";
}
else {
$load15_width = round($load15 * 200);
$bgcolor15 = "#222222";
$fgcolor15 = "#82826E";
}
// If users, hyperlink 'User(s)' in top display:
if (!stristr($top,"0 users,")) {
$top = preg_replace("/(user|users),/", "<a href='$scriptname?users=1' onClick=\"window.open('$scriptname?users=1', 'users', 'width=625, height=300, scrollbars'); return false\" title='show users'>$1</a>,", $top);
}
// Mytop/mysqlreport and vnstat ------------------------------------------------
// Run or produce a useful message if not installed.
if ($mysql_mon == 1) {
exec("which mytop",$output,$return);
if ($return == 1) {
$mysql = "\n\nMytop is not installed. See the <a href='http://jeremy.zawodny.com/mysql/mytop/'>mytop website</a> for information.\n\n";
$mycmdlink = "";
$mysql_head = "";
}
elseif ($return == 0) {
$mysql = trim(`$mysql_com`);
$pattern = "/^.*\bQueries\b.*$/mi";
preg_match($pattern, $mysql, $hits);
$queryline = trim($hits[0]);
$my_parts = explode(" ",$queryline);
}
$mysql_div = "<div class='subleftcmd'>$mycmdlink</div><div class='subleft'>mytop</div><div class='left'><pre>$mysql</pre></div>\n";
}
elseif ($mysql_mon == 2) {
if (file_exists('mysqlreport') && is_executable('mysqlreport')) {
$mysql = trim(`$mysql_com`);
if (stristr($mysql,'uptime')) {
// Get total queries for topbar display
$parts = explode("_\n",$mysql);
$parts = explode("\n",$parts[2]);
$qline = preg_replace("/ {1,99}/", "|", $parts[0]);
$my_parts = explode('|',$qline);
// The 'Full report' button
$full_report = "\n<div class='toolbar'>$mysqlrep_det</div>";
// Change underscores to dashes for readability
$mysql = str_replace('_','-',$mysql);
}
elseif (stristr($mysql,'Access denied for user')) {
$mysql = "\n\nThe mysqlreport script was denied access to mysql. Check that the mysql username
& password (in the vpsinfo configuration) are valid.\n\n";
$mycmdlink = '';
}
elseif (stristr($mysql,'bad interpreter')) {
$mysql = "\n\nThe mysqlreport script encountered a problem -- the first line does not have the
correct path for perl on your system.\n\n";
$mycmdlink = '';
}
else {
$mysql = "\n\nAn unknown error occurred with the mysqlreport script.\n\n";
$mycmdlink = '';
}
}
elseif (file_exists('mysqlreport')) {
$mysql = "\n\nThe mysqlreport script could not be executed. Check the file ownership & permissions.\n\n";
$mycmdlink = '';
}
else {
$mysql = "\n\nThe mysqlreport script was not found.\n
You need to get it from <a href='http://hackmysql.com/mysqlreport'>http://hackmysql.com/mysqlreport</a>, store it in the same
directory as vpsinfo, and set correct ownership & permissions.\n\n";
$mycmdlink = '';
}
$mysql_div = "<div class='subleftcmd'>$mycmdlink</div><div class='subleft'>mysqlreport</div>
<div class='left'><pre>$mysql</pre></div>$full_report\n";
}
if ($my_parts) {
if (is_numeric($my_parts[1])) {
$mysql_queries = round($my_parts[1]);
$mysql_units = "";
}
else {
$mysql_units = strtoupper(substr($my_parts[1],-1));
if ($mysql_units == "M") {
$mysql_queries = round(substr($my_parts[1],0,-1),2);
}
if ($mysql_units == "K") {
$mysql_queries = round(substr($my_parts[1],0,-1));
}
}
$mysql_head = "<td valign='top' nowrap><div class='head_label' style='padding-right:5px' title='number of mysql queries'>mysql queries</div><div class='head_num2' style='padding-right:5px'>$mysql_queries<span class='head_units'> $mysql_units</span></div></td>";
}
if ($vnstat) {
exec("which vnstat",$output,$return);
if ($return == 1) {
$vnstat = "\n\nVnstat is not installed. See the <a href='http://humdi.net/vnstat/'>vnstat website</a> for information.\n\n";
$vncmdlink=''; $vn_sampl=''; $vn_days=''; $vn_mons='';
$vnstat_div = "<div class='subleft'>vnstat</div><div class='left'><pre>$vnstat</pre></div>";
}
elseif ($return == 0) {
$vnstat = trim(`$vnstat_com`);
$pattern = "/^.*\btoday\b.*$/mi";
preg_match_all($pattern, $vnstat, $hits);
$todayline = $hits[0][0];
$today = explode("|",$todayline);
$today_mb = str_replace(" MB","",$today[2]);
$today_mb = trim($today_mb);
if (stristr($today_mb,",")) {
$today_mb = str_replace(",","",$today_mb);
}
$today_mb = round($today_mb);
if ($today_mb > 999) {
$bw_today = round(($today_mb / 1024),1);
$bw_units = "GB";
}
else {
$bw_today = $today_mb;
$bw_units = "MB";
}
if ($today_mb > $bw_alert) {
$bw_today = "<span class='warn'>$bw_today</span>";
}
$vnstat_head = "<td valign='top' nowrap><div class='head_label' title='amount of data transferred today'>transfer today</div><div class='head_num'>$bw_today<span class='head_units'> $bw_units</span></div></td>
";
$vnstat_div = "<div class='subleftcmd'>$vncmdlink</div><div class='subleft'>vnstat</div><div class='leftscroll'><pre>$vnstat</pre></div>
<div class='toolbar'>$vn_sampl $vn_days $vn_mons</div>";
}
}
// vpsstat-like processing of user_beancounters or RAM & swap -----------------
list($vpsstat,$mem1,$mem1_units,$mem1_label,$mem1_tip,$mem2,$mem2_units,$mem2_label,$mem2_tip) = vpsstat();
if ($vpsstat) {
$vpsstat_div = "<div class='subleftcmd'>$vpscmdlink</div><div class='subleft'>vpsstat</div><div class='left'><pre>$vpsstat</pre></div>\n";
}
// Process/daemon monitor -----------------------------------------------------
$allprocs = explode(" ", $processes);
foreach ($allprocs as $proc) {
$proc = trim($proc);
if (stristr($allps,$proc)) {
$tcpstatus .= "<span class='servup' title='$proc is up'> $proc </span> ";
}
else {
$tcpstatus .= "<span class='servdown' title='$proc is down!'> $proc </span> ";
}
}
// FUNCTIONS ==================================================================
function netstat($netstat_com) {
$out = trim(`$netstat_com`);
$out = str_replace(" Address","_Address",$out);
$lines = explode("\n",$out);
for ($i=0; $i<count($lines); $i++) {
if ($i > 0) {
$line = preg_replace("/ {1,99}/", "|", $lines[$i]);
$line = str_replace("::ffff:","",$line);
$parts = explode("|",$line);
$col_0 = str_pad($parts[0], 5, " ", STR_PAD_RIGHT);
$col_1 = str_pad($parts[1], 6, " ", STR_PAD_LEFT);
$col_2 = str_pad($parts[2], 6, " ", STR_PAD_LEFT);
$col_3 = str_pad($parts[3], 23, " ", STR_PAD_RIGHT);
if (stristr($parts[4],":")) {
$col_4_parts = explode(":",$parts[4]);
$ip_str = $col_4_parts[0];
}
$col_4 = str_pad($parts[4], 23, " ", STR_PAD_RIGHT);
if ($ip_str) {
$link = "<a href='$scriptname?whois=$ip_str' onClick=\"window.open('$scriptname?whois=$ip_str', 'netstat', 'width=650, height=350, resizable, scrollbars'); return false\" title='whois $ip_str'>$ip_str</a>";
$col_4 = str_replace($ip_str,$link,$col_4);
}
$col_5 = $parts[5];
$cols = $col_0." ".$col_1." ".$col_2." ".$col_3." ".$col_4." ".$col_5;
}
else {
$cols = $lines[$i];
}
$all .= "\n" . $cols;
}
$all = str_replace("_Address"," Address",$all);
return $all;
}
function poppage($cmd,$out,$meta,$reload,$shorttime,$buttons,$title) {
echo "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<title>$cmd</title>
$meta
<style type='text/css'>
html, body {
width: 100%;
height: 100%;
overflow: hidden;
}
body {
background-color: #000000;
color: #CCCCCC;
margin: 0;
padding: 0;
}
#scroll {
clear: both;
overflow: auto;
border: none;
margin: 0;
padding: 0;
overflow-Y: auto;
overflow-X: visible;
scrollbar-face-color: #666666;
scrollbar-track-color: #999999;
scrollbar-3dlight-color: #999999;
scrollbar-highlight-color: #666666;
}
pre {
font-family: vt7X13,\"Courier New\",Courier,monospace;
font-size: 11px;
line-height: 14px;
padding: 5px 5px 10px 6px;
margin: 0;
}
div.title {
float: left;
font-family: Verdana,Arial,Helvetica,sans-serif;
background-color: #333333;
color: #DDDDDD;
font-size: 13px;
font-weight: bold;
padding: 4px 0 2px 6px;
}
div.commands {
font-family: Verdana,Arial,Helvetica,sans-serif;
background-color: #333333;
text-align: right;
font-size: 13px;
padding: 4px 10px 5px 0;
border-bottom: 1px solid #666666;
}
.button {
width: 60px;
font-size: 11px;
border: 1px solid #999999;
background-color: #666666;
color: #FFFFFF;
}
a:link, a:visited, a:active {
color: #BBBB00;
text-decoration: none;
}
</style>
<script language='javascript'>
function fullHgt() {
if (document.getElementById('scroll')) {
var hgt = document.body.clientHeight - 27;
document.getElementById('scroll').style.height=hgt+'px';
}
}
</script>
</head>
<body onLoad='fullHgt()' onResize='fullHgt()'>
<div class='title'>$title @ $shorttime</div>
<div class='commands'>$buttons </div>
<div id='scroll'><pre>$out</pre></div>
</body>\n</html>";
}
function vpsstat() {
$rawbeans = `/bin/beanc 2> /dev/null`;
if (!$rawbeans) {
if (file_exists('/proc/user_beancounters')) {
$rawbeans = `cat /proc/user_beancounters 2> /dev/null`;
}
else {
$ded=TRUE;
}
}
if ($rawbeans) {
$lines = explode("\n", $rawbeans);
for ($i=0; $i<count($lines); $i++) {
if (preg_match("/oomg|privv|numpr|numt|numo|numfi/",$lines[$i])) {
$line = preg_replace("/ {1,99}/", "|", $lines[$i]);
$line_parts = explode("|",$line);
if (stristr($lines[$i],"oomg") || stristr($lines[$i],"privv")) {
$cur = round($line_parts[2] / 256, 1) . " MB";
$rec = round($line_parts[3] / 256, 1) . " MB";
$bar = round($line_parts[4] / 256) . " MB";
if (stristr($lines[$i],"oomg")) {
$lim = "n/a";
$mem1 = round($cur);
if ($mem1 > $bar) {
$mem1 = "<span class='warn'>$mem1</span>";
}
$mem1_label = "oomguarpages";
$oomg_per = round($mem1 / $bar * 100);
$mem1_tip = "title='oomguarpages is guaranteed memory; you are using $oomg_per% of your quota'";
$mem1_units = "MB";
}
else {
$lim = round($line_parts[5] / 256) . " MB";
$mem2 = round($cur);
$mem2_label = "privvmpages";
$pmg_per = round($mem2 / $lim * 100);
$mem2_tip = "title='privvmpages is burstable memory; you are using $pmg_per% of your limit'";
$mem2_units = "MB";
}
}
else {
$cur = $line_parts[2];
$rec = $line_parts[3];
$bar = "n/a";
$lim = $line_parts[5];
}
$beans .= str_pad($line_parts[1],12) . str_pad($cur, 12, " ", STR_PAD_LEFT) .str_pad($rec, 12, " ", STR_PAD_LEFT) . str_pad($bar, 12, " ", STR_PAD_LEFT) . str_pad($lim, 12, " ", STR_PAD_LEFT) . str_pad($line_parts[6], 12, " ", STR_PAD_LEFT) . "\n";
}
}
$parts = explode("\n",$beans);
$vpsstat = "Resource Current Recent Max Barrier Limit Failures\n";
$vpsstat .= "------------ ---------- ---------- ---------- ---------- ----------\n";
$vpsstat .= "$parts[2]\n$parts[0]\n$parts[1]\n$parts[3]\n$parts[4]\n$parts[5]";
}
if (!$vpsstat && $ded==FALSE) {
$vpsstat = "\n
It seems you're running Virtuozzo 3 or OpenVZ. In order to read the VPS stats
(beancounters) you need a small 'helper' app. To install it do the following at
a shell prompt as root:
[root@vps] wget http://www.labradordata.ca/downloads/install_beanc.sh
[root@vps] sh install_beanc.sh\n\n";
}
elseif ($ded==TRUE) {
$free = `free`;
if ($free) {
$pattern = "/^.*\bMem\b.*$/mi";
preg_match($pattern, $free, $hits);
$memline = $hits[0];
$memline = preg_replace("/ {1,99}/", "|", $memline);
$parts = explode("|",$memline);
$kbytes = $parts[3];
$mbytes = round($kbytes / 1024);
if ($mbytes > 999) {
$mem1 = round(($mbytes / 1024),1);
$mem1_units = "GB";
}
else {
$mem1 = $mbytes;
$mem1_units = "MB";
}
$mem1_label = "free RAM";
$mem1_tip = "title='amount of free memory'";
$pattern = "/^.*\bSwap\b.*$/mi";
preg_match($pattern, $free, $hits);
$memline = $hits[0];
$memline = preg_replace("/ {1,99}/", "|", $memline);
$parts = explode("|",$memline);
$kbytes = $parts[2];
$mbytes = round($kbytes / 1024);
if ($mbytes > 999) {
$mem2 = round(($mbytes / 1024),1);
$mem2_units = "GB";
}
else {
$mem2 = $mbytes;
$mem2_units = "MB";
}
$mem2_label = "swap used";
$mem2_tip = "title='amount of swap space currently used'";
}
}
return array($vpsstat,$mem1,$mem1_units,$mem1_label,$mem1_tip,$mem2,$mem2_units,$mem2_label,$mem2_tip);
}
$mtime = explode (" ", microtime());
$tend = $mtime[0] + $mtime[1];
$totaltime = round(($tend - $tstart),4);
$pagegen = "page generated in $totaltime sec.";
// MAIN PAGE OUTPUT ===========================================================
if ($gzip) {
ini_set('zlib.output_compression_level', 1);
ob_start("ob_gzhandler");
}
header("Cache-Control: no-cache, must-revalidate");
header('Pragma: no-cache');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?=$meta_refresh?>
<style type ='text/css'>
BODY {
font-family: Verdana,Arial,Helvetica,sans-serif;
background-color: #31311B;
color: #CCCCCC;
margin: 5px 5px 30px 5px;
padding: 0;
}
/* General layout ---------------------------- */
div.space {
font-size: 1px;
height: 3px;
}
td.head {
border: 1px solid #666666;
background-color: #000000;
}
td.tdleft {
}
td.tdright {
padding-left: 5px;
}
/* Header section ---------------------------- */
div.hostname {
font-size: 16px;
font-weight: bold;
color: #DDDDDD;
padding: 2px 0 2px 5px;
}
div.date {
font-size: 13px;
font-weight: bold;
color: #DDDDDD;
padding: 0 0 2px 5px;
}
div.head_label {
font-family: Tahoma,"MS Sans Serif",Arial,Helvetica,sans-serif;
font-size: 11px;
padding-left: 13px;
text-align: right;
cursor: help;
}
div.head_num {
font-size: 22px;
padding-left: 13px;
padding-right: 1px;
text-align: right;
}
div.head_num2 {
font-size: 18px;
padding-left: 13px;
padding-right: 1px;
text-align: right;
}
.head_units {
font-family: Tahoma,"MS Sans Serif",Arial,Helvetica,sans-serif;
font-size: 10px;
vertical-align : super;
}
div.head_sum {
font-family: Tahoma,"MS Sans Serif",Arial,Helvetica,sans-serif;
font-size: 11px;
padding: 1px 5px 2px 0;
text-align: right;
}
/* Service monitoring in the header */
div.servstatus {
font-family: Tahoma,"MS Sans Serif",Arial,Helvetica,sans-serif;
font-size: 11px;
background-color: #333333;
padding: 2px 0 2px 2px;
}
span.servup {
background-color: #004000;
color: #CCCCCC;
cursor: help;
}
span.servdown {
background-color: #CC0000;
color: #FFFFFF;
cursor: help;
}
div.disk {
font-family: Tahoma,"MS Sans Serif",Arial,Helvetica,sans-serif;
font-size: 11px;
text-align: right;
background-color: #333333;
padding: 2px 5px 2px 0;
}
.warn {
background-color: #CC0000;
}
/* Load bars */
div.load_label {
height: 12px;
font-family: Tahoma,"MS Sans Serif",Arial,Helvetica,sans-serif;
font-size: 11px;
color: #CCCCCC;
line-height: 11px;
text-align: right;
cursor: help;
}
div.load_bg {
font-size: 2px;
height: 10px;
width: 200px;
cursor: help;
}
div.load_fg {
height: 10px;
}
/* Box layouts ------------------------------- */
div.subleft,div.subright {
font-size: 13px;
font-weight: bold;
background-color: #333333;
color: #DDDDDD;
}
div.subleft {
width: auto;
border: 1px solid #666666;
border-bottom: none;
margin-top: 5px;
padding: 0 0 3px 6px;
}
div.subright {
width: auto;
border: 1px solid #666666;
border-bottom: none;
margin-top: 5px;
padding: 0 0 3px 6px;
}
div.left {
clear: right;
margin: 0;
background-color: #000000;
border: 1px solid #666666;
border-top: none;
}
div.leftscroll {
clear: right;
height: 230px;
overflow: auto;
margin-right: -1px;
background-color: #000000;
border: 1px solid #666666;
border-bottom: 1px solid #444444;
border-top: none;
/* IE-specific hacks */
overflow-Y: auto;
overflow-X: visible;
scrollbar-face-color: #666666;
scrollbar-track-color: #999999;
scrollbar-3dlight-color: #999999;
scrollbar-highlight-color: #666666;
}
div.right,div.toolbar,div.toolbar_left {
width: auto;
background-color: #000000;
border: 1px solid #666666;
border-top: none;
}
div.toolbar {
border-top: none;
padding: 3px 5px 4px 0;
text-align: right;
}
div.toolbar_left {
border-top: none;
padding: 3px 0 4px 5px;
text-align: left;
}
/* Box buttons to command windows */
div.subleftcmd {
text-align: right;
font-size: 10px;
line-height: 14px;
float: right;
margin-top: 5px;
margin-right: 0px;