-
Notifications
You must be signed in to change notification settings - Fork 1
/
tsunami_grapher.php
169 lines (141 loc) · 5.34 KB
/
tsunami_grapher.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
#!/usr/bin/php
<?php
include 'include/tsunami_common.php';
include 'config/tsunami_config.php';
//parse the hosts configuration
include 'include/tsunami_host_parser.php';
//parse the collector output
include 'include/tsunami_collected_parser.php';
function runExternal($cmd) {
global $runningChildren;
global $grapherConcurrency;
$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} elseif ($pid) {
// parent
$runningChildren++;
if ($runningChildren>=$grapherConcurrency) {
pcntl_wait($status);
$runningChildren--;
}
} else {
// child
`$cmd`;
exit;
}
}
//if there are command line arguments, process them
if($argc > 1)
$searchHost = $argv[1]; //use $argv[1] as host ID
if($argc > 2)
{
if($argv[2] == "all" or $argv[2] == "none")
$searchSubhost = $argv[2];
else
#$searchSubhost = sprintf("%03d", $argv[2]); //use $argv[2] as subhost ID
$searchSubhost = $argv[2]; //use $argv[2] as subhost ID
}
//ignore other args
echo date("Ymd H:i:s")." Starting graphs build.\n";
$runningChildren = 0;
//make the graphs directory if it does not exist
if(!file_exists($pathWWW.$wwwPathGraphs))
{
echo date("Ymd H:i:s")." Creating directory \"$pathWWW$wwwPathGraphs\"\n";
mkdir($pathWWW.$pathWWWGraphs);
}
foreach($aHosts as $host)
{
if(isset($searchHost) and $searchHost != "all" and $host->m_id != $searchHost)
continue;
$pathHostGraphs = $pathWWW.$wwwPathGraphs.$host->m_id."/";
//if there is no host graph directory, make it
if(!file_exists($pathHostGraphs))
{
echo date("Ymd H:i:s")." Creating directory \"$pathHostGraphs\"\n";
mkdir($pathHostGraphs);
}
if(!isset($searchSubhost) or $searchSubhost == "all" or $searchSubhost == "none")
{
//for each nonwalk graph, create the graph
foreach($host->m_graphs as $graph)
{
foreach($aGraphTimeframes as $timeframe)
{
//set graph variables
$filenameRRD = $pathRRD.$host->m_id."/".$host->m_id.".rrd";
$filenamePNG = $pathHostGraphs.$host->m_id."-".$graph->m_name."-".$timeframe->m_desc.".png";
$title = $graph->m_title." - ".$timeframe->m_desc." - ".$host->m_id;
$timeStart = $timeframe->m_timeStart;
$timeEnd = $timeframe->m_timeEnd;
$height = 60;
$width = 400;
eval("\$cmdLine = \"".addslashes($graph->m_cmdLine)."\";");
if(isset($graph->m_args))
$cmdLine .= " ".$graph->m_args;
$cmdLine .= " --color BACK#00000000 --color CANVAS#ffffff --color ARROW#00000000 --color SHADEA#00000000 --color SHADEB#00000000 --disable-rrdtool-tag";
echo date("Ymd H:i:s")." Creating graph \"$filenamePNG\"\n";
// echo "\"$cmdLine\".\n" ;
runExternal($cmdLine);
if(isset($graph->m_bPreview))
{
$filenamePNG = $pathHostGraphs.$host->m_id."-".$graph->m_name."-".$timeframe->m_desc."-preview.png";
$height = 30;
$width = 150;
eval("\$cmdLine = \"".addslashes($graph->m_cmdLine)."\";");
//change command line to create thumbnail
$cmdLine .= " --title=\"\" --vertical-label=\"\" --color BACK#00000000 --color CANVAS#ffffff --color ARROW#00000000 --color SHADEA#00000000 --color SHADEB#00000000 --no-legend --disable-rrdtool-tag";
echo date("Ymd H:i:s")." Creating graph \"$filenamePNG\"\n";
// echo "\"$cmdLine\".\n" ;
runExternal($cmdLine);
}
}
}
}
foreach($aCollectedHosts[$host->m_id]->m_subhosts as $subhost)
{
if(isset($searchSubhost) and $searchSubhost != "all" and $subhost != $searchSubhost)
continue;
$pathSubhostGraphs = $pathHostGraphs.$subhost."/";
if(!file_exists($pathSubhostGraphs))
{
echo date("Ymd H:i:s")." Creating directory \"$pathSubhostGraphs\"\n";
mkdir($pathSubhostGraphs);
}
foreach($host->m_graphsWalk as $graph)
{
foreach($aGraphTimeframes as $timeframe)
{
//set graph variables
$filenameRRD = $pathRRD.$host->m_id."/".$host->m_id."-".$subhost.".rrd";
$filenamePNG = $pathSubhostGraphs.$host->m_id."-".$subhost."-".$graph->m_name."-".$timeframe->m_desc.".png";
$title = $graph->m_title." - ".$timeframe->m_desc." - ".$host->m_id."-".$subhost;
$timeStart = $timeframe->m_timeStart;
$timeEnd = $timeframe->m_timeEnd;
$height = 60;
$width = 400;
eval("\$cmdLine = \"".addslashes($graph->m_cmdLine)."\";");
$cmdLine .= " --color BACK#00000000 --color CANVAS#ffffff --color ARROW#00000000 --color SHADEA#00000000 --color SHADEB#00000000 --disable-rrdtool-tag";
// These graphs are generated in realtime
// echo date("Ymd H:i:s")." Creating graph \"$filenamePNG\"\n";
// runExternal($cmdLine);
if(isset($graph->m_bPreview))
{
$filenamePNG = $pathSubhostGraphs.$host->m_id."-".$subhost."-".$graph->m_name."-".$timeframe->m_desc."-preview.png";
$height = 30;
$width = 150;
eval("\$cmdLine = \"".addslashes($graph->m_cmdLine)."\";");
//change command line to create thumbnail
$cmdLine .= " --title=\"\" --vertical-label=\"\" --color BACK#00000000 --color CANVAS#ffffff --color ARROW#00000000 --color SHADEA#00000000 --color SHADEB#00000000 --no-legend --disable-rrdtool-tag";
echo date("Ymd H:i:s")." Creating graph \"$filenamePNG\"\n";
$cmdLine .= " --color BACK#00000000 --color CANVAS#ffffff --color ARROW#00000000 --color SHADEA#00000000 --color SHADEB#00000000 --disable-rrdtool-tag";
// echo "\"$cmdLine\".\n" ;
runExternal($cmdLine);
}
}
}
}
}
echo date("Ymd H:i:s")." Done building graphs.\n";
?>