예제 #1
0
function rrd_xload()
{
    $filetime = "/etc/artica-postfix/pids/rrd.load.time";
    $unix = new unix();
    if (!$GLOBALS["FORCE"]) {
        $timeN = $unix->file_time_sec($filetime);
        if ($timeN < 120) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$timeN}/120, abroting\n";
            }
            return;
        }
    }
    @unlink($filetime);
    @file_put_contents($filetime, time());
    if (!is_dir("/usr/share/artica-postfix/ressources/databases/rrd")) {
        @mkdir("/usr/share/artica-postfix/ressources/databases/rrd", 0755, true);
    }
    if (!is_file("/usr/share/artica-postfix/ressources/databases/rrd/load.rrd")) {
        echo "Creating load.rrd\n";
        $opts = array("--step", "120", "--start", 0, "DS:load:GAUGE:120:U:U", "RRA:AVERAGE:0.5:1:1440", "RRA:AVERAGE:0.5:6:1800", "RRA:AVERAGE:0.5:24:1800", "RRA:AVERAGE:0.5:288:1800", "RRA:MIN:0.5:1:1440", "RRA:MIN:0.5:6:1800", "RRA:MIN:0.5:24:1800", "RRA:MIN:0.5:288:1800", "RRA:MAX:0.5:1:1440", "RRA:MAX:0.5:6:1800", "RRA:MAX:0.5:24:1800", "RRA:MAX:0.5:288:1800");
        $ret = @rrd_create("/usr/share/artica-postfix/ressources/databases/rrd/load.rrd", $opts, count($opts));
        if ($ret == 0) {
            $err = rrd_error();
            echo "Create error: {$err}\n";
        }
    }
    $array_load = sys_getloadavg();
    $internal_load = $array_load[0];
    $t = time();
    echo "Load:{$internal_load}\n";
    //$internal_load=str_replace(".", ",", $internal_load);
    $ret = rrd_update("/usr/share/artica-postfix/ressources/databases/rrd/load.rrd", "{$t}:{$internal_load}");
    if ($ret == 0) {
        $err = rrd_error();
        echo "update error: {$err}\n";
    }
    create_graph("/usr/share/artica-postfix/ressources/logs/web/load.png", "-1h", "Load Hourly");
}
예제 #2
0
function main()
{
    global $matching_path;
    $have_tree = false;
    $have_taxa = false;
    $have_table = false;
    $newick = '';
    if (isset($_POST['tree'])) {
        $obj = parse_nexus(stripcslashes($_POST['tree']));
        $taxa = get_taxa_from_tree($obj);
        $newick = $obj->tree->newick;
        //echo $newick;
        //print_r($obj);
        $t = new Tree();
        $t->Parse($newick);
        $ni = new NodeIterator($t->getRoot());
        $q = $ni->Begin();
        while ($q != NULL) {
            if ($q->IsLeaf()) {
                if (isset($obj->translations->translate)) {
                    $q->SetLabel($obj->translations->translate[$q->GetLabel()]);
                }
            }
            $q = $ni->Next();
        }
        $newick = $t->WriteNewick();
        //echo $newick;
        $have_tree = true;
    }
    if (isset($_POST['taxa'])) {
        $have_taxa = true;
    }
    if (isset($_POST['table'])) {
        $table = $_POST['table'];
        $have_table = true;
    }
    if (isset($_POST['newick'])) {
        $newick = $_POST['newick'];
    }
    if ($have_tree || $have_taxa) {
        if ($have_table) {
            // get taxa
            $taxa = explode("\n", stripcslashes($_POST['taxa']));
            $n = count($taxa);
            for ($i = 0; $i < $n; $i++) {
                $taxa[$i] = trim($taxa[$i]);
            }
            // get table data
            $table = stripcslashes($_POST['table']);
            // Interpret table automatically...
            // assume column one contains OTUs, and some other column(s) have lat and long
            $data = extract_table($table);
            //print_r($data);
            if (count($taxa) != count($data)) {
                echo '<html>
	<head>
	<meta charset="utf-8" />
			<style type="text/css" title="text/css">
			body { font-family:sans-serif;padding:20px; }
			</style>
	<title>Create KML tree - Error</title>
	</head>
	<body>
	<a href=".">Back</a>
	<h1>Error</h1>
	<p>The number of taxa in the tree (' . count($taxa) . ') does not match the number in the table (' . count($data) . ')</p>
	</body>
	</html>';
                exit;
            }
            $data_lookup_by_label = array();
            foreach ($data as $d) {
                $data_lookup_by_label[$d->label] = $d;
            }
            // show matching...
            /*
            echo '			<form method="post" action=".">
            	<table border="1">';
            	
            	echo '<tr><th>Taxa in tree</th><th>Taxa in table</th><th>Latitude</th><th>Longitude</th></tr>';
            	
            	$nrows = count($data);
            	for ($i=0;$i < $nrows; $i++)
            	{
            		echo '<tr>';
            		
            		echo '<td>' . $taxa[$i] . '</td>';
            		echo '<td>' . $data[$i]->label . '</td>';
            		echo '<td>' . $data[$i]->latlong['latitude'] . '</td>';
            		echo '<td>' . $data[$i]->latlong['longitude'] . '</td>';
            		echo '</td></tr>';
            	}					
            
            					
            	
            echo '</table>
            
            	
            	<input type="submit" value="Go"></input>
            </form>';
            */
            // build graph for matching
            // Create GML file for graph linking taxon labels in tree and table
            // Taxon labels in table
            $b = array();
            foreach ($data as $row) {
                $b[] = $row->label;
            }
            $filename = 'tmp/' . uniqid() . '.gml';
            $gml = create_graph($taxa, $b);
            file_put_contents($filename, $gml);
            //echo $gml;
            // Compute maximum weight bipartite matching
            $command = $matching_path . 'matching ' . $filename;
            $output = array();
            exec($command, $output);
            //echo $command;
            $json = join("", $output);
            //echo $json;
            $match = json_decode($json);
            if (0) {
                echo '<pre>';
                $n = count($taxa);
                foreach ($match->matching as $pair) {
                    echo $taxa[$pair[0]] . "|\t" . $b[$pair[1] - $n] . "\n";
                }
                echo '</pre>';
            }
            // Mapping between tree labels and table labels
            $match_by_label = array();
            $n = count($taxa);
            foreach ($match->matching as $pair) {
                $match_by_label[$taxa[$pair[0]]] = $b[$pair[1] - $n];
            }
            // match and build KML file
            $t = new Tree();
            $t->Parse($newick);
            $t->BuildWeights($t->GetRoot());
            //echo $newick;
            $ni = new NodeIterator($t->getRoot());
            $q = $ni->Begin();
            while ($q != NULL) {
                if ($q->IsLeaf()) {
                    $data = $data_lookup_by_label[$match_by_label[$q->GetLabel()]];
                    $q->SetAttribute('lat', $data->latlong['latitude']);
                    $q->SetAttribute('long', $data->latlong['longitude']);
                }
                $q = $ni->Next();
            }
            // KML...
            //echo '<pre>';
            //$t->Dump();
            //echo '</pre>';
            $kml = tree2kml($t);
            echo '<html>
			<head>
			<meta charset="utf-8" />
			<style type="text/css" title="text/css">
			body { font-family:sans-serif;padding:20px; }
			</style>
			<title>Create KML tree - Step 3</title>
   <script type="text/javascript" src="https://www.google.com/jsapi"> </script>
   <script type="text/javascript">
      var ge;
      google.load("earth", "1");

      function init() {
         google.earth.createInstance(\'map3d\', initCB, failureCB);
      }

      function initCB(instance) {
         ge = instance;
         ge.getWindow().setVisibility(true);
         
         var treeDoc = ge.parseKml(';
            $kml_lines = explode("\n", $kml);
            $k = join(" ", $kml_lines);
            echo "'" . $k . "'";
            echo ');	
         ge.getFeatures().appendChild(treeDoc);
         
      }

      function failureCB(errorCode) {
      }

      google.setOnLoadCallback(init);
   </script>
			
			</head>
			<body>
			<a href=".">Home</a>
			<h1>Step 3: Match tree to table and create KML</h1>';
            // Display mapping
            echo '<h2>Tree and table matching</h2>';
            echo '<table border="1">';
            echo '<tr><th>Taxa in tree</th><th>Taxa in table</th><th>Latitude</th><th>Longitude</th></tr>';
            $n = count($taxa);
            foreach ($match->matching as $pair) {
                echo '<tr>';
                echo '<td>';
                echo $taxa[$pair[0]];
                echo '</td>';
                $data = $data_lookup_by_label[$match_by_label[$taxa[$pair[0]]]];
                echo '<td>' . $data->label . '</td>';
                echo '<td>' . $data->latlong['latitude'] . '</td>';
                echo '<td>' . $data->latlong['longitude'] . '</td>';
                echo '</tr>';
            }
            echo '</table>';
            echo '<h2>KML</h2>';
            echo '<textarea rows="30" cols="100">';
            echo $kml;
            echo '</textarea>';
            echo '<h2>Google Earth plugin</h2>';
            echo ' <div id="map3d" style="height: 400px; width: 600px;"></div>';
            echo '</body>
			</html>';
        } else {
            // We have the tree but no data yet
            echo '<html>
			<head>
			<meta charset="utf-8" />
			<style type="text/css" title="text/css">
			body { font-family:sans-serif;padding:20px; }
			</style>
			<title>Create KML tree - Step 2</title>
			</head>
			<body>
			<a href=".">Home</a>
			<h1>Step 2: Add table</h1>
			<form method="post" action=".">
			
				<input name="newick" type="hidden" value="' . $newick . '">
				
				<table>
				<tr><th>Taxa in tree</th><th>Paste in table with taxa (in first column), and latitude and longitude.<br/>The first row of the table must contain column headings.</th></tr>
				<tr>
				<td>
				<textarea id="taxa" name="taxa" rows="30" cols="60" readonly="readonly">' . join("\n", $taxa) . '</textarea>
				</td>
				<td>
				<textarea  id="table" name="table" rows="30" cols="60"></textarea>
				</td>
				</tr>
				</table>
				
				<input type="submit" value="Next step"></input>
			</form>
			</body>
			</html>';
        }
    } else {
        // Starting point, get tree
        echo '<html>
	<head>
	<meta charset="utf-8" />
			<style type="text/css" title="text/css">
			body { font-family:sans-serif;padding:20px; }
			</style>
	<title>Create KML tree - Step 1</title>
	</head>
	<body>
	<h1>Step 1: Paste in a tree in NEXUS format</h1>
	<form method="post" action=".">
		<textarea id="tree" name="tree" rows="30" cols="60"></textarea>
		<br />
		<input type="submit" value="Next step"></input>
	</form>
	</body>
	</html>';
    }
}
예제 #3
0
<?php

require_once 'miner.inc.php';
include_once 'functions.inc.php';
include_once 'settings.inc.php';
create_graph("mhsav-hour.png", "-1h", "Last Hour");
create_graph("mhsav-day.png", "-1d", "Last Day");
create_graph("mhsav-week.png", "-1w", "Last Week");
create_graph("mhsav-month.png", "-1m", "Last Month");
create_graph("mhsav-year.png", "-1y", "Last Year");
function create_graph($output, $start, $title)
{
    $RRDPATH = '/opt/minepeon/var/rrd/';
    $options = array("--slope-mode", "--start", $start, "--title={$title}", "--vertical-label=Hash per second", "--lower=0", "DEF:hashrate=" . $RRDPATH . "hashrate.rrd:hashrate:AVERAGE", "CDEF:realspeed=hashrate,1000,*", "LINE2:realspeed#FF0000");
    $ret = rrd_graph("/opt/minepeon/http/rrd/" . $output, $options);
    if (!$ret) {
        //echo "<b>Graph error: </b>".rrd_error()."\n";
    }
}
if (isset($_POST['url'])) {
    $pools = miner('pools', '')['POOLS'];
    $pool = 0;
    foreach ($pools as $key => $value) {
        if (isset($value['User']) && $value['URL'] == $_POST['url']) {
            miner('switchpool', $pool);
        }
        $pool = $pool + 1;
    }
}
include 'head.php';
?>
예제 #4
0
/**
 * MyBB 1.8
 * Copyright 2014 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybb.com
 * License: http://www.mybb.com/about/license
 *
 */
// Disallow direct access to this file for security reasons
if (!defined("IN_MYBB")) {
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
if ($mybb->input['action'] == "do_graph") {
    $range = array('start' => $mybb->get_input('start', MyBB::INPUT_INT), 'end' => $mybb->get_input('end', MyBB::INPUT_INT));
    create_graph($mybb->input['type'], $range);
    die;
}
$page->add_breadcrumb_item($lang->statistics, "index.php?module=tools-statistics");
$sub_tabs['overall_statistics'] = array('title' => $lang->overall_statistics, 'link' => "index.php?module=tools-statistics", 'description' => $lang->overall_statistics_desc);
$plugins->run_hooks("admin_tools_statistics_begin");
if (!$mybb->input['action']) {
    $query = $db->simple_select("stats", "COUNT(*) as total");
    if ($db->fetch_field($query, "total") == 0) {
        flash_message($lang->error_no_statistics_available_yet, 'error');
        admin_redirect("index.php?module=tools");
    }
    $per_page = 20;
    $plugins->run_hooks("admin_tools_statistics_overall_begin");
    // Do we have date range criteria?
    if ($mybb->input['from_year']) {
예제 #5
0
<?php

require 'miner.inc.php';
include 'settings.inc.php';
echo create_graph('mhsav-hour.png', '-1h', 'Last Hour') && create_graph('mhsav-day.png', '-1d', 'Last Day') && create_graph('mhsav-week.png', '-1w', 'Last Week') && create_graph('mhsav-month.png', '-1m', 'Last Month') && create_graph('mhsav-year.png', '-1y', 'Last Year');
function create_graph($output, $start, $title)
{
    $rrd = '/opt/minepeon/var/rrd/';
    $png = '/opt/minepeon/http/rrd/';
    $options = array('--slope-mode', '--start', $start, '--title=' . $title, '--vertical-label=Hash per second', '--lower=0', '--color=BACK#fff', '--color=CANVAS#fff', '--color=SHADEB#fff', '--color=SHADEA#fff', 'DEF:hashrate=' . $rrd . 'hashrate.rrd:hashrate:AVERAGE', 'CDEF:realspeed=hashrate,1000,*', 'AREA:realspeed#ddd', 'LINE:realspeed#000');
    return rrd_graph($png . $output, $options);
}
예제 #6
0
<?php

if (session_id() == "") {
    session_start();
}
$docroot = $_SERVER['DOCUMENT_ROOT'];
require_once $docroot . "/graphs/phpgraphlib/phpgraphlib.php";
require_once $docroot . "/models/twextra_model.php";
if (isset($_REQUEST['graph_type'])) {
    $graph_type = $_REQUEST['graph_type'];
}
create_graph($graph_type);
function create_graph($graph_type = '')
{
    $graph = new PHPGraphLib(1400, 600);
    $model = new TwextraModel();
    //$data = array("Alex"=>99, "Mary"=>98, "Joan"=>70, "Ed"=>90);
    if ($graph_type == 'daily_stats') {
        $data = $model->get_stats_daily();
        $graph->setTitle("Daily Unique Traffic");
    } else {
        if ($graph_type == 'message_history') {
            //this graph is currently not plotted!
            $screen_name = 'rajen4126';
            $message_from = 0;
            $next = 20;
            $order = 'created';
            $asc_desc = 'desc';
            $length = 20;
            $data = $model->get_message_history($screen_name, $message_from, $next, $order, $asc_desc, $length);
            foreach ($data as $entry) {