UNPKG

6.73 kBJavaScriptView Raw
1"use strict";
2var _a;
3Object.defineProperty(exports, "__esModule", { value: true });
4exports.MetricFilter = void 0;
5const jsiiDeprecationWarnings = require("../.warnings.jsii.js");
6const JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti");
7const aws_cloudwatch_1 = require("@aws-cdk/aws-cloudwatch");
8const core_1 = require("@aws-cdk/core");
9const logs_generated_1 = require("./logs.generated");
10/**
11 * A filter that extracts information from CloudWatch Logs and emits to CloudWatch Metrics
12 */
13class MetricFilter extends core_1.Resource {
14 constructor(scope, id, props) {
15 super(scope, id);
16 try {
17 jsiiDeprecationWarnings._aws_cdk_aws_logs_MetricFilterProps(props);
18 }
19 catch (error) {
20 if (process.env.JSII_DEBUG !== "1" && error.name === "DeprecationError") {
21 Error.captureStackTrace(error, MetricFilter);
22 }
23 throw error;
24 }
25 this.metricName = props.metricName;
26 this.metricNamespace = props.metricNamespace;
27 // It looks odd to map this object to a singleton list, but that's how
28 // we're supposed to do it according to the docs.
29 //
30 // > Currently, you can specify only one metric transformation for
31 // > each metric filter. If you want to specify multiple metric
32 // > transformations, you must specify multiple metric filters.
33 //
34 // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-metricfilter.html
35 new logs_generated_1.CfnMetricFilter(this, 'Resource', {
36 logGroupName: props.logGroup.logGroupName,
37 filterPattern: props.filterPattern.logPatternString,
38 metricTransformations: [{
39 metricNamespace: props.metricNamespace,
40 metricName: props.metricName,
41 metricValue: props.metricValue ?? '1',
42 defaultValue: props.defaultValue,
43 }],
44 });
45 }
46 /**
47 * Return the given named metric for this Metric Filter
48 *
49 * @default avg over 5 minutes
50 */
51 metric(props) {
52 return new aws_cloudwatch_1.Metric({
53 metricName: this.metricName,
54 namespace: this.metricNamespace,
55 statistic: 'avg',
56 ...props,
57 }).attachTo(this);
58 }
59}
60exports.MetricFilter = MetricFilter;
61_a = JSII_RTTI_SYMBOL_1;
62MetricFilter[_a] = { fqn: "@aws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