Skip to content
v2.278.0

Unit Enum ​

Unit for metric.

Example ​

ts
declare const logGroup: logs.LogGroup;
const mf = new logs.MetricFilter(this, 'MetricFilter', {
  logGroup,
  metricNamespace: 'MyApp',
  metricName: 'Latency',
  filterPattern: logs.FilterPattern.exists('$.latency'),
  metricValue: '$.latency',
  dimensions: {
    ErrorCode: '$.errorCode',
  },
  unit: cloudwatch.Unit.MILLISECONDS,
});

//expose a metric from the metric filter
const metric = mf.metric();

//you can use the metric to create a new alarm
new cloudwatch.Alarm(this, 'alarm from metric filter', {
  metric,
  threshold: 100,
  evaluationPeriods: 2,
});
python
# log_group: logs.LogGroup

mf = logs.MetricFilter(self, "MetricFilter",
    log_group=log_group,
    metric_namespace="MyApp",
    metric_name="Latency",
    filter_pattern=logs.FilterPattern.exists("$.latency"),
    metric_value="$.latency",
    dimensions={
        "ErrorCode": "$.errorCode"
    },
    unit=cloudwatch.Unit.MILLISECONDS
)

# expose a metric from the metric filter
metric = mf.metric()

# you can use the metric to create a new alarm
cloudwatch.Alarm(self, "alarm from metric filter",
    metric=metric,
    threshold=100,
    evaluation_periods=2
)
java
LogGroup logGroup;

MetricFilter mf = MetricFilter.Builder.create(this, "MetricFilter")
        .logGroup(logGroup)
        .metricNamespace("MyApp")
        .metricName("Latency")
        .filterPattern(FilterPattern.exists("$.latency"))
        .metricValue("$.latency")
        .dimensions(Map.of(
                "ErrorCode", "$.errorCode"))
        .unit(Unit.MILLISECONDS)
        .build();

//expose a metric from the metric filter
Metric metric = mf.metric();

//you can use the metric to create a new alarm
//you can use the metric to create a new alarm
Alarm.Builder.create(this, "alarm from metric filter")
        .metric(metric)
        .threshold(100)
        .evaluationPeriods(2)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
LogGroup logGroup;

var mf = new MetricFilter(this, "MetricFilter", new MetricFilterProps {
    LogGroup = logGroup,
    MetricNamespace = "MyApp",
    MetricName = "Latency",
    FilterPattern = FilterPattern.Exists("$.latency"),
    MetricValue = "$.latency",
    Dimensions = new Dictionary<string, string> {
        { "ErrorCode", "$.errorCode" }
    },
    Unit = Unit.MILLISECONDS
});

//expose a metric from the metric filter
var metric = mf.Metric();

//you can use the metric to create a new alarm
//you can use the metric to create a new alarm
new Alarm(this, "alarm from metric filter", new AlarmProps {
    Metric = metric,
    Threshold = 100,
    EvaluationPeriods = 2
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var logGroup LogGroup

mf := logs.NewMetricFilter(this, jsii.String("MetricFilter"), &MetricFilterProps{
	LogGroup: LogGroup,
	MetricNamespace: jsii.String("MyApp"),
	MetricName: jsii.String("Latency"),
	FilterPattern: logs.FilterPattern_Exists(jsii.String("$.latency")),
	MetricValue: jsii.String("$.latency"),
	Dimensions: map[string]*string{
		"ErrorCode": jsii.String("$.errorCode"),
	},
	Unit: cloudwatch.Unit_MILLISECONDS,
})

//expose a metric from the metric filter
metric := mf.Metric()

//you can use the metric to create a new alarm
//you can use the metric to create a new alarm
cloudwatch.NewAlarm(this, jsii.String("alarm from metric filter"), &AlarmProps{
	Metric: Metric,
	Threshold: jsii.Number(100),
	EvaluationPeriods: jsii.Number(2),
})

Members ​

MemberDescription
SECONDSSeconds.
MICROSECONDSMicroseconds.
MILLISECONDSMilliseconds.
BYTESBytes.
KILOBYTESKilobytes.
MEGABYTESMegabytes.
GIGABYTESGigabytes.
TERABYTESTerabytes.
BITSBits.
KILOBITSKilobits.
MEGABITSMegabits.
GIGABITSGigabits.
TERABITSTerabits.
PERCENTPercent.
COUNTCount.
BYTES_PER_SECONDBytes/second (B/s).
KILOBYTES_PER_SECONDKilobytes/second (kB/s).
MEGABYTES_PER_SECONDMegabytes/second (MB/s).
GIGABYTES_PER_SECONDGigabytes/second (GB/s).
TERABYTES_PER_SECONDTerabytes/second (TB/s).
BITS_PER_SECONDBits/second (b/s).
KILOBITS_PER_SECONDKilobits/second (kb/s).
MEGABITS_PER_SECONDMegabits/second (Mb/s).
GIGABITS_PER_SECONDGigabits/second (Gb/s).
TERABITS_PER_SECONDTerabits/second (Tb/s).
COUNT_PER_SECONDCount/second.
NONENone.

Referenced by ​