Skip to content
This repository has been archived by the owner on Mar 19, 2020. It is now read-only.

Commit

Permalink
Merge branch 'prom-2.2' into 'master'
Browse files Browse the repository at this point in the history
add 2.2 api endpoints

See merge request klatys/papi!3
  • Loading branch information
Jan Klat committed Jun 1, 2018
2 parents 921b656 + 0505504 commit 1bf3d51
Show file tree
Hide file tree
Showing 14 changed files with 2,953 additions and 25 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Targets to provide simple means for obtaining data from Prometheus API.

Stable for [Prometheus 1.x and <= v2.1 api spec](https://prometheus.io/docs/prometheus/2.1/querying/api/)
Stable for [Prometheus 1.x and <= v2.2 api spec](https://prometheus.io/docs/prometheus/2.2/querying/api/)
NOTICE: some endpoints are only available in newer versions of Prometheus. For detailed list see [table of available calls](#available-calls) below.

## Instalation
Expand Down Expand Up @@ -47,12 +47,14 @@ PApi currently has methods for all available endpoints provided by Prometheus.

| Call | Code | Prometheus compatibility | Official doc |
| --------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------ | ------------------------------------------------------------------------------------------------ |
| Query | `$client->getQuery('up', new \DateTimeImmutable('now');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#instant-queries) |
| QueryRange | `$client->getQueryRange('up', new \DateTimeImmutable('today'), new \DateTimeImmutable('now'), '12h');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#range-queries) |
| Series | `$client->getSeries(['up'], new \DateTimeImmutable('-1 minute'), new \DateTimeImmutable('now');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#finding-series-by-label-matchers) |
| Label Values | `$client->getLabelValues('job');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#querying-label-values) |
| Targets (active only) | `$client->getTargets();` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#targets) |
| Alert Managers | `$client->getAlertManagers();` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#alertmanagers) |
| Create snapshot | `$client->createSnapshot();` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#snapshot) |
| Delete series | `$client->deleteSeries(['up'], new DateTimeImmutable('today'), new DateTimeImmutable('now');` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#delete-series) |
| Clean tombstones | `$client->cleanTombstones();` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#clean-tombstones) |
| Query | `$client->getQuery('up', new \DateTimeImmutable('now');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#instant-queries) |
| QueryRange | `$client->getQueryRange('up', new \DateTimeImmutable('today'), new \DateTimeImmutable('now'), '12h');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#range-queries) |
| Series | `$client->getSeries(['up'], new \DateTimeImmutable('-1 minute'), new \DateTimeImmutable('now');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#finding-series-by-label-matchers) |
| Label Values | `$client->getLabelValues('job');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#querying-label-values) |
| Targets (active only) | `$client->getTargets();` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#targets) |
| Alert Managers | `$client->getAlertManagers();` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#alertmanagers) |
| Create snapshot | `$client->createSnapshot();` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#snapshot) |
| Delete series | `$client->deleteSeries(['up'], new DateTimeImmutable('today'), new DateTimeImmutable('now');` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#delete-series) |
| Clean tombstones | `$client->cleanTombstones();` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#clean-tombstones) |
| Get Config | `$client->getConfig();` | >=2.2 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#config) |
| Get Flags | `$client->getFlags();` | >=2.2 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#flags) |
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"php": ">=7.1",
"ext-curl": "*",
"skrz/meta": "^3.1",
"symfony/finder": "~2.7|~3.0|~4.0"
"symfony/finder": "~2.7|~3.0|~4.0",
"symfony/yaml": "~2.7|~3.0|~4.0"
},
"require-dev": {
"cdn77/coding-standard": "^0.5",
Expand Down
21 changes: 18 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use PApi\Connection\CurlConnection;
use PApi\Response\ArrayValuesResponse;
use PApi\Response\DataResponse;
use PApi\Response\FlagsDataResponse;
use PApi\Response\Meta\ArrayValuesResponseMeta;
use PApi\Response\Meta\DataResponseMeta;
use PApi\Response\Meta\FlagsDataResponseMeta;

class Client
{
Expand Down Expand Up @@ -118,11 +120,14 @@ public function getQuery(
}

/**
* Make sure to enable admin APIs via `--web.enable-admin-api`
* Make sure to enable admin APIs via `--web.enable-admin-api`.
* Skip head option is only relevant for Prometheus 2.2+
*/
public function createSnapshot() : DataResponse
public function createSnapshot(bool $skipHead = false) : DataResponse
{
return DataResponseMeta::fromJson($this->connection->executePost('admin/tsdb/snapshot'));
return DataResponseMeta::fromJson($this->connection->executePost('admin/tsdb/snapshot', [
'skip_head' => $skipHead,
]));
}

/**
Expand All @@ -147,4 +152,14 @@ public function cleanTombstones() : bool
$this->connection->executePost('admin/tsdb/clean_tombstones');
return true;
}

public function getConfig() : DataResponse
{
return DataResponseMeta::fromJson($this->connection->executeGet('status/config'));
}

public function getFlags() : FlagsDataResponse
{
return FlagsDataResponseMeta::fromJson($this->connection->executeGet('status/flags'));
}
}
263 changes: 263 additions & 0 deletions src/Response/FlagsData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
<?php

declare (strict_types=1);

namespace PApi\Response;

use Skrz\Meta\PHP\PhpArrayOffset;

class FlagsData
{
/**
* @PhpArrayOffset("alertmanager.notification-queue-capacity", group="json:")
* @var string
*/
protected $alertmanagerNotificationQueueCapacity;

/**
* @PhpArrayOffset("alertmanager.timeout", group="json:")
* @var string
*/
protected $alertmanagerTimeout;

/**
* @PhpArrayOffset("config.file", group="json:")
* @var string
*/
protected $configFile;

/**
* @PhpArrayOffset("log.level", group="json:")
* @var string
*/
protected $logLevel;

/**
* @PhpArrayOffset("query.lookback-delta", group="json:")
* @var string
*/
protected $queryLookbackDelta;

/**
* @PhpArrayOffset("query.max-concurrency", group="json:")
* @var string
*/
protected $queryMaxConcurrency;

/**
* @PhpArrayOffset("query.timeout", group="json:")
* @var string
*/
protected $queryTimeout;

/**
* @PhpArrayOffset("storage.tsdb.max-block-duration", group="json:")
* @var string
*/
protected $storageTsdbMaxBlockDuration;

/**
* @PhpArrayOffset("storage.tsdb.min-block-duration", group="json:")
* @var string
*/
protected $storageTsdbMinBlockDuration;

/**
* @PhpArrayOffset("storage.tsdb.path", group="json:")
* @var string
*/
protected $storageTsdbPath;

/**
* @PhpArrayOffset("storage.tsdb.retention", group="json:")
* @var string
*/
protected $storageTsdbRetention;

/**
* @PhpArrayOffset("storage.tsdb.use-lockfile", group="json:")
* @var string
*/
protected $storageTsdbUseLockfile;

/**
* @PhpArrayOffset("web.console.libraries", group="json:")
* @var string
*/
protected $webConsoleLibraries;

/**
* @PhpArrayOffset("web.console.templates", group="json:")
* @var string
*/
protected $webConsoleTemplates;

/**
* @PhpArrayOffset("web.enable-admin-api", group="json:")
* @var string
*/
protected $webEnableAdminApi;

/**
* @PhpArrayOffset("web.enable-lifecycle", group="json:")
* @var string
*/
protected $webEnableLifecycle;

/**
* @PhpArrayOffset("web.external-url", group="json:")
* @var string
*/
protected $webExternalUrl;

/**
* @PhpArrayOffset("web.listen-address", group="json:")
* @var string
*/
protected $webListenAddress;

/**
* @PhpArrayOffset("web.local-assets", group="json:")
* @var string
*/
protected $webLocalAssets;

/**
* @PhpArrayOffset("web.max-connections", group="json:")
* @var string
*/
protected $webMaxConnections;

/**
* @PhpArrayOffset("web.read-timeout", group="json:")
* @var string
*/
protected $webReadTimeout;

/**
* @PhpArrayOffset("web.route-prefix", group="json:")
* @var string
*/
protected $webRoutePrefix;

/**
* @PhpArrayOffset("web.user-assets", group="json:")
* @var string
*/
protected $webUserAssets;

public function getAlertmanagerNotificationQueueCapacity() : string
{
return $this->alertmanagerNotificationQueueCapacity;
}

public function getAlertmanagerTimeout() : string
{
return $this->alertmanagerTimeout;
}

public function getConfigFile() : string
{
return $this->configFile;
}

public function getLogLevel() : string
{
return $this->logLevel;
}

public function getQueryLookbackDelta() : string
{
return $this->queryLookbackDelta;
}

public function getQueryMaxConcurrency() : string
{
return $this->queryMaxConcurrency;
}

public function getQueryTimeout() : string
{
return $this->queryTimeout;
}

public function getStorageTsdbMaxBlockDuration() : string
{
return $this->storageTsdbMaxBlockDuration;
}

public function getStorageTsdbMinBlockDuration() : string
{
return $this->storageTsdbMinBlockDuration;
}

public function getStorageTsdbPath() : string
{
return $this->storageTsdbPath;
}

public function getStorageTsdbRetention() : string
{
return $this->storageTsdbRetention;
}

public function getStorageTsdbUseLockfile() : string
{
return $this->storageTsdbUseLockfile;
}

public function getWebConsoleLibraries() : string
{
return $this->webConsoleLibraries;
}

public function getWebConsoleTemplates() : string
{
return $this->webConsoleTemplates;
}

public function getWebEnableAdminApi() : string
{
return $this->webEnableAdminApi;
}

public function getWebEnableLifecycle() : string
{
return $this->webEnableLifecycle;
}

public function getWebExternalUrl() : string
{
return $this->webExternalUrl;
}

public function getWebListenAddress() : string
{
return $this->webListenAddress;
}

public function getWebLocalAssets() : string
{
return $this->webLocalAssets;
}

public function getWebMaxConnections() : string
{
return $this->webMaxConnections;
}

public function getWebReadTimeout() : string
{
return $this->webReadTimeout;
}

public function getWebRoutePrefix() : string
{
return $this->webRoutePrefix;
}

public function getWebUserAssets() : string
{
return $this->webUserAssets;
}
}
16 changes: 16 additions & 0 deletions src/Response/FlagsDataResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare (strict_types=1);

namespace PApi\Response;

class FlagsDataResponse extends Response
{
/** @var FlagsData */
protected $data;

public function getData() : FlagsData
{
return $this->data;
}
}
Loading

0 comments on commit 1bf3d51

Please sign in to comment.