forked from fbrnc/MuninPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirSize.php
84 lines (75 loc) · 1.86 KB
/
DirSize.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
#!/usr/bin/php -q
<?php
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MuninPlugin.php';
/**
* Directory size plugin for munin
*
* - Add symlink:
* ln -s <pathtothisfile> /etc/munin/plugins/dirsize
*
* - Add configuration to /etc/munin/plugin-conf.d/
* [dirsize]
* env.DIRS /dir1,/dir2
*
* @author Fabrizio Branca
*/
class DirSize extends MuninPlugin {
protected $cacheTime = 0;
/**
* @var array internal cache
*/
protected $data = array();
/**
* Setup
*
* @return array
*/
protected function getSetup() {
return array(
'graph_title' => 'Directory usage',
// @see http://munin-monitoring.org/wiki/graph_category
'graph_category' => 'disk',
// "second" or "minute" @see http://munin-monitoring.org/wiki/graph_period
'graph_period' => 'minute',
// "yes" or "no" @see http://munin-monitoring.org/wiki/graph_scale
'graph_scale' => 'yes',
'graph_vlabel' => 'Bytes',
// @see http://munin-monitoring.org/wiki/graph_args
'graph_args' => '--base 1024',
'graph_info' => 'This graph shows the size of several directories'
);
}
/**
* Graphs
* Reading configuration from environment variable (set in munin's plugin configuration)
*
* @return array
*/
protected function getGraphs() {
$graphs = array();
foreach (explode(',', getenv('DIRS')) as $dir) {
$graphs[$this->normalizeFieldName($dir)] = array(
'label' => $dir,
'info' => 'Size of '. $dir,
'type' => MuninPlugin::GRAPH_GAUGE,
'draw' => MuninPlugin::DRAW_LINE1
);
}
return $graphs;
}
/**
* Get values
*
* @return array
*/
protected function _getValues() {
$values = array();
foreach (explode(',', getenv('DIRS')) as $dir) {
list($size) = explode("\t", shell_exec('du -s '.$dir));
$values[$this->normalizeFieldName($dir)] = $size;
}
return $values;
}
}
$plugin = new DirSize($argv);
$plugin->process($argv);