# Statistic

Statistic to use over the aggregation period.

- Source: [`aws-cloudwatch/lib/metric-types.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-cloudwatch/lib/metric-types.ts#L69)
- Type last changed: v2.54.0 · 7 Dec 2022

## Example

TypeScript:

```ts
declare const matchmakingRuleSet: gamelift.MatchmakingRuleSet;
// Alarm that triggers when the per-second average of not placed matches exceed 10%
const ruleEvaluationRatio = new cloudwatch.MathExpression({
  expression: '1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)',
  usingMetrics: {
    ruleEvaluationsPassed: matchmakingRuleSet.metricRuleEvaluationsPassed({ statistic: cloudwatch.Statistic.SUM }),
    ruleEvaluationsFailed: matchmakingRuleSet.metric('ruleEvaluationsFailed'),
  },
});
new cloudwatch.Alarm(this, 'Alarm', {
  metric: ruleEvaluationRatio,
  threshold: 0.1,
  evaluationPeriods: 3,
});
```

Python:

```python
# matchmaking_rule_set: gamelift.MatchmakingRuleSet

# Alarm that triggers when the per-second average of not placed matches exceed 10%
rule_evaluation_ratio = cloudwatch.MathExpression(
    expression="1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)",
    using_metrics={
        "rule_evaluations_passed": matchmaking_rule_set.metric_rule_evaluations_passed(statistic=cloudwatch.Statistic.SUM),
        "rule_evaluations_failed": matchmaking_rule_set.metric("ruleEvaluationsFailed")
    }
)
cloudwatch.Alarm(self, "Alarm",
    metric=rule_evaluation_ratio,
    threshold=0.1,
    evaluation_periods=3
)
```

Java:

```java
MatchmakingRuleSet matchmakingRuleSet;

// Alarm that triggers when the per-second average of not placed matches exceed 10%
MathExpression ruleEvaluationRatio = MathExpression.Builder.create()
        .expression("1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)")
        .usingMetrics(Map.of(
                "ruleEvaluationsPassed", matchmakingRuleSet.metricRuleEvaluationsPassed(MetricOptions.builder().statistic(Statistic.SUM).build()),
                "ruleEvaluationsFailed", matchmakingRuleSet.metric("ruleEvaluationsFailed")))
        .build();
Alarm.Builder.create(this, "Alarm")
        .metric(ruleEvaluationRatio)
        .threshold(0.1)
        .evaluationPeriods(3)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
MatchmakingRuleSet matchmakingRuleSet;

// Alarm that triggers when the per-second average of not placed matches exceed 10%
var ruleEvaluationRatio = new MathExpression(new MathExpressionProps {
    Expression = "1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)",
    UsingMetrics = new Dictionary<string, IMetric> {
        { "ruleEvaluationsPassed", matchmakingRuleSet.MetricRuleEvaluationsPassed(new MetricOptions { Statistic = Statistic.SUM }) },
        { "ruleEvaluationsFailed", matchmakingRuleSet.Metric("ruleEvaluationsFailed") }
    }
});
new Alarm(this, "Alarm", new AlarmProps {
    Metric = ruleEvaluationRatio,
    Threshold = 0.1,
    EvaluationPeriods = 3
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var matchmakingRuleSet MatchmakingRuleSet

// Alarm that triggers when the per-second average of not placed matches exceed 10%
ruleEvaluationRatio := cloudwatch.NewMathExpression(&MathExpressionProps{
	Expression: jsii.String("1 - (ruleEvaluationsPassed / ruleEvaluationsFailed)"),
	UsingMetrics: map[string]IMetric{
		"ruleEvaluationsPassed": matchmakingRuleSet.metricRuleEvaluationsPassed(&MetricOptions{
			"statistic": cloudwatch.Statistic_SUM,
		}),
		"ruleEvaluationsFailed": matchmakingRuleSet.metric(jsii.String("ruleEvaluationsFailed")),
	},
})
cloudwatch.NewAlarm(this, jsii.String("Alarm"), &AlarmProps{
	Metric: ruleEvaluationRatio,
	Threshold: jsii.Number(0.1),
	EvaluationPeriods: jsii.Number(3),
})
```

## Members

| Member | Description |
| --- | --- |
| `SAMPLE_COUNT` | The count (number) of data points used for the statistical calculation. |
| `AVERAGE` | The value of Sum / SampleCount during the specified period. |
| `SUM` | All values submitted for the matching metric added together. |
| `MINIMUM` | The lowest value observed during the specified period. |
| `MAXIMUM` | The highest value observed during the specified period. |
