21 define(
"TITLE_DASHBOARD_GENERAL", _(
"Overview Dashboard"));
32 function __construct()
34 $this->Name =
"dashboard";
35 $this->Title = TITLE_DASHBOARD_GENERAL;
36 $this->MenuList =
"Admin::Dashboards::Overview";
38 parent::__construct();
39 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
49 "select sum(reltuples) as val from pg_class where relname like $1 and reltype !=0",
52 $item_count = $row[
'val'];
54 $V =
"<tr><td>$TableLabel</td>";
55 $V .=
"<td align='right'>" . number_format($item_count,0,
"",
",") .
"</td>";
57 $LastVacTime = $this->GetLastVacTime($TableName);
58 if (empty($LastVacTime)) {
59 $mystyle =
"style=background-color:red";
63 $V .=
"<td $mystyle>" . substr($LastVacTime, 0, 16) .
"</td>";
65 $LastAnalyzeTime = $this->GetLastAnalyzeTime($TableName);
66 if (empty($LastAnalyzeTime)) {
67 $mystyle =
"style=background-color:red";
71 $V .=
"<td $mystyle>" . substr($LastAnalyzeTime, 0, 16) .
"</td>";
83 $V =
"<table border=1>\n";
87 $head3 = _(
"Last<br>Vacuum");
88 $head4 = _(
"Last<br>Analyze");
89 $V .=
"<tr><th>$head1</th><th>$head2</th><th>$head3</th><th>$head4</th></tr>\n";
114 function GetLastAnalyzeTimeOrVacTime($queryPart,$TableName)
116 $sql =
"select greatest($queryPart) as lasttime from pg_stat_all_tables where schemaname = 'public' and relname like $1";
117 $row = $this->
dbManager->getSingleRow($sql, array($TableName), __METHOD__);
119 return $row[
"lasttime"];
122 function GetLastVacTime($TableName)
124 return $this->GetLastAnalyzeTimeOrVacTime(
"last_vacuum, last_autovacuum",$TableName);
127 function GetPHPInfoTable()
129 $PHP_VERSION = phpversion();
130 $loadedModules = get_loaded_extensions();
133 <table class='infoTable' border=1> 155 <td><div class='infoTable'>";
156 foreach ($loadedModules as $currentExtensionName) {
157 $currentVersion = phpversion($currentExtensionName);
158 $table .= $currentExtensionName .
": " . $currentVersion .
"<br />";
161 $table .=
"</div></td> 170 function GetLastAnalyzeTime($TableName)
172 return $this->GetLastAnalyzeTimeOrVacTime(
"last_analyze, last_autoanalyze",
184 $V =
"<table border=1>\n";
187 $V .=
"<tr><th>$text</th><th>$text1</th></tr>\n";
190 $sql =
"SELECT pg_database_size('fossology') as val;";
191 $row = $this->
dbManager->getSingleRow($sql, array(), __METHOD__.
"get_Size");
193 $text = _(
"FOSSology database size");
194 $V .=
"<tr><td>$text</td>";
195 $V .=
"<td align='right'> $Size </td></tr>\n";
198 $text = _(
"Postgresql version");
199 $V .=
"<tr><td>$text</td>";
200 $V .=
"<td align='right'> {$this->pgVersion['server']} </td></tr>\n";
204 $sql =
"SELECT count(*) AS val FROM pg_stat_activity";
205 $row = $this->
dbManager->getSingleRow($sql, array(), __METHOD__.
"get_connection_count");
206 $connection_count = $row[
'val'];
209 $text = _(
"Active database connections");
210 $V .=
"<tr><td>$text</td>";
211 $V .=
"<td align='right'>" . number_format($connection_count,0,
"",
",") .
"</td></tr>\n";
225 $V =
"<table border=1 id='databaseTable'>\n";
228 $head3 = _(
"Started");
229 $head4 = _(
"Elapsed");
230 $V .=
"<tr><th>$head1</th><th>$head2</th><th>$head3</th><th>$head4</th></tr>\n";
231 $getCurrentVersion = explode(
" ", $this->pgVersion[
'server']);
232 $currentVersion = str_replace(
".",
"", $getCurrentVersion[0]);
233 unset($getCurrentVersion);
234 $oldVersion = str_replace(
".",
"",
"9.2");
235 $current_query = ($currentVersion >= $oldVersion) ?
"state" :
"current_query";
236 $procpid = ($currentVersion >= $oldVersion) ?
"pid" :
"procpid";
237 $sql =
"SELECT $procpid processid, $current_query, query_start, now()-query_start AS elapsed FROM pg_stat_activity WHERE $current_query != '<IDLE>' AND datname = 'fossology' ORDER BY $procpid";
239 $statementName = __METHOD__.
"queryFor_".$current_query.
"_orderBy_".$procpid;
240 $this->
dbManager->prepare($statementName,$sql);
241 $result = $this->
dbManager->execute($statementName, array());
243 if (pg_num_rows($result) > 1) {
244 while ($row = pg_fetch_assoc($result)) {
245 if ($row[$current_query] == $sql) {
249 $V .=
"<td class='dashboard'>$row[processid]</td>";
250 $V .=
"<td class='dashboard'>" . htmlspecialchars($row[$current_query]) .
253 $V .=
"<td class='dashboard'>$StartTime</td>";
254 $V .=
"<td class='dashboard'>$row[elapsed]</td>";
258 $V .=
"<tr><td class='dashboard' colspan=4>There are no active FOSSology queries</td></tr>";
261 pg_free_result($result);
277 $Buf = $this->
DoCmd($Cmd);
280 $Lines = explode(
"\n",$Buf);
284 $V .=
"<table border=1>\n";
285 $head0 = _(
"Filesystem");
286 $head1 = _(
"Capacity");
288 $head3 = _(
"Available");
289 $head4 = _(
"Percent Full");
290 $head5 = _(
"Mount Point");
291 $V .=
"<tr><th>$head0</th><th>$head1</th><th>$head2</th><th>$head3</th><th>$head4</th><th>$head5</th></tr>\n";
293 foreach ($Lines as $L) {
304 $L = preg_replace(
"/[[:space:]][[:space:]]*/",
" ", $L);
305 $List = explode(
" ", $L);
308 if ($List[0] ==
'tmpfs') {
311 if ($List[0] ==
'udev') {
314 if ($List[0] ==
'none') {
317 if ($List[5] ==
'/boot') {
321 $V .=
"<tr><td>" . htmlentities($List[0]) .
"</td>";
322 $V .=
"<td align='right' style='border-right:none'>$List[1]</td>";
323 $V .=
"<td align='right' style='border-right:none'>$List[2]</td>";
324 $V .=
"<td align='right' style='border-right:none'>$List[3]</td>";
327 $PctFull = (int) $List[4];
329 if ($PctFull > $WarnAtPct) {
330 $mystyle =
"style=border-right:none;background-color:red";
332 $mystyle =
"style='border-right:none'";
334 $V .=
"<td align='right' $mystyle>$List[4]</td>";
336 $V .=
"<td align='left'>" . htmlentities($List[5]) .
"</td></tr>\n";
341 $V .= _(
"Note:") .
"<br>";
342 $Indent =
" ";
345 $V .= $Indent . _(
"Database").
": " .
" ";
349 $Cmd =
"ps -eo cmd | grep postgres | grep -- -D";
350 $Buf = $this->
DoCmd($Cmd);
352 $DargToEndOfStr =
trim(substr($Buf, strpos($Buf,
"-D") + 2 ));
353 $DargArray = explode(
' ', $DargToEndOfStr);
354 $V .= $DargArray[0] .
"<br>";
357 $V .= $Indent . _(
"Repository") .
": " . $SysConf[
'FOSSOLOGY'][
'path'] .
"<br>";
360 $V .= $Indent . _(
"FOSSology config") .
": " . $SYSCONFDIR .
"<br>";
365 public function Output()
368 $this->pgVersion = pg_version($PG_CONN);
371 $V .=
"<table style='width: 100%;' border=0>\n";
373 $V .=
"<td valign='top'>\n";
374 $text = _(
"Database Contents");
375 $V .=
"<h2>$text</h2>\n";
379 $V .=
"<td class='dashboard'>\n";
380 $text = _(
"Database Metrics");
381 $V .=
"<h2>$text</h2>\n";
387 $V .=
"<td class='dashboard'>";
388 $text = _(
"Active FOSSology queries");
389 $V .=
"<h2>$text</h2>\n";
393 $V .=
"<td class='dashboard'>";
394 $text = _(
"PHP Info");
395 $V .=
"<h2>$text</h2>\n";
396 $V .= $this->GetPHPInfoTable();
401 $V .=
"<td class='dashboard'>";
402 $text = _(
"Disk Space");
403 $V .=
"<h2>$text</h2>\n";
420 $fin = popen($cmd,
"r");
422 while (! feof($fin)) {
423 $buffer .= fread($fin, 8192);
431 $NewPlugin->Initialize();
DatabaseContentsRow($TableName, $TableLabel)
Return each html row for DatabaseContents()
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
DoCmd($cmd)
execute a shell command
DatabaseContents()
Database Contents metrics.
DatabaseMetrics()
Database metrics.
fo_dbManager * dbManager
fo_dbManager object
This is the Plugin class. All plugins should:
DatabaseQueries()
Database queries.
DiskFree()
Determine amount of free disk space.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
HumanSize($bytes)
Translate a byte number to a proper type, xxx bytes to xxx B/KB/MB/GB/TB/PB.
char * trim(char *ptext)
Trimming whitespace.