Compare commits
No commits in common. "ba8158f35e13670b5014ea315a86eb9d545d4bfe" and "7c79ea3b6bb2b5d4a6d0ed34f771e5f81f7477db" have entirely different histories.
ba8158f35e
...
7c79ea3b6b
@ -7,25 +7,7 @@ $config = [
|
||||
],
|
||||
'app_demo_metric2' => [
|
||||
'help' => 'Help text for metric',
|
||||
'http' => [
|
||||
'url' => 'http://example.com', // The url to get collected for the metric
|
||||
'data' => 'responsebody', // The body is used as output
|
||||
],
|
||||
'httpurl' => 'http://example.com', // The url to get collected for the metric
|
||||
'jsonelem' => '0.metric',
|
||||
],
|
||||
'app_demo_metric3' => [
|
||||
'help' => 'Help text for metric',
|
||||
'http' => [
|
||||
'url' => 'http://example.com', // The url to get collected for the metric
|
||||
'data' => 'hasresponse', // If an error occured during request this will return 0, otherwise 1
|
||||
],
|
||||
],
|
||||
'app_demo_metric4' => [
|
||||
'help' => 'Help text for metric',
|
||||
'http' => [
|
||||
'url' => 'http://example.com', // The url to get collected for the metric
|
||||
'data' => 'responsetime', // This will return the transfer time
|
||||
'proxy' => 'http://192.168.1.252:8080', // The proxy server the request needs to use
|
||||
],
|
||||
],
|
||||
];
|
32
index.php
32
index.php
@ -2,46 +2,20 @@
|
||||
require 'vendor/autoload.php';
|
||||
require 'config.php';
|
||||
|
||||
if($_SERVER["REQUEST_URI"] == '/metrics' || php_sapi_name() == 'cli') {
|
||||
if($_SERVER["REQUEST_URI"] == '/metrics') {
|
||||
foreach ($config as $key => &$c) {
|
||||
if(isset($c['command'])) {
|
||||
$output=null;
|
||||
$retval=null;
|
||||
exec($c['command'], $output, $retval);
|
||||
$output = implode("\n", $output);
|
||||
} elseif(isset($c['http'])) {
|
||||
} elseif(isset($c['httpurl'])) {
|
||||
$client = new GuzzleHttp\Client();
|
||||
|
||||
$options = [];
|
||||
$output = NULL;
|
||||
if (isset($c['http']['proxy'])) {
|
||||
$options['proxy'] = $c['http']['proxy'];
|
||||
}
|
||||
if (isset($c['http']['data']) && $c['http']['data'] == 'responsetime') {
|
||||
$options['on_stats'] = function (GuzzleHttp\TransferStats $stats) use (&$output) {
|
||||
$output = $stats->getTransferTime();
|
||||
};
|
||||
}
|
||||
|
||||
$hasresponse = NULL;
|
||||
try{
|
||||
$res = $client->request('GET', $c['http']['url'], $options);
|
||||
$hasresponse = true;
|
||||
} catch(GuzzleHttp\Exception\GuzzleException $e) {
|
||||
$hasresponse = false;
|
||||
}
|
||||
|
||||
if (isset($c['http']['data']) && $c['http']['data'] == 'responsebody') {
|
||||
$res = $client->get($c['httpurl']);
|
||||
$output = $res->getBody()->getContents();
|
||||
} elseif (isset($c['http']['data']) && $c['http']['data'] == 'hasresponse') {
|
||||
$output = (int)$hasresponse;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($c['jsonelem'])) {
|
||||
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));
|
||||
} else {
|
||||
$c['value'] = $output;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user