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

Commit 1bf3d51

Browse files
author
Jan Klat
committed
Merge branch 'prom-2.2' into 'master'
add 2.2 api endpoints See merge request klatys/papi!3
2 parents 921b656 + 0505504 commit 1bf3d51

14 files changed

+2953
-25
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

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

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

4848
| Call | Code | Prometheus compatibility | Official doc |
4949
| --------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------ | ------------------------------------------------------------------------------------------------ |
50-
| Query | `$client->getQuery('up', new \DateTimeImmutable('now');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#instant-queries) |
51-
| 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) |
52-
| 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) |
53-
| Label Values | `$client->getLabelValues('job');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#querying-label-values) |
54-
| Targets (active only) | `$client->getTargets();` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#targets) |
55-
| Alert Managers | `$client->getAlertManagers();` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#alertmanagers) |
56-
| Create snapshot | `$client->createSnapshot();` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#snapshot) |
57-
| 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) |
58-
| Clean tombstones | `$client->cleanTombstones();` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.1/querying/api/#clean-tombstones) |
50+
| Query | `$client->getQuery('up', new \DateTimeImmutable('now');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#instant-queries) |
51+
| 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) |
52+
| 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) |
53+
| Label Values | `$client->getLabelValues('job');` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#querying-label-values) |
54+
| Targets (active only) | `$client->getTargets();` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#targets) |
55+
| Alert Managers | `$client->getAlertManagers();` | >=1.0 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#alertmanagers) |
56+
| Create snapshot | `$client->createSnapshot();` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#snapshot) |
57+
| 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) |
58+
| Clean tombstones | `$client->cleanTombstones();` | >=2.1 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#clean-tombstones) |
59+
| Get Config | `$client->getConfig();` | >=2.2 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#config) |
60+
| Get Flags | `$client->getFlags();` | >=2.2 | [doc](https://prometheus.io/docs/prometheus/2.2/querying/api/#flags) |

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"php": ">=7.1",
99
"ext-curl": "*",
1010
"skrz/meta": "^3.1",
11-
"symfony/finder": "~2.7|~3.0|~4.0"
11+
"symfony/finder": "~2.7|~3.0|~4.0",
12+
"symfony/yaml": "~2.7|~3.0|~4.0"
1213
},
1314
"require-dev": {
1415
"cdn77/coding-standard": "^0.5",

src/Client.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
use PApi\Connection\CurlConnection;
99
use PApi\Response\ArrayValuesResponse;
1010
use PApi\Response\DataResponse;
11+
use PApi\Response\FlagsDataResponse;
1112
use PApi\Response\Meta\ArrayValuesResponseMeta;
1213
use PApi\Response\Meta\DataResponseMeta;
14+
use PApi\Response\Meta\FlagsDataResponseMeta;
1315

1416
class Client
1517
{
@@ -118,11 +120,14 @@ public function getQuery(
118120
}
119121

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

128133
/**
@@ -147,4 +152,14 @@ public function cleanTombstones() : bool
147152
$this->connection->executePost('admin/tsdb/clean_tombstones');
148153
return true;
149154
}
155+
156+
public function getConfig() : DataResponse
157+
{
158+
return DataResponseMeta::fromJson($this->connection->executeGet('status/config'));
159+
}
160+
161+
public function getFlags() : FlagsDataResponse
162+
{
163+
return FlagsDataResponseMeta::fromJson($this->connection->executeGet('status/flags'));
164+
}
150165
}

src/Response/FlagsData.php

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
5+
namespace PApi\Response;
6+
7+
use Skrz\Meta\PHP\PhpArrayOffset;
8+
9+
class FlagsData
10+
{
11+
/**
12+
* @PhpArrayOffset("alertmanager.notification-queue-capacity", group="json:")
13+
* @var string
14+
*/
15+
protected $alertmanagerNotificationQueueCapacity;
16+
17+
/**
18+
* @PhpArrayOffset("alertmanager.timeout", group="json:")
19+
* @var string
20+
*/
21+
protected $alertmanagerTimeout;
22+
23+
/**
24+
* @PhpArrayOffset("config.file", group="json:")
25+
* @var string
26+
*/
27+
protected $configFile;
28+
29+
/**
30+
* @PhpArrayOffset("log.level", group="json:")
31+
* @var string
32+
*/
33+
protected $logLevel;
34+
35+
/**
36+
* @PhpArrayOffset("query.lookback-delta", group="json:")
37+
* @var string
38+
*/
39+
protected $queryLookbackDelta;
40+
41+
/**
42+
* @PhpArrayOffset("query.max-concurrency", group="json:")
43+
* @var string
44+
*/
45+
protected $queryMaxConcurrency;
46+
47+
/**
48+
* @PhpArrayOffset("query.timeout", group="json:")
49+
* @var string
50+
*/
51+
protected $queryTimeout;
52+
53+
/**
54+
* @PhpArrayOffset("storage.tsdb.max-block-duration", group="json:")
55+
* @var string
56+
*/
57+
protected $storageTsdbMaxBlockDuration;
58+
59+
/**
60+
* @PhpArrayOffset("storage.tsdb.min-block-duration", group="json:")
61+
* @var string
62+
*/
63+
protected $storageTsdbMinBlockDuration;
64+
65+
/**
66+
* @PhpArrayOffset("storage.tsdb.path", group="json:")
67+
* @var string
68+
*/
69+
protected $storageTsdbPath;
70+
71+
/**
72+
* @PhpArrayOffset("storage.tsdb.retention", group="json:")
73+
* @var string
74+
*/
75+
protected $storageTsdbRetention;
76+
77+
/**
78+
* @PhpArrayOffset("storage.tsdb.use-lockfile", group="json:")
79+
* @var string
80+
*/
81+
protected $storageTsdbUseLockfile;
82+
83+
/**
84+
* @PhpArrayOffset("web.console.libraries", group="json:")
85+
* @var string
86+
*/
87+
protected $webConsoleLibraries;
88+
89+
/**
90+
* @PhpArrayOffset("web.console.templates", group="json:")
91+
* @var string
92+
*/
93+
protected $webConsoleTemplates;
94+
95+
/**
96+
* @PhpArrayOffset("web.enable-admin-api", group="json:")
97+
* @var string
98+
*/
99+
protected $webEnableAdminApi;
100+
101+
/**
102+
* @PhpArrayOffset("web.enable-lifecycle", group="json:")
103+
* @var string
104+
*/
105+
protected $webEnableLifecycle;
106+
107+
/**
108+
* @PhpArrayOffset("web.external-url", group="json:")
109+
* @var string
110+
*/
111+
protected $webExternalUrl;
112+
113+
/**
114+
* @PhpArrayOffset("web.listen-address", group="json:")
115+
* @var string
116+
*/
117+
protected $webListenAddress;
118+
119+
/**
120+
* @PhpArrayOffset("web.local-assets", group="json:")
121+
* @var string
122+
*/
123+
protected $webLocalAssets;
124+
125+
/**
126+
* @PhpArrayOffset("web.max-connections", group="json:")
127+
* @var string
128+
*/
129+
protected $webMaxConnections;
130+
131+
/**
132+
* @PhpArrayOffset("web.read-timeout", group="json:")
133+
* @var string
134+
*/
135+
protected $webReadTimeout;
136+
137+
/**
138+
* @PhpArrayOffset("web.route-prefix", group="json:")
139+
* @var string
140+
*/
141+
protected $webRoutePrefix;
142+
143+
/**
144+
* @PhpArrayOffset("web.user-assets", group="json:")
145+
* @var string
146+
*/
147+
protected $webUserAssets;
148+
149+
public function getAlertmanagerNotificationQueueCapacity() : string
150+
{
151+
return $this->alertmanagerNotificationQueueCapacity;
152+
}
153+
154+
public function getAlertmanagerTimeout() : string
155+
{
156+
return $this->alertmanagerTimeout;
157+
}
158+
159+
public function getConfigFile() : string
160+
{
161+
return $this->configFile;
162+
}
163+
164+
public function getLogLevel() : string
165+
{
166+
return $this->logLevel;
167+
}
168+
169+
public function getQueryLookbackDelta() : string
170+
{
171+
return $this->queryLookbackDelta;
172+
}
173+
174+
public function getQueryMaxConcurrency() : string
175+
{
176+
return $this->queryMaxConcurrency;
177+
}
178+
179+
public function getQueryTimeout() : string
180+
{
181+
return $this->queryTimeout;
182+
}
183+
184+
public function getStorageTsdbMaxBlockDuration() : string
185+
{
186+
return $this->storageTsdbMaxBlockDuration;
187+
}
188+
189+
public function getStorageTsdbMinBlockDuration() : string
190+
{
191+
return $this->storageTsdbMinBlockDuration;
192+
}
193+
194+
public function getStorageTsdbPath() : string
195+
{
196+
return $this->storageTsdbPath;
197+
}
198+
199+
public function getStorageTsdbRetention() : string
200+
{
201+
return $this->storageTsdbRetention;
202+
}
203+
204+
public function getStorageTsdbUseLockfile() : string
205+
{
206+
return $this->storageTsdbUseLockfile;
207+
}
208+
209+
public function getWebConsoleLibraries() : string
210+
{
211+
return $this->webConsoleLibraries;
212+
}
213+
214+
public function getWebConsoleTemplates() : string
215+
{
216+
return $this->webConsoleTemplates;
217+
}
218+
219+
public function getWebEnableAdminApi() : string
220+
{
221+
return $this->webEnableAdminApi;
222+
}
223+
224+
public function getWebEnableLifecycle() : string
225+
{
226+
return $this->webEnableLifecycle;
227+
}
228+
229+
public function getWebExternalUrl() : string
230+
{
231+
return $this->webExternalUrl;
232+
}
233+
234+
public function getWebListenAddress() : string
235+
{
236+
return $this->webListenAddress;
237+
}
238+
239+
public function getWebLocalAssets() : string
240+
{
241+
return $this->webLocalAssets;
242+
}
243+
244+
public function getWebMaxConnections() : string
245+
{
246+
return $this->webMaxConnections;
247+
}
248+
249+
public function getWebReadTimeout() : string
250+
{
251+
return $this->webReadTimeout;
252+
}
253+
254+
public function getWebRoutePrefix() : string
255+
{
256+
return $this->webRoutePrefix;
257+
}
258+
259+
public function getWebUserAssets() : string
260+
{
261+
return $this->webUserAssets;
262+
}
263+
}

src/Response/FlagsDataResponse.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
5+
namespace PApi\Response;
6+
7+
class FlagsDataResponse extends Response
8+
{
9+
/** @var FlagsData */
10+
protected $data;
11+
12+
public function getData() : FlagsData
13+
{
14+
return $this->data;
15+
}
16+
}

0 commit comments

Comments
 (0)