forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-cloudwatch): query results widget
Add a `QueryWidget` to generate a dashboard widget showing the results of a query from Logs Insights. This was a missing feature which is available in the console. closes aws#3681
- Loading branch information
1 parent
fbc1df3
commit 3a819db
Showing
6 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { ConcreteWidget } from "./widget"; | ||
|
||
/** | ||
* Properties for a Query widget | ||
*/ | ||
export interface QueryWidgetProps { | ||
/** | ||
* Title for the graph | ||
* | ||
* @default No title | ||
*/ | ||
readonly title?: string; | ||
|
||
/** | ||
* Log group to query | ||
*/ | ||
readonly logGroup: string; | ||
|
||
/** | ||
* Query for log insights | ||
*/ | ||
readonly query: string; | ||
|
||
/** | ||
* The region the metrics of this graph should be taken from | ||
* | ||
* @default Current region | ||
*/ | ||
readonly region?: string; | ||
|
||
/** | ||
* Width of the widget, in a grid of 24 units wide | ||
* | ||
* @default 6 | ||
*/ | ||
readonly width?: number; | ||
|
||
/** | ||
* Height of the widget | ||
* | ||
* @default 6 | ||
*/ | ||
readonly height?: number; | ||
} | ||
|
||
/** | ||
* Display query results from Logs Insights | ||
*/ | ||
export class QueryWidget extends ConcreteWidget { | ||
private readonly props: QueryWidgetProps; | ||
|
||
constructor(props: QueryWidgetProps) { | ||
super(props.width || 6, props.height || 6); | ||
this.props = props; | ||
} | ||
|
||
public toJson(): any[] { | ||
return [{ | ||
type: 'log', | ||
width: this.width, | ||
height: this.height, | ||
x: this.x, | ||
y: this.y, | ||
properties: { | ||
view: 'table', | ||
title: this.props.title, | ||
region: this.props.region || cdk.Aws.REGION, | ||
query: cdk.Fn.join('', [ | ||
"SOURCE '", this.props.logGroup, "' | ", this.props.query | ||
]) | ||
} | ||
}]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters