A simple Object Oriented library for Prometheus API
You can simply Download the Release, and to include the autoloader
require_once '/path/to/your-project/vendor/autoload.php';API utilizes the DotEnv PHP library by Vance Lucas. In the root directory of your application will contain a .env file.
Set your prometheus URL
PROMETHEUS_URL="https://prometheus.yourdomain.com"
Detect an AJAX request
AJAX_DETECT=0
This determines whether errors should be printed to the screen as part of the output. Default "0".
SHOW_ERRORS=0
Tells whether script error messages should be logged library log. Default "1".
LOG_ERRORS=1
We need to create application so that we can run it and send the responses back.
$app = new \core\Application();Then We set request parameters
$app->setParams([
'endpoint' => Request::QUERY,
]);And We can to send request
$app->send_request();The sections below describe the API endpoints for each type of expression query.
prometheus.yourdomain.com/api/v1/query?query=function(index{conditions}[offset_modifier])[range_vector_selectors:]
$app->setParams([
'endpoint' => Request::QUERY,
'func' => [
'name' => 'irate',
'offset_modifier' => '5m',
],
'index' => [
'name' => 'ifHCInOctets',
'conditions' => [
'instance' => '127.0.0.1',
'ifIndex' => 1
],
],
'range_vector_selectors' => '1h'
]);Then send request
$res = $app->send_request();$app->setParams([
'endpoint' => Request::LABELS,
]);Then send request
$res = $app->send_request();$app->setParams([
'endpoint' => Request::LABELS,
]);Then send request
$res = $app->send_request();You can use curl and jq as that checks response (JSON)
curl -g "https://prometheus.yourdomain.com/prometheus-api/index.php" | jq