|
1 | | -import { AxiosResponse, InternalAxiosRequestConfig } from 'axios'; |
2 | | -import { QueryResult, Metric, RuleGroup, Alert, TargetState, SerieSelector } from './types'; |
3 | | -export declare type PrometheusConnectionAuth = { |
4 | | - username: string; |
5 | | - password: string; |
6 | | -}; |
7 | | -export declare type PrometheusConnectionProxy = { |
8 | | - host: string; |
9 | | - port: number; |
10 | | -}; |
11 | | -export declare class PrometheusConnectionOptions { |
12 | | - endpoint: string; |
13 | | - baseURL?: string; |
14 | | - headers?: object; |
15 | | - auth?: PrometheusConnectionAuth; |
16 | | - proxy?: PrometheusConnectionProxy; |
17 | | - withCredentials?: boolean; |
18 | | - timeout?: number; |
19 | | - preferPost?: boolean; |
20 | | - requestInterceptor?: { |
21 | | - onFulfilled: (value: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>; |
22 | | - onRejected?: (error: any) => any; |
23 | | - }; |
24 | | - responseInterceptor?: { |
25 | | - onFulfilled: (value: AxiosResponse) => AxiosResponse | Promise<AxiosResponse>; |
26 | | - onRejected?: (error: any) => any; |
27 | | - }; |
28 | | - warningHook?: (any: any) => any; |
29 | | -} |
30 | | -export declare type PrometheusQueryDate = Date | number; |
31 | | -export declare class PrometheusDriver { |
32 | | - private options; |
33 | | - private axiosInstance; |
34 | | - /** |
35 | | - * Creates a PrometheusDriver client |
36 | | - * `options` has the following fields: |
37 | | - * - endpoint: address of Prometheus instance |
38 | | - * - baseURL: base path of Prometheus API (default: /api/v1) |
39 | | - * - headers: headers to be sent (k/v format) |
40 | | - * - auth: {username: 'foo', password: 'bar'}: basic auth |
41 | | - * - proxy: {host: '127.0.0.1', port: 9000}: hostname and port of a proxy server |
42 | | - * - withCredentials: indicates whether or not cross-site Access-Control requests |
43 | | - * - timeout: number of milliseconds before the request times out |
44 | | - * - warningHook: a hook for handling warning messages |
45 | | - * @param {*} options |
46 | | - */ |
47 | | - constructor(options: PrometheusConnectionOptions); |
48 | | - private request; |
49 | | - private handleResponse; |
50 | | - private formatTimeToPrometheus; |
51 | | - private listifyIfNeeded; |
52 | | - private formatPromQlParams; |
53 | | - /*********************** EXPRESSION QUERIES ***********************/ |
54 | | - /** |
55 | | - * Evaluates an instant query at a single point in time |
56 | | - * @param {*} query Prometheus expression query string. |
57 | | - * @param {*} time Evaluation Date object or number in milliseconds. Optional. |
58 | | - * @param {*} timeout Evaluation timeout string. Optional. |
59 | | - */ |
60 | | - instantQuery(query: string, time?: PrometheusQueryDate, timeout?: string): Promise<QueryResult>; |
61 | | - /** |
62 | | - * Evaluates an expression query over a range of time |
63 | | - * @param {*} query Prometheus expression query string. |
64 | | - * @param {*} start Start Date object or number in milliseconds. |
65 | | - * @param {*} end End Date object or number in milliseconds. |
66 | | - * @param {*} step Query resolution step width in duration format or number of seconds. |
67 | | - * @param {*} timeout Evaluation timeout string. Optional. |
68 | | - */ |
69 | | - rangeQuery(query: string, start: PrometheusQueryDate, end: PrometheusQueryDate, step: string | number, timeout?: string): Promise<QueryResult>; |
70 | | - /*********************** METADATA API ***********************/ |
71 | | - /** |
72 | | - * Finding series by label matchers |
73 | | - * @param {*} matchs Repeated series selector argument that selects the series to return. |
74 | | - * @param {*} start Start Date object or number in milliseconds. |
75 | | - * @param {*} end End Date object or number in milliseconds. |
76 | | - */ |
77 | | - series(matchs: SerieSelector, start: PrometheusQueryDate, end: PrometheusQueryDate): Promise<Metric[]>; |
78 | | - /** |
79 | | - * Getting label names |
80 | | - * @param {*} matchs Repeated series selector argument that selects the series to return. Optional. |
81 | | - * @param {*} start Start Date object or number in milliseconds. Optional. |
82 | | - * @param {*} end End Date object or number in milliseconds. Optional. |
83 | | - */ |
84 | | - labelNames(matchs?: SerieSelector, start?: PrometheusQueryDate, end?: PrometheusQueryDate): Promise<string[]>; |
85 | | - /** |
86 | | - * Getting label values |
87 | | - * @param {*} labelName Label name to query values for. |
88 | | - * @param {*} matchs Repeated series selector argument that selects the series to return. Optional. |
89 | | - * @param {*} start Start Date object or number in milliseconds. Optional. |
90 | | - * @param {*} end End Date object or number in milliseconds. Optional. |
91 | | - */ |
92 | | - labelValues(labelName: string, matchs?: SerieSelector, start?: PrometheusQueryDate, end?: PrometheusQueryDate): Promise<string[]>; |
93 | | - /** |
94 | | - * Overview of the current state of the Prometheus target discovery: |
95 | | - * @param {*} state Filter by target state. Can be 'active', 'dropped' or 'any'. Optional. |
96 | | - */ |
97 | | - targets(state?: TargetState): Promise<object>; |
98 | | - /** |
99 | | - * Returns metadata about metrics currently scraped from targets. |
100 | | - * @param {*} matchTarget Label selectors that match targets by their label sets. Optional. |
101 | | - * @param {*} metric Metric name to retrieve metadata for. Optional. |
102 | | - * @param {*} limit Maximum number of targets to match. Optional. |
103 | | - */ |
104 | | - targetsMetadata(matchTarget: SerieSelector, metric?: string, limit?: number): Promise<any>; |
105 | | - /** |
106 | | - * Metadata about metrics currently scrapped from targets |
107 | | - * @param {*} metric Metric name to retrieve metadata for. Optional. |
108 | | - * @param {*} limit Maximum number of targets to match. Optional. |
109 | | - */ |
110 | | - metadata(metric?: string, limit?: number): Promise<any>; |
111 | | - /*********************** SERIES API ***********************/ |
112 | | - /** |
113 | | - * Getting a list of alerting and recording rules |
114 | | - */ |
115 | | - rules(): Promise<RuleGroup[]>; |
116 | | - /** |
117 | | - * Returns a list of all active alerts. |
118 | | - */ |
119 | | - alerts(): Promise<Alert[]>; |
120 | | - /** |
121 | | - * Returns an overview of the current state of the Prometheus alertmanager discovery. |
122 | | - */ |
123 | | - alertmanagers(): Promise<any>; |
124 | | - /*********************** STATUS API ***********************/ |
125 | | - /** |
126 | | - * Following status endpoints expose current Prometheus configuration. |
127 | | - */ |
128 | | - status(): Promise<any>; |
129 | | - /** |
130 | | - * Returns flag values that Prometheus was configured with. |
131 | | - * New in v2.2 |
132 | | - */ |
133 | | - statusFlags(): Promise<any>; |
134 | | - /** |
135 | | - * Returns runtime information properties that Prometheus was configured with. |
136 | | - * New in v2.14 |
137 | | - */ |
138 | | - statusRuntimeInfo(): Promise<any>; |
139 | | - /** |
140 | | - * Returns various build information properties about Prometheus Server. |
141 | | - */ |
142 | | - statusBuildinfo(): Promise<any>; |
143 | | - /** |
144 | | - * Returns various cardinality statistics about the Prometheus TSDB. |
145 | | - * New in v2.14 |
146 | | - */ |
147 | | - statusTSDB(): Promise<any>; |
148 | | - /*********************** ADMIN API ***********************/ |
149 | | - /** |
150 | | - * Creates a snapshot of all current data |
151 | | - * New in v2.1 |
152 | | - * @param {*} skipHead Skip data present in the head block. Boolean. Optional. |
153 | | - */ |
154 | | - adminSnapshot(skipHead?: boolean): Promise<any>; |
155 | | - /** |
156 | | - * Deletes data for a selection of series in a time range |
157 | | - * New in v2.1 |
158 | | - * @param {*} matchs Repeated series selector argument that selects the series to return. |
159 | | - * @param {*} start Start Date object or number in milliseconds. |
160 | | - * @param {*} end End Date object or number in milliseconds. |
161 | | - */ |
162 | | - adminDeleteSeries(matchs: SerieSelector, start: PrometheusQueryDate, end: PrometheusQueryDate): Promise<any>; |
163 | | - /** |
164 | | - * Removes the deleted data from disk and cleans up |
165 | | - * New in v2.1 |
166 | | - */ |
167 | | - adminCleanTombstones(): Promise<any>; |
168 | | -} |
| 1 | +import { AxiosResponse, InternalAxiosRequestConfig } from 'axios'; |
| 2 | +import { QueryResult, Metric, RuleGroup, Alert, TargetState, SerieSelector } from './types'; |
| 3 | +export type PrometheusConnectionAuth = { |
| 4 | + username: string; |
| 5 | + password: string; |
| 6 | +}; |
| 7 | +export type PrometheusConnectionProxy = { |
| 8 | + host: string; |
| 9 | + port: number; |
| 10 | +}; |
| 11 | +export declare class PrometheusConnectionOptions { |
| 12 | + endpoint: string; |
| 13 | + baseURL?: string; |
| 14 | + headers?: object; |
| 15 | + auth?: PrometheusConnectionAuth; |
| 16 | + proxy?: PrometheusConnectionProxy; |
| 17 | + withCredentials?: boolean; |
| 18 | + timeout?: number; |
| 19 | + preferPost?: boolean; |
| 20 | + requestInterceptor?: { |
| 21 | + onFulfilled: (value: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>; |
| 22 | + onRejected?: (error: any) => any; |
| 23 | + }; |
| 24 | + responseInterceptor?: { |
| 25 | + onFulfilled: (value: AxiosResponse) => AxiosResponse | Promise<AxiosResponse>; |
| 26 | + onRejected?: (error: any) => any; |
| 27 | + }; |
| 28 | + warningHook?: (any: any) => any; |
| 29 | +} |
| 30 | +export type PrometheusQueryDate = Date | number; |
| 31 | +export declare class PrometheusDriver { |
| 32 | + private options; |
| 33 | + private axiosInstance; |
| 34 | + /** |
| 35 | + * Creates a PrometheusDriver client |
| 36 | + * `options` has the following fields: |
| 37 | + * - endpoint: address of Prometheus instance |
| 38 | + * - baseURL: base path of Prometheus API (default: /api/v1) |
| 39 | + * - headers: headers to be sent (k/v format) |
| 40 | + * - auth: {username: 'foo', password: 'bar'}: basic auth |
| 41 | + * - proxy: {host: '127.0.0.1', port: 9000}: hostname and port of a proxy server |
| 42 | + * - withCredentials: indicates whether or not cross-site Access-Control requests |
| 43 | + * - timeout: number of milliseconds before the request times out |
| 44 | + * - warningHook: a hook for handling warning messages |
| 45 | + * @param {*} options |
| 46 | + */ |
| 47 | + constructor(options: PrometheusConnectionOptions); |
| 48 | + private request; |
| 49 | + /** |
| 50 | + * Normalises Axios successes **and** failures to a single shape. |
| 51 | + * When `isError` is true we know `input` is an `AxiosError`. |
| 52 | + */ |
| 53 | + private handleResponse; |
| 54 | + private formatTimeToPrometheus; |
| 55 | + private listifyIfNeeded; |
| 56 | + private formatPromQlParams; |
| 57 | + /*********************** EXPRESSION QUERIES ***********************/ |
| 58 | + /** |
| 59 | + * Evaluates an instant query at a single point in time |
| 60 | + * @param {*} query Prometheus expression query string. |
| 61 | + * @param {*} time Evaluation Date object or number in milliseconds. Optional. |
| 62 | + * @param {*} timeout Evaluation timeout string. Optional. |
| 63 | + */ |
| 64 | + instantQuery(query: string, time?: PrometheusQueryDate, timeout?: string): Promise<QueryResult>; |
| 65 | + /** |
| 66 | + * Evaluates an expression query over a range of time |
| 67 | + * @param {*} query Prometheus expression query string. |
| 68 | + * @param {*} start Start Date object or number in milliseconds. |
| 69 | + * @param {*} end End Date object or number in milliseconds. |
| 70 | + * @param {*} step Query resolution step width in duration format or number of seconds. |
| 71 | + * @param {*} timeout Evaluation timeout string. Optional. |
| 72 | + */ |
| 73 | + rangeQuery(query: string, start: PrometheusQueryDate, end: PrometheusQueryDate, step: string | number, timeout?: string): Promise<QueryResult>; |
| 74 | + /*********************** METADATA API ***********************/ |
| 75 | + /** |
| 76 | + * Finding series by label matchers |
| 77 | + * @param {*} matchs Repeated series selector argument that selects the series to return. |
| 78 | + * @param {*} start Start Date object or number in milliseconds. |
| 79 | + * @param {*} end End Date object or number in milliseconds. |
| 80 | + */ |
| 81 | + series(matchs: SerieSelector, start: PrometheusQueryDate, end: PrometheusQueryDate): Promise<Metric[]>; |
| 82 | + /** |
| 83 | + * Getting label names |
| 84 | + * @param {*} matchs Repeated series selector argument that selects the series to return. Optional. |
| 85 | + * @param {*} start Start Date object or number in milliseconds. Optional. |
| 86 | + * @param {*} end End Date object or number in milliseconds. Optional. |
| 87 | + */ |
| 88 | + labelNames(matchs?: SerieSelector, start?: PrometheusQueryDate, end?: PrometheusQueryDate): Promise<string[]>; |
| 89 | + /** |
| 90 | + * Getting label values |
| 91 | + * @param {*} labelName Label name to query values for. |
| 92 | + * @param {*} matchs Repeated series selector argument that selects the series to return. Optional. |
| 93 | + * @param {*} start Start Date object or number in milliseconds. Optional. |
| 94 | + * @param {*} end End Date object or number in milliseconds. Optional. |
| 95 | + */ |
| 96 | + labelValues(labelName: string, matchs?: SerieSelector, start?: PrometheusQueryDate, end?: PrometheusQueryDate): Promise<string[]>; |
| 97 | + /** |
| 98 | + * Overview of the current state of the Prometheus target discovery: |
| 99 | + * @param {*} state Filter by target state. Can be 'active', 'dropped' or 'any'. Optional. |
| 100 | + */ |
| 101 | + targets(state?: TargetState): Promise<object>; |
| 102 | + /** |
| 103 | + * Returns metadata about metrics currently scraped from targets. |
| 104 | + * @param {*} matchTarget Label selectors that match targets by their label sets. Optional. |
| 105 | + * @param {*} metric Metric name to retrieve metadata for. Optional. |
| 106 | + * @param {*} limit Maximum number of targets to match. Optional. |
| 107 | + */ |
| 108 | + targetsMetadata(matchTarget: SerieSelector, metric?: string, limit?: number): Promise<any>; |
| 109 | + /** |
| 110 | + * Metadata about metrics currently scrapped from targets |
| 111 | + * @param {*} metric Metric name to retrieve metadata for. Optional. |
| 112 | + * @param {*} limit Maximum number of targets to match. Optional. |
| 113 | + */ |
| 114 | + metadata(metric?: string, limit?: number): Promise<any>; |
| 115 | + /*********************** SERIES API ***********************/ |
| 116 | + /** |
| 117 | + * Getting a list of alerting and recording rules |
| 118 | + */ |
| 119 | + rules(): Promise<RuleGroup[]>; |
| 120 | + /** |
| 121 | + * Returns a list of all active alerts. |
| 122 | + */ |
| 123 | + alerts(): Promise<Alert[]>; |
| 124 | + /** |
| 125 | + * Returns an overview of the current state of the Prometheus alertmanager discovery. |
| 126 | + */ |
| 127 | + alertmanagers(): Promise<any>; |
| 128 | + /*********************** STATUS API ***********************/ |
| 129 | + /** |
| 130 | + * Following status endpoints expose current Prometheus configuration. |
| 131 | + */ |
| 132 | + status(): Promise<any>; |
| 133 | + /** |
| 134 | + * Returns flag values that Prometheus was configured with. |
| 135 | + * New in v2.2 |
| 136 | + */ |
| 137 | + statusFlags(): Promise<any>; |
| 138 | + /** |
| 139 | + * Returns runtime information properties that Prometheus was configured with. |
| 140 | + * New in v2.14 |
| 141 | + */ |
| 142 | + statusRuntimeInfo(): Promise<any>; |
| 143 | + /** |
| 144 | + * Returns various build information properties about Prometheus Server. |
| 145 | + */ |
| 146 | + statusBuildinfo(): Promise<any>; |
| 147 | + /** |
| 148 | + * Returns various cardinality statistics about the Prometheus TSDB. |
| 149 | + * New in v2.14 |
| 150 | + */ |
| 151 | + statusTSDB(): Promise<any>; |
| 152 | + /*********************** ADMIN API ***********************/ |
| 153 | + /** |
| 154 | + * Creates a snapshot of all current data |
| 155 | + * New in v2.1 |
| 156 | + * @param {*} skipHead Skip data present in the head block. Boolean. Optional. |
| 157 | + */ |
| 158 | + adminSnapshot(skipHead?: boolean): Promise<any>; |
| 159 | + /** |
| 160 | + * Deletes data for a selection of series in a time range |
| 161 | + * New in v2.1 |
| 162 | + * @param {*} matchs Repeated series selector argument that selects the series to return. |
| 163 | + * @param {*} start Start Date object or number in milliseconds. |
| 164 | + * @param {*} end End Date object or number in milliseconds. |
| 165 | + */ |
| 166 | + adminDeleteSeries(matchs: SerieSelector, start: PrometheusQueryDate, end: PrometheusQueryDate): Promise<any>; |
| 167 | + /** |
| 168 | + * Removes the deleted data from disk and cleans up |
| 169 | + * New in v2.1 |
| 170 | + */ |
| 171 | + adminCleanTombstones(): Promise<any>; |
| 172 | +} |
0 commit comments