UNPKG

15 kBTypeScriptView Raw
1import * as iam from '@aws-cdk/aws-iam';
2import * as cdk from '@aws-cdk/core';
3import * as constructs from 'constructs';
4import { Alarm, ComparisonOperator, TreatMissingData } from './alarm';
5import { IMetric, MetricAlarmConfig, MetricConfig, MetricGraphConfig, Unit } from './metric-types';
6import { Construct } from '@aws-cdk/core';
7export declare type DimensionHash = {
8 [dim: string]: any;
9};
10export declare type DimensionsMap = {
11 [dim: string]: string;
12};
13/**
14 * Options shared by most methods accepting metric options
15 */
16export interface CommonMetricOptions {
17 /**
18 * The period over which the specified statistic is applied.
19 *
20 * @default Duration.minutes(5)
21 */
22 readonly period?: cdk.Duration;
23 /**
24 * What function to use for aggregating.
25 *
26 * Can be one of the following:
27 *
28 * - "Minimum" | "min"
29 * - "Maximum" | "max"
30 * - "Average" | "avg"
31 * - "Sum" | "sum"
32 * - "SampleCount | "n"
33 * - "pNN.NN"
34 *
35 * @default Average
36 */
37 readonly statistic?: string;
38 /**
39 * Dimensions of the metric
40 *
41 * @default - No dimensions.
42 *
43 * @deprecated Use 'dimensionsMap' instead.
44 */
45 readonly dimensions?: DimensionHash;
46 /**
47 * Dimensions of the metric
48 *
49 * @default - No dimensions.
50 */
51 readonly dimensionsMap?: DimensionsMap;
52 /**
53 * Unit used to filter the metric stream
54 *
55 * Only refer to datums emitted to the metric stream with the given unit and
56 * ignore all others. Only useful when datums are being emitted to the same
57 * metric stream under different units.
58 *
59 * The default is to use all matric datums in the stream, regardless of unit,
60 * which is recommended in nearly all cases.
61 *
62 * CloudWatch does not honor this property for graphs.
63 *
64 * @default - All metric datums in the given metric stream
65 */
66 readonly unit?: Unit;
67 /**
68 * Label for this metric when added to a Graph in a Dashboard
69 *
70 * You can use [dynamic labels](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html)
71 * to show summary information about the entire displayed time series
72 * in the legend. For example, if you use:
73 *
74 * ```
75 * [max: ${MAX}] MyMetric
76 * ```
77 *
78 * As the metric label, the maximum value in the visible range will
79 * be shown next to the time series name in the graph's legend.
80 *
81 * @default - No label
82 */
83 readonly label?: string;
84 /**
85 * The hex color code, prefixed with '#' (e.g. '#00ff00'), to use when this metric is rendered on a graph.
86 * The `Color` class has a set of standard colors that can be used here.
87 * @default - Automatic color
88 */
89 readonly color?: string;
90 /**
91 * Account which this metric comes from.
92 *
93 * @default - Deployment account.
94 */
95 readonly account?: string;
96 /**
97 * Region which this metric comes from.
98 *
99 * @default - Deployment region.
100 */
101 readonly region?: string;
102}
103/**
104 * Properties for a metric
105 */
106export interface MetricProps extends CommonMetricOptions {
107 /**
108 * Namespace of the metric.
109 */
110 readonly namespace: string;
111 /**
112 * Name of the metric.
113 */
114 readonly metricName: string;
115}
116/**
117 * Properties of a metric that can be changed
118 */
119export interface MetricOptions extends CommonMetricOptions {
120}
121/**
122 * Configurable options for MathExpressions
123 */
124export interface MathExpressionOptions {
125 /**
126 * Label for this expression when added to a Graph in a Dashboard
127 *
128 * If this expression evaluates to more than one time series (for
129 * example, through the use of `METRICS()` or `SEARCH()` expressions),
130 * each time series will appear in the graph using a combination of the
131 * expression label and the individual metric label. Specify the empty
132 * string (`''`) to suppress the expression label and only keep the
133 * metric label.
134 *
135 * You can use [dynamic labels](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html)
136 * to show summary information about the displayed time series
137 * in the legend. For example, if you use:
138 *
139 * ```
140 * [max: ${MAX}] MyMetric
141 * ```
142 *
143 * As the metric label, the maximum value in the visible range will
144 * be shown next to the time series name in the graph's legend. If the
145 * math expression produces more than one time series, the maximum
146 * will be shown for each individual time series produce by this
147 * math expression.
148 *
149 * @default - Expression value is used as label
150 */
151 readonly label?: string;
152 /**
153 * Color for this metric when added to a Graph in a Dashboard
154 *
155 * @default - Automatic color
156 */
157 readonly color?: string;
158 /**
159 * The period over which the expression's statistics are applied.
160 *
161 * This period overrides all periods in the metrics used in this
162 * math expression.
163 *
164 * @default Duration.minutes(5)
165 */
166 readonly period?: cdk.Duration;
167 /**
168 * Account to evaluate search expressions within.
169 *
170 * Specifying a searchAccount has no effect to the account used
171 * for metrics within the expression (passed via usingMetrics).
172 *
173 * @default - Deployment account.
174 */
175 readonly searchAccount?: string;
176 /**
177 * Region to evaluate search expressions within.
178 *
179 * Specifying a searchRegion has no effect to the region used
180 * for metrics within the expression (passed via usingMetrics).
181 *
182 * @default - Deployment region.
183 */
184 readonly searchRegion?: string;
185}
186/**
187 * Properties for a MathExpression
188 */
189export interface MathExpressionProps extends MathExpressionOptions {
190 /**
191 * The expression defining the metric.
192 *
193 * When an expression contains a SEARCH function, it cannot be used
194 * within an Alarm.
195 */
196 readonly expression: string;
197 /**
198 * The metrics used in the expression, in a map.
199 *
200 * The key is the identifier that represents the given metric in the
201 * expression, and the value is the actual Metric object.
202 *
203 * @default - Empty map.
204 */
205 readonly usingMetrics?: Record<string, IMetric>;
206}
207/**
208 * A metric emitted by a service
209 *
210 * The metric is a combination of a metric identifier (namespace, name and dimensions)
211 * and an aggregation function (statistic, period and unit).
212 *
213 * It also contains metadata which is used only in graphs, such as color and label.
214 * It makes sense to embed this in here, so that compound constructs can attach
215 * that metadata to metrics they expose.
216 *
217 * This class does not represent a resource, so hence is not a construct. Instead,
218 * Metric is an abstraction that makes it easy to specify metrics for use in both
219 * alarms and graphs.
220 */
221export declare class Metric implements IMetric {
222 /**
223 * Grant permissions to the given identity to write metrics.
224 *
225 * @param grantee The IAM identity to give permissions to.
226 */
227 static grantPutMetricData(grantee: iam.IGrantable): iam.Grant;
228 /** Dimensions of this metric */
229 readonly dimensions?: DimensionHash;
230 /** Namespace of this metric */
231 readonly namespace: string;
232 /** Name of this metric */
233 readonly metricName: string;
234 /** Period of this metric */
235 readonly period: cdk.Duration;
236 /** Statistic of this metric */
237 readonly statistic: string;
238 /** Label for this metric when added to a Graph in a Dashboard */
239 readonly label?: string;
240 /** The hex color code used when this metric is rendered on a graph. */
241 readonly color?: string;
242 /** Unit of the metric. */
243 readonly unit?: Unit;
244 /** Account which this metric comes from */
245 readonly account?: string;
246 /** Region which this metric comes from. */
247 readonly region?: string;
248 /** Warnings attached to this metric. */
249 readonly warnings?: string[];
250 constructor(props: MetricProps);
251 /**
252 * Return a copy of Metric `with` properties changed.
253 *
254 * All properties except namespace and metricName can be changed.
255 *
256 * @param props The set of properties to change.
257 */
258 with(props: MetricOptions): Metric;
259 /**
260 * Attach the metric object to the given construct scope
261 *
262 * Returns a Metric object that uses the account and region from the Stack
263 * the given construct is defined in. If the metric is subsequently used
264 * in a Dashboard or Alarm in a different Stack defined in a different
265 * account or region, the appropriate 'region' and 'account' fields
266 * will be added to it.
267 *
268 * If the scope we attach to is in an environment-agnostic stack,
269 * nothing is done and the same Metric object is returned.
270 */
271 attachTo(scope: constructs.IConstruct): Metric;
272 toMetricConfig(): MetricConfig;
273 /** @deprecated use toMetricConfig() */
274 toAlarmConfig(): MetricAlarmConfig;
275 /**
276 * @deprecated use toMetricConfig()
277 */
278 toGraphConfig(): MetricGraphConfig;
279 /**
280 * Make a new Alarm for this metric
281 *
282 * Combines both properties that may adjust the metric (aggregation) as well
283 * as alarm properties.
284 */
285 createAlarm(scope: Construct, id: string, props: CreateAlarmOptions): Alarm;
286 toString(): string;
287 /**
288 * Return the dimensions of this Metric as a list of Dimension.
289 */
290 private dimensionsAsList;
291 private validateDimensions;
292}
293/**
294 * A math expression built with metric(s) emitted by a service
295 *
296 * The math expression is a combination of an expression (x+y) and metrics to apply expression on.
297 * It also contains metadata which is used only in graphs, such as color and label.
298 * It makes sense to embed this in here, so that compound constructs can attach
299 * that metadata to metrics they expose.
300 *
301 * MathExpression can also be used for search expressions. In this case,
302 * it also optionally accepts a searchRegion and searchAccount property for cross-environment
303 * search expressions.
304 *
305 * This class does not represent a resource, so hence is not a construct. Instead,
306 * MathExpression is an abstraction that makes it easy to specify metrics for use in both
307 * alarms and graphs.
308 */
309export declare class MathExpression implements IMetric {
310 /**
311 * The expression defining the metric.
312 */
313 readonly expression: string;
314 /**
315 * The metrics used in the expression as KeyValuePair <id, metric>.
316 */
317 readonly usingMetrics: Record<string, IMetric>;
318 /**
319 * Label for this metric when added to a Graph.
320 */
321 readonly label?: string;
322 /**
323 * The hex color code, prefixed with '#' (e.g. '#00ff00'), to use when this metric is rendered on a graph.
324 * The `Color` class has a set of standard colors that can be used here.
325 */
326 readonly color?: string;
327 /**
328 * Aggregation period of this metric
329 */
330 readonly period: cdk.Duration;
331 /**
332 * Account to evaluate search expressions within.
333 */
334 readonly searchAccount?: string;
335 /**
336 * Region to evaluate search expressions within.
337 */
338 readonly searchRegion?: string;
339 /**
340 * Warnings generated by this math expression
341 */
342 readonly warnings?: string[];
343 constructor(props: MathExpressionProps);
344 /**
345 * Return a copy of Metric with properties changed.
346 *
347 * All properties except namespace and metricName can be changed.
348 *
349 * @param props The set of properties to change.
350 */
351 with(props: MathExpressionOptions): MathExpression;
352 /**
353 * @deprecated use toMetricConfig()
354 */
355 toAlarmConfig(): MetricAlarmConfig;
356 /**
357 * @deprecated use toMetricConfig()
358 */
359 toGraphConfig(): MetricGraphConfig;
360 toMetricConfig(): MetricConfig;
361 /**
362 * Make a new Alarm for this metric
363 *
364 * Combines both properties that may adjust the metric (aggregation) as well
365 * as alarm properties.
366 */
367 createAlarm(scope: Construct, id: string, props: CreateAlarmOptions): Alarm;
368 toString(): string;
369 private validateNoIdConflicts;
370}
371/**
372 * Properties needed to make an alarm from a metric
373 */
374export interface CreateAlarmOptions {
375 /**
376 * The period over which the specified statistic is applied.
377 *
378 * Cannot be used with `MathExpression` objects.
379 *
380 * @default - The period from the metric
381 * @deprecated Use `metric.with({ period: ... })` to encode the period into the Metric object
382 */
383 readonly period?: cdk.Duration;
384 /**
385 * What function to use for aggregating.
386 *
387 * Can be one of the following:
388 *
389 * - "Minimum" | "min"
390 * - "Maximum" | "max"
391 * - "Average" | "avg"
392 * - "Sum" | "sum"
393 * - "SampleCount | "n"
394 * - "pNN.NN"
395 *
396 * Cannot be used with `MathExpression` objects.
397 *
398 * @default - The statistic from the metric
399 * @deprecated Use `metric.with({ statistic: ... })` to encode the period into the Metric object
400 */
401 readonly statistic?: string;
402 /**
403 * Name of the alarm
404 *
405 * @default Automatically generated name
406 */
407 readonly alarmName?: string;
408 /**
409 * Description for the alarm
410 *
411 * @default No description
412 */
413 readonly alarmDescription?: string;
414 /**
415 * Comparison to use to check if metric is breaching
416 *
417 * @default GreaterThanOrEqualToThreshold
418 */
419 readonly comparisonOperator?: ComparisonOperator;
420 /**
421 * The value against which the specified statistic is compared.
422 */
423 readonly threshold: number;
424 /**
425 * The number of periods over which data is compared to the specified threshold.
426 */
427 readonly evaluationPeriods: number;
428 /**
429 * Specifies whether to evaluate the data and potentially change the alarm state if there are too few data points to be statistically significant.
430 *
431 * Used only for alarms that are based on percentiles.
432 *
433 * @default - Not configured.
434 */
435 readonly evaluateLowSampleCountPercentile?: string;
436 /**
437 * Sets how this alarm is to handle missing data points.
438 *
439 * @default TreatMissingData.Missing
440 */
441 readonly treatMissingData?: TreatMissingData;
442 /**
443 * Whether the actions for this alarm are enabled
444 *
445 * @default true
446 */
447 readonly actionsEnabled?: boolean;
448 /**
449 * The number of datapoints that must be breaching to trigger the alarm. This is used only if you are setting an "M
450 * out of N" alarm. In that case, this value is the M. For more information, see Evaluating an Alarm in the Amazon
451 * CloudWatch User Guide.
452 *
453 * @default ``evaluationPeriods``
454 *
455 * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarm-evaluation
456 */
457 readonly datapointsToAlarm?: number;
458}