Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(classic): add GaugeWidget for cloudwatch dashboard #1012

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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