/**
  * \brief test for Bytes2Human
  */
 function test_Bytes2Human()
 {
     print "test function Bytes2Human()\n";
     $Bytes = 1073741824;
     $result = Bytes2Human($Bytes);
     $this->assertEquals("1 GB", $result);
     $Bytes = 10240;
     $result = Bytes2Human($Bytes);
     $this->assertEquals("10 KB", $result);
 }
Exemplo n.º 2
0
 /**
  * \brief Display the info data associated with the file.
  */
 function ShowView($Upload, $Item, $ShowMenu = 0)
 {
     global $PG_CONN;
     $V = "";
     if (empty($Upload) || empty($Item)) {
         return;
     }
     $Page = GetParm("page", PARM_INTEGER);
     if (empty($Page)) {
         $Page = 0;
     }
     $Max = 50;
     $Offset = $Page * $Max;
     /**********************************
        List File Info
        **********************************/
     if ($Page == 0) {
         $text = _("Repository Locator");
         $V .= "<H2>{$text}</H2>\n";
         $sql = "SELECT * FROM uploadtree\n        INNER JOIN pfile ON uploadtree_pk = {$Item}\n        AND pfile_fk = pfile_pk\n        LIMIT 1;";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $R = pg_fetch_assoc($result);
         pg_free_result($result);
         $V .= "<table border=1>\n";
         $text = _("Attribute");
         $text1 = _("Value");
         $V .= "<tr><th>{$text}</th><th>{$text1}</th></tr>\n";
         $Bytes = $R['pfile_size'];
         $BytesH = Bytes2Human($Bytes);
         $Bytes = number_format($Bytes, 0, "", ",");
         if ($BytesH == $Bytes) {
             $BytesH = "";
         } else {
             $BytesH = '(' . $BytesH . ')';
         }
         $text = _("File Size");
         $V .= "<tr><td align='center'>{$text}</td><td align='right'>{$Bytes} {$BytesH}</td></tr>\n";
         $text = _("SHA1 Checksum");
         $V .= "<tr><td align='center'>{$text}</td><td align='right'>" . $R['pfile_sha1'] . "</td></tr>\n";
         $text = _("MD5 Checksum");
         $V .= "<tr><td align='center'>{$text}</td><td align='right'>" . $R['pfile_md5'] . "</td></tr>\n";
         $text = _("Repository ID");
         $V .= "<tr><td align='center'>{$text}</td><td align='right'>" . $R['pfile_sha1'] . "." . $R['pfile_md5'] . "." . $R['pfile_size'] . "</td></tr>\n";
         $text = _("Pfile ID");
         $V .= "<tr><td align='center'>{$text}</td><td align='right'>" . $R['pfile_fk'] . "</td></tr>\n";
         $V .= "</table>\n";
     }
     return $V;
 }
 /**
  * \brief Database metrics
  * \returns html table containing metrics
  */
 function DatabaseMetrics()
 {
     global $PG_CONN;
     $V = "<table border=1>\n";
     $text = _("Metric");
     $text1 = _("Total");
     $V .= "<tr><th>{$text}</th><th>{$text1}</th></tr>\n";
     /* Database size */
     $sql = "SELECT pg_database_size('fossology') as val;";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $Size = Bytes2Human($row['val']);
     pg_free_result($result);
     $text = _("FOSSology database size");
     $V .= "<tr><td>{$text}</td>";
     $V .= "<td align='right'>  {$Size} </td></tr>\n";
     /**** Version ****/
     $sql = "SELECT * from version();";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     pg_free_result($result);
     $version = explode(' ', $row['version'], 3);
     $text = _("Postgresql version");
     $V .= "<tr><td>{$text}</td>";
     $V .= "<td align='right'>  {$version['1']} </td></tr>\n";
     // Get the current query column name in pg_stat_activity
     if (strcmp($version[1], "9.2") >= 0) {
         // when greater than PostgreSQL 9.2 replace "current_query" with "state"
         $current_query = "state";
     } else {
         $current_query = "current_query";
     }
     /**** Query stats ****/
     // count current queries
     $sql = "SELECT count(*) AS val FROM pg_stat_activity";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $connection_count = '';
     $connection_count = $row['val'];
     pg_free_result($result);
     /**** Active connection count ****/
     $text = _("Active database connections");
     $V .= "<tr><td>{$text}</td>";
     $V .= "<td align='right'>" . number_format($connection_count, 0, "", ",") . "</td></tr>\n";
     $sql = "SELECT count(*) AS val FROM pg_stat_activity WHERE {$current_query} != '<IDLE>' AND datname = 'fossology';";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $item_count = $row['val'];
     pg_free_result($result);
     $V .= "</table>\n";
     return $V;
 }