instrument some php
rodzic
954461e94c
commit
814d26f984
|
@ -2,6 +2,8 @@
|
|||
require_once("includes/functions.inc.php");
|
||||
require_once("includes/config.inc.php");
|
||||
|
||||
$stats = new StatsD();
|
||||
|
||||
$action = $_GET['action'];
|
||||
|
||||
$software_available = array("gfs", "gfs_hd");
|
||||
|
@ -19,6 +21,7 @@ case "getCSV":
|
|||
}
|
||||
$returned = json_encode($data);
|
||||
echo $returned;
|
||||
$stats->counting('habhub.predictor.php.get_csv');
|
||||
break;
|
||||
|
||||
case "JSONexists":
|
||||
|
@ -58,6 +61,7 @@ case "getModelByUUID":
|
|||
$pred_model = array();
|
||||
if ( !file_exists(PREDS_PATH . $uuid . "/" . SCENARIO_FILE ) ) {
|
||||
$pred_model['valid'] = false;
|
||||
$stats->counting('habhub.predictor.php.couldnt_get_by_uuid');
|
||||
} else {
|
||||
// populate the array, JSON encode it and return
|
||||
$pred_model = parse_ini_file(PREDS_PATH . $uuid . "/" . SCENARIO_FILE);
|
||||
|
@ -67,6 +71,7 @@ case "getModelByUUID":
|
|||
$pred_model['valid'] = false;
|
||||
}
|
||||
$pred_model['uuid'] = $uuid;
|
||||
$stats->counting('habhub.predictor.php.got_by_uuid');
|
||||
}
|
||||
echo json_encode($pred_model);
|
||||
break;
|
||||
|
@ -83,6 +88,7 @@ case "submitForm":
|
|||
$json_return['error'] = "Server couldn't make a model from the form
|
||||
data";
|
||||
echo json_encode($json_return);
|
||||
$stats->counter('habhub.predictor.php.form_error');
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -91,6 +97,7 @@ case "submitForm":
|
|||
if ( !$verify_dump['valid'] ) {
|
||||
$json_return['error'] = $verify_dump['msg'];
|
||||
echo json_encode($json_return);
|
||||
$stats->counter('habhub.predictor.php.invalid_model')
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -98,6 +105,7 @@ case "submitForm":
|
|||
if ( !$pred_model['uuid'] = makesha1hash($pred_model) ) {
|
||||
$json_return['error'] = "Couldn't make the SHA1 hash";
|
||||
echo json_encode($json_return);
|
||||
$stats->counter('habhub.predictor.php.unhashable');
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -106,10 +114,12 @@ case "submitForm":
|
|||
$json_return['valid'] = "true";
|
||||
$json_return['uuid'] = $pred_model['uuid'];
|
||||
$json_return['timestamp'] = $pred_model['timestamp'];
|
||||
$stats->counting('habhub.predictor.php.prediction_run');
|
||||
|
||||
} else {
|
||||
$json_return['error'] = "The form submit function was called without
|
||||
any data";
|
||||
$stats->counting('habhub.predictor.php.no_form_data');
|
||||
}
|
||||
|
||||
echo json_encode($json_return);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
require_once("config.inc.php");
|
||||
require_once("statsd.php");
|
||||
|
||||
// Given a POST array, create a scenario model
|
||||
function createModel($post_array) {
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* A simple PHP class for interacting with a statsd server
|
||||
* @author John Crepezzi <john.crepezzi@gmail.com>
|
||||
* https://raw.github.com/seejohnrun/php-statsd/master/libraries/statsd.php
|
||||
*/
|
||||
class StatsD {
|
||||
|
||||
private $host, $port;
|
||||
|
||||
// Instantiate a new client
|
||||
public function __construct($host = 'localhost', $port = 8125) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
}
|
||||
|
||||
// Record timing
|
||||
public function timing($key, $time, $rate = 1) {
|
||||
$this->send("$key:$time|ms", $rate);
|
||||
}
|
||||
|
||||
// Time something
|
||||
public function time_this($key, $callback, $rate = 1) {
|
||||
$begin = microtime(true);
|
||||
$callback();
|
||||
$time = floor((microtime(true) - $begin) * 1000);
|
||||
// And record
|
||||
$this->timing($key, $time, $rate);
|
||||
}
|
||||
|
||||
// Record counting
|
||||
public function counting($key, $amount = 1, $rate = 1) {
|
||||
$this->send("$key:$amount|c", $rate);
|
||||
}
|
||||
|
||||
// Send
|
||||
private function send($value, $rate) {
|
||||
$fp = fsockopen('udp://' . $this->host, $this->port, $errno, $errstr);
|
||||
// Will show warning if not opened, and return false
|
||||
if ($fp) {
|
||||
fwrite($fp, "$value|@$rate");
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,10 @@
|
|||
|
||||
require_once("includes/config.inc.php");
|
||||
require_once("includes/functions.inc.php");
|
||||
|
||||
$stats = new StatsD();
|
||||
$stats->counting('hits');
|
||||
|
||||
// Get the time for pre-populating the form
|
||||
$time = time() + 3600;
|
||||
?>
|
||||
|
|
Ładowanie…
Reference in New Issue