10 define(
"TITLE_DASHBOARD_GENERAL", _(
"Overview Dashboard"));
24 $this->Name =
"dashboard";
25 $this->Title = TITLE_DASHBOARD_GENERAL;
26 $this->MenuList =
"Admin::Dashboards::Overview";
28 parent::__construct();
29 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
30 $this->pgVersion = pg_version(
$PG_CONN);
40 "select sum(reltuples) as val from pg_class where relname like $1 and reltype !=0",
43 $item_count = $row[
'val'];
45 $V =
"<tr><td>$TableLabel</td>";
46 $V .=
"<td align='right'>" . number_format($item_count,0,
"",
",") .
"</td>";
48 $LastVacTime = $this->GetLastVacTime($TableName);
49 if (empty($LastVacTime)) {
50 $mystyle =
"style=background-color:red";
54 $V .=
"<td $mystyle>" . substr($LastVacTime, 0, 16) .
"</td>";
56 $LastAnalyzeTime = $this->GetLastAnalyzeTime($TableName);
57 if (empty($LastAnalyzeTime)) {
58 $mystyle =
"style=background-color:red";
62 $V .=
"<td $mystyle>" . substr($LastAnalyzeTime, 0, 16) .
"</td>";
68 "metric" => $TableLabel,
69 "total" => intval($item_count),
70 "lastVacuum" => $LastVacTime,
71 "lastAnalyze" => $LastAnalyzeTime
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($fromRest =
false)
129 $PHP_VERSION = phpversion();
130 $loadedModules = get_loaded_extensions();
135 <table class='infoTable' border=1>
157 <td><div class='infoTable'>";
159 $restRes[
'phpVersion'] = $PHP_VERSION;
160 $restRes[
'loadedExtensions'] = [];
161 foreach ($loadedModules as $currentExtensionName) {
162 $currentVersion = phpversion($currentExtensionName);
163 $table .= $currentExtensionName .
": " . $currentVersion .
"<br />";
164 $restRes[
'loadedExtensions'][] = [
165 'name' => $currentExtensionName,
166 'version' => $currentVersion
170 $table .=
"</div></td>
183 function GetLastAnalyzeTime($TableName)
185 return $this->GetLastAnalyzeTimeOrVacTime(
"last_analyze, last_autoanalyze",
197 $V =
"<table border=1>\n";
200 $V .=
"<tr><th>$text</th><th>$text1</th></tr>\n";
203 $sql =
"SELECT pg_database_size('fossology') as val;";
204 $row = $this->
dbManager->getSingleRow($sql, array(), __METHOD__.
"get_Size");
206 $text = _(
"FOSSology database size");
207 $V .=
"<tr><td>$text</td>";
208 $V .=
"<td align='right'> $Size </td></tr>\n";
212 "total" => $row[
'val']
216 $text = _(
"Postgresql version");
217 $V .=
"<tr><td>$text</td>";
218 $V .=
"<td align='right'> {$this->pgVersion['server']} </td></tr>\n";
222 "total" => $this->pgVersion[
'server']
227 $sql =
"SELECT count(*) AS val FROM pg_stat_activity";
228 $row = $this->
dbManager->getSingleRow($sql, array(), __METHOD__.
"get_connection_count");
229 $connection_count = $row[
'val'];
232 $text = _(
"Active database connections");
233 $V .=
"<tr><td>$text</td>";
234 $V .=
"<td align='right'>" . number_format($connection_count,0,
"",
",") .
"</td></tr>\n";
240 "total" => $connection_count
258 $V =
"<table border=1 id='databaseTable'>\n";
261 $head3 = _(
"Started");
262 $head4 = _(
"Elapsed");
264 $V .=
"<tr><th>$head1</th><th>$head2</th><th>$head3</th><th>$head4</th></tr>\n";
265 $getCurrentVersion = explode(
" ", $this->pgVersion[
'server']);
266 $currentVersion = str_replace(
".",
"", $getCurrentVersion[0]);
267 unset($getCurrentVersion);
268 $oldVersion = str_replace(
".",
"",
"9.2");
269 $current_query = ($currentVersion >= $oldVersion) ?
"state" :
"current_query";
270 $procpid = ($currentVersion >= $oldVersion) ?
"pid" :
"procpid";
271 $sql =
"SELECT $procpid processid, $current_query, query_start AT TIME ZONE 'UTC' AS query_start, now()-query_start AS elapsed FROM pg_stat_activity WHERE $current_query != '<IDLE>' AND datname = 'fossology' ORDER BY $procpid";
273 $statementName = __METHOD__.
"queryFor_".$current_query.
"_orderBy_".$procpid;
274 $this->
dbManager->prepare($statementName,$sql);
275 $result = $this->
dbManager->execute($statementName, array());
277 if (pg_num_rows($result) > 1) {
278 while ($row = pg_fetch_assoc($result)) {
279 if ($row[$current_query] == $sql) {
283 $V .=
"<td class='dashboard'>$row[processid]</td>";
284 $V .=
"<td class='dashboard'>" . htmlspecialchars($row[$current_query]) .
287 $V .=
"<td class='dashboard'>$StartTime</td>";
288 $V .=
"<td class='dashboard'>$row[elapsed]</td>";
290 $dt =
new DateTime($row[
'query_start'],
new DateTimeZone(
"UTC"));
292 "pid" => $row[
'processid'],
293 "query" => htmlspecialchars($row[$current_query]),
294 "startTime" => $dt->format(
"Y-m-d\\TH:i:s.v\\Z"),
295 "elapsed" => $row[
'elapsed']
299 $V .=
"<tr><td class='dashboard' colspan=4>There are no active FOSSology queries</td></tr>";
302 pg_free_result($result);
323 $Buf = $this->
DoCmd($Cmd);
326 $Lines = explode(
"\n",$Buf);
329 $V =
"<table border=1>\n";
330 $head0 = _(
"Filesystem");
331 $head1 = _(
"Capacity");
333 $head3 = _(
"Available");
334 $head4 = _(
"Percent Full");
335 $head5 = _(
"Mount Point");
336 $V .=
"<tr><th>$head0</th><th>$head1</th><th>$head2</th><th>$head3</th><th>$head4</th><th>$head5</th></tr>\n";
338 foreach ($Lines as $L) {
349 $L = preg_replace(
"/[[:space:]][[:space:]]*/",
" ", $L);
350 $List = explode(
" ", $L);
353 if ($List[0] ==
'tmpfs') {
356 if ($List[0] ==
'udev') {
359 if ($List[0] ==
'none') {
362 if ($List[5] ==
'/boot') {
366 $V .=
"<tr><td>" . htmlentities($List[0]) .
"</td>";
367 $V .=
"<td align='right' style='border-right:none'>$List[1]</td>";
368 $V .=
"<td align='right' style='border-right:none'>$List[2]</td>";
369 $V .=
"<td align='right' style='border-right:none'>$List[3]</td>";
372 $PctFull = (int) $List[4];
374 if ($PctFull > $WarnAtPct) {
375 $mystyle =
"style=border-right:none;background-color:red";
377 $mystyle =
"style='border-right:none'";
379 $V .=
"<td align='right' $mystyle>$List[4]</td>";
381 $V .=
"<td align='left'>" . htmlentities($List[5]) .
"</td></tr>\n";
383 $restRes[
"data"][] = [
384 "filesystem" => htmlentities($List[0]),
385 "capacity" => $List[1],
387 "available" => $List[3],
388 "percentFull" => $List[4],
389 "mountPoint" => htmlentities($List[5])
395 $V .= _(
"Note:") .
"<br>";
396 $Indent =
" ";
399 $V .= $Indent . _(
"Database").
": " .
" ";
403 $Cmd =
"ps -eo cmd | grep postgres | grep -- -D";
404 $Buf = $this->
DoCmd($Cmd);
406 $DargToEndOfStr =
trim(substr($Buf, strpos($Buf,
"-D") + 2 ));
407 $DargArray = explode(
' ', $DargToEndOfStr);
408 $V .= $DargArray[0] .
"<br>";
411 $V .= $Indent . _(
"Repository") .
": " . $SysConf[
'FOSSOLOGY'][
'path'] .
"<br>";
414 $V .= $Indent . _(
"FOSSology config") .
": " . $SYSCONFDIR .
"<br>";
416 $restRes[
"notes"] = [
417 "database" => $DargArray[0],
418 "repository" => $SysConf[
'FOSSOLOGY'][
'path'],
419 "fossologyConfig" => $SYSCONFDIR
431 $V =
"<table style='width: 100%;' border=0>\n";
433 $V .=
"<td valign='top'>\n";
434 $text = _(
"Database Contents");
435 $V .=
"<h2>$text</h2>\n";
439 $V .=
"<td class='dashboard'>\n";
440 $text = _(
"Database Metrics");
441 $V .=
"<h2>$text</h2>\n";
447 $V .=
"<td class='dashboard'>";
448 $text = _(
"Active FOSSology queries");
449 $V .=
"<h2>$text</h2>\n";
453 $V .=
"<td class='dashboard'>";
454 $text = _(
"PHP Info");
455 $V .=
"<h2>$text</h2>\n";
456 $V .= $this->GetPHPInfoTable();
461 $V .=
"<td class='dashboard'>";
462 $text = _(
"Disk Space");
463 $V .=
"<h2>$text</h2>\n";
480 $fin = popen($cmd,
"r");
482 while (! feof($fin)) {
483 $buffer .= fread($fin, 8192);
491 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
__construct()
base constructor. Most plugins will just use this
DatabaseContents()
Database Contents metrics.
DatabaseQueries($fromRest=false)
Database queries.
DatabaseMetrics($fromRest=false)
Database metrics.
DiskFree($fromRest=false)
Determine amount of free disk space.
DatabaseContentsRow($TableName, $TableLabel, $fromRest=false)
Return each html row for DatabaseContents()
Output()
This function is called when user output is requested. This function is responsible for content....
DoCmd($cmd)
execute a shell command
HumanSize( $bytes)
Translate a byte number to a proper type, xxx bytes to xxx B/KB/MB/GB/TB/PB.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
fo_dbManager * dbManager
fo_dbManager object