Skip to content

Commit

Permalink
feat(classic): add GaugeWidget for cloudwatch dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
maniolias committed Mar 16, 2023
1 parent 95cf49f commit 5437224
Show file tree
Hide file tree
Showing 7 changed files with 1,808 additions and 1,402 deletions.
212 changes: 118 additions & 94 deletions awsx-classic/cloudwatch/widgets_graph.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,118 @@
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as pulumi from "@pulumi/pulumi";
import * as wjson from "./widgets_json";

import { MetricWidget, MetricWidgetArgs } from "./widgets_simple";

// Contains all the classes for easily making graph widgets in a dashboard.

export interface GraphMetricWidgetArgs extends MetricWidgetArgs {
/**
* Limits for the minimums and maximums of the y-axis. This applies to every metric being
* graphed, unless specific metrics override it.
*/
yAxis?: pulumi.Input<YAxis>;
}

export interface YAxis {
/** Optional min and max settings for the left Y-axis. */
left?: MinMax;

/** Optional min and max settings for the right Y-axis. */
right?: MinMax;
}

export interface MinMax {
/** The minimum value for this Y-axis */
min?: number;
/** The maximum value for this Y-axis */
max?: number;
}


/**
* Base type for widets that display metrics as a graph (either a line or stacked graph).
*
* See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph_metrics.html for more
* details.
*/
export abstract class GraphMetricWidget extends MetricWidget {
constructor(private readonly graphArgs: GraphMetricWidgetArgs) {
super(graphArgs);
}

protected computeView = (): wjson.MetricWidgetPropertiesJson["view"] => "timeSeries";
protected computeYAxis = (): wjson.MetricWidgetPropertiesJson["yAxis"] => this.graphArgs.yAxis;
}

/**
* Displays a set of metrics as a line graph.
*/
export class LineGraphMetricWidget extends GraphMetricWidget {
constructor(args: GraphMetricWidgetArgs) {
super(args);
}

protected computedStacked = () => false;
}

/**
* Displays a set of metrics as a stacked area graph.
*/
export class StackedAreaGraphMetricWidget extends GraphMetricWidget {
constructor(args: GraphMetricWidgetArgs) {
super(args);
}

protected computedStacked = () => true;
}

/**
* Displays a set of metrics as a single number.
*/
export class SingleNumberMetricWidget extends MetricWidget {
constructor(args: MetricWidgetArgs) {
super(args);
}

protected computedStacked = () => false;
protected computeView = (): wjson.MetricWidgetPropertiesJson["view"] => "singleValue";
protected computeYAxis = (): wjson.MetricWidgetPropertiesJson["yAxis"] => undefined;
}
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as pulumi from "@pulumi/pulumi";
import * as wjson from "./widgets_json";

import { MetricWidget, MetricWidgetArgs } from "./widgets_simple";

type DeepRequired<T> = {
[K in keyof T]: Required<DeepRequired<T[K]>>
}
// Contains all the classes for easily making graph widgets in a dashboard.

export interface GraphMetricWidgetArgs extends MetricWidgetArgs {
/**
* Limits for the minimums and maximums of the y-axis. This applies to every metric being
* graphed, unless specific metrics override it.
*/
yAxis?: pulumi.Input<YAxis>;
}

export interface GaugeMetricWidgetArgs extends MetricWidgetArgs {
/**
* Limits for the minimums and maximums of the y-axis. Needed for Gauge Widget.
*/
yAxis: pulumi.Input<DeepRequired<YAxis>>;
}


export interface YAxis {
/** Optional min and max settings for the left Y-axis. */
left?: MinMax;

/** Optional min and max settings for the right Y-axis. */
right?: MinMax;
}

export interface MinMax {
/** The minimum value for this Y-axis */
min?: number;
/** The maximum value for this Y-axis */
max?: number;
}


/**
* Base type for widets that display metrics as a graph (either a line or stacked graph).
*
* See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph_metrics.html for more
* details.
*/
export abstract class GraphMetricWidget extends MetricWidget {
constructor(private readonly graphArgs: GraphMetricWidgetArgs) {
super(graphArgs);
}

protected computeView = (): wjson.MetricWidgetPropertiesJson["view"] => "timeSeries";
protected computeYAxis = (): wjson.MetricWidgetPropertiesJson["yAxis"] => this.graphArgs.yAxis;
}

/**
* Displays a set of metrics as a line graph.
*/
export class LineGraphMetricWidget extends GraphMetricWidget {
constructor(args: GraphMetricWidgetArgs) {
super(args);
}

protected computedStacked = () => false;
}

/**
* Displays a set of metrics as a stacked area graph.
*/
export class StackedAreaGraphMetricWidget extends GraphMetricWidget {
constructor(args: GraphMetricWidgetArgs) {
super(args);
}

protected computedStacked = () => true;
}

/**
* Displays a set of metrics as a single number.
*/
export class SingleNumberMetricWidget extends MetricWidget {
constructor(args: MetricWidgetArgs) {
super(args);
}

protected computedStacked = () => false;
protected computeView = (): wjson.MetricWidgetPropertiesJson["view"] => "singleValue";
protected computeYAxis = (): wjson.MetricWidgetPropertiesJson["yAxis"] => undefined;
}

/**
* Displays a set of metrics as a gauge number.
*/
export class GaugeMetricWidget extends MetricWidget {
constructor(private readonly gaugeArgs: GaugeMetricWidgetArgs) {
super(gaugeArgs);
}

protected computedStacked = () => false;
protected computeView = (): wjson.MetricWidgetPropertiesJson["view"] => "gauge";
protected computeYAxis = (): wjson.MetricWidgetPropertiesJson["yAxis"] => this.gaugeArgs.yAxis;
}
2 changes: 1 addition & 1 deletion awsx-classic/cloudwatch/widgets_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface MetricWidgetPropertiesJson {
period: pulumi.Input<number> | undefined;
region: pulumi.Input<string | undefined>;
stat: pulumi.Input<string>;
view: pulumi.Input<"timeSeries" | "singleValue" | undefined>;
view: pulumi.Input<"timeSeries" | "singleValue" | "gauge" | undefined>;
stacked: pulumi.Input<boolean | undefined>;
yAxis: pulumi.Input<YAxis> | undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion awsx-classic/cloudwatch/widgets_simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export class LogWidget extends SimpleWidget {
protected computeType(): wjson.LogWidgetJson["type"] {
return "log";
}
protected computeView = (): wjson.MetricWidgetPropertiesJson["view"] => "timeSeries";
protected computeView = (): wjson.LogWidgetPropertiesJson["view"] => "timeSeries";
protected computedStacked = () => false;

protected computeProperties(region: pulumi.Output<aws.Region>): wjson.LogWidgetJson["properties"] {
Expand Down

0 comments on commit 5437224

Please sign in to comment.