Beispiel #1
0
function status()
{
    $sock = new sockets();
    $datas = explode("\n", $sock->getfile('?psprocesses'));
    while (list($num, $ligne) = each($datas)) {
        if (preg_match('#([0-9]+)\\s+([0-9]+)\\s+([a-zA-Z\\-\\.0-9]+)#', $ligne, $regs)) {
            $proc = $regs[3];
            $mem1 = $regs[1] + $regs[2];
            $follow_arr[$proc]["MEM"] = $follow_arr[$proc]["MEM"] + $mem1;
            $follow_arr[$proc]["PROC"] = $follow_arr[$proc]["PROC"] + 1;
        }
    }
    if (!is_array($follow_arr)) {
        $tpl = new templates('{global_services_status}', '{error_no_socks}');
        echo $tpl->web_page;
        exit;
    }
    $html = "<h2>{services_status}</h2>\n\t<table >\n\t<tr class=rowA>\n\t<td><strong>{service_name}</td>\n\t<td><strong>{global_memory}</td>\n\t<td><strong>{process_number}</td>\n\t</tr>";
    while (list($num, $ligne) = each($follow_arr)) {
        if (array_stats($num)) {
            if ($class == 'rowA') {
                $class = 'rowB';
            } else {
                $class = "rowA";
            }
            $mem = round($ligne["MEM"] / 1024);
            $html = $html . "\n\t<tr class={$class}>\n\t<td>{$num}</td>\n\t<td>{$mem} mb</td>\n\t<td>{$ligne["PROC"]}</td>\n\t</tr>";
        }
    }
    $html = $html . "</table>";
    $tpl = new templates('{global_services_status}', $html);
    echo $tpl->web_page;
}
Beispiel #2
0
<?php

// Get Timezones Contained In a Region
// INCLUDE: {report: "functions.php"}
// VARIABLE: {
//      name: "region",
//      display: "Region Code",
//      type: "select",
//      options: ["cdt","acst","pdt"],
//      default: "acst"
// }
// CHART: {type: "LineChart"}
$timezone_abbreviations = DateTimeZone::listAbbreviations();
// If an invalid timezone abbreviation is passed in, show an error to the user
if (!isset($timezone_abbreviations[$region])) {
    throw new Exception("Invalid region - " . $region);
}
// Build report rows
$rows = array();
foreach ($timezone_abbreviations[$region] as $timezone) {
    $rows[] = array('Timezone' => $timezone['timezone_id'], 'Offset' => $timezone['offset'] / 3600);
}
// Add an AVERAGE Row at the bottom
// The array_stats function is defined in the included report functions.php
// This is just a demo.  Normally, you would just use the ROLLUP header for something like this
$stats = array_stats($rows, 'Offset');
$rows[] = array('Timezone' => 'AVERAGE', 'Offset' => $stats['mean']);
// Output the rows
echo json_encode($rows);
Beispiel #3
0
<?php

// Returning ALL of multiple values
function array_stats($values)
{
    $min = min($values);
    $max = max($values);
    $mean = array_sum($values) / count($values);
    return array($min, $max, $mean);
}
$values = array(1, 3, 5, 9, 13, 1442);
list($min, $max, $mean) = array_stats($values);
print $min . " " . $max . " " . $mean . "<br>";
// Returning selected values
function time_parts($time)
{
    return explode(':', $time);
}
list(, $minute, ) = time_parts('12:34:56');
print $minute . "<br>";
/* Obtaining selected read-in info
while ($fields = fgetcsv($fh, 4096)) {
  print $fields[2] . "\n"; // the third field
}*/
?>