File: memcachestat.php

package info (click to toggle)
simplesamlphp 1.13.1-2%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,304 kB
  • sloc: php: 65,124; xml: 629; python: 376; sh: 193; perl: 185; makefile: 43
file content (108 lines) | stat: -rw-r--r-- 3,415 bytes parent folder | download | duplicates (3)
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
<?php

function tdate($input) {
	return date(DATE_RFC822, $input); 
}

function hours($input) {
	if ($input < 60) return number_format($input, 2) . ' sec';
	if ($input < 60*60) return number_format(($input/60),2) . ' min';
	if ($input < 24*60*60) return number_format(($input/(60*60)),2) . ' hours';
	return number_format($input/(24*60*60),2) . ' days';
	
}


function humanreadable($input) {
	 
	$output = "";
	$input = abs($input);
	
	if ($input >= (1024*1024*1024*1024*1024*1024*1024*100)) {
		$output = sprintf("%5ldEi", $input / (1024*1024*1024*1024*1024*1024) );		
	} else if ($input >= (1024*1024*1024*1024*1024*1024*10)) {
		$output = sprintf("%5.1fEi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0*1024.0) );		
	} else if ($input >= (1024*1024*1024*1024*1024*1024)) {
		$output = sprintf("%5.2fEi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0*1024.0) );	


	} else if ($input >= (1024*1024*1024*1024*1024*100)) {
		$output = sprintf("%5ldPi", $input / (1024*1024*1024*1024*1024) );		
	} else if ($input >= (1024*1024*1024*1024*1024*10)) {
		$output = sprintf("%5.1fPi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0) );		
	} else if ($input >= (1024*1024*1024*1024*1024)) {
		$output = sprintf("%5.2fPi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0) );	
		
	} else if ($input >= (1024*1024*1024*1024*100)) {
		$output = sprintf("%5ldTi", $input / (1024*1024*1024*1024) );
	} else if ($input >= (1024*1024*1024*1024*10)) {
		$output = sprintf("%5.1fTi", $input / (1024.0*1024.0*1024.0*1024.0) );	
	} else if ($input >= (1024*1024*1024*1024)) {
		$output = sprintf("%5.2fTi", $input / (1024.0*1024.0*1024.0*1024.0) );


	} else if ($input >= (1024*1024*1024*100)) {
		$output = sprintf("%5ldGi", $input / (1024*1024*1024) );		
	} else if ($input >= (1024*1024*1024*10)) {
		$output = sprintf("%5.1fGi", $input / (1024.0*1024.0*1024.0) );		
	} else if ($input >= (1024*1024*1024)) {
		$output = sprintf("%5.2fGi", $input / (1024.0*1024.0*1024.0) );	
		
	} else if ($input >= (1024*1024*100)) {
		$output = sprintf("%5ldMi", $input / (1024*1024) );
	} else if ($input >= (1024*1024*10)) {
		$output = sprintf("%5.1fM", $input / (1024.0*1024.0) );	
	} else if ($input >= (1024*1024)) {
		$output = sprintf("%5.2fMi", $input / (1024.0*1024.0) );		
		
	} else if ($input >= (1024 * 100)) {
		$output = sprintf("%5ldKi", $input / (1024) );
	} else if ($input >= (1024 * 10)) {
		$output = sprintf("%5.1fKi", $input / 1024.0 );
	} else if ($input >= (1024)) {
		$output = sprintf("%5.2fKi", $input / 1024.0 );
		
	} else {
		$output = sprintf("%5ld", $input );
	}

	return $output;
}




$config = SimpleSAML_Configuration::getInstance();

/* Make sure that the user has admin access rights. */
SimpleSAML_Utilities::requireAdmin();


$formats = array(
	'bytes' => 'humanreadable',
	'bytes_read' => 'humanreadable',
	'bytes_written' => 'humanreadable',
	'limit_maxbytes' => 'humanreadable',
	'time' => 'tdate',
	'uptime' => 'hours',
);

$statsraw = SimpleSAML_Memcache::getStats();

$stats = $statsraw;

foreach($stats AS $key => &$entry) {
	if (array_key_exists($key, $formats)) {
		$func = $formats[$key];
		foreach($entry AS $k => $val) {
			$entry[$k] = $func($val);
		}
	}

}

$template = new SimpleSAML_XHTML_Template($config, 'memcacheMonitor:memcachestat.tpl.php');
$template->data['title'] = 'Memcache stats';
$template->data['table'] = $stats;
$template->data['statsraw'] = $statsraw;
$template->show();