-
Notifications
You must be signed in to change notification settings - Fork 4k
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(ec2): add vpn metrics #1979
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import cloudwatch = require('@aws-cdk/aws-cloudwatch'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
import net = require('net'); | ||
import { CfnCustomerGateway, CfnVPNConnection, CfnVPNConnectionRoute } from './ec2.generated'; | ||
|
@@ -98,6 +99,44 @@ export enum VpnConnectionType { | |
} | ||
|
||
export class VpnConnection extends cdk.Construct implements IVpnConnection { | ||
/** | ||
* Return the given named metric for all VPN connections. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "all VPC connections in the account/region" |
||
*/ | ||
public static metricAll(metricName: string, props?: cloudwatch.MetricCustomization): cloudwatch.Metric { | ||
return new cloudwatch.Metric({ | ||
namespace: 'AWS/VPN', | ||
metricName, | ||
...props | ||
}); | ||
} | ||
|
||
/** | ||
* Metric for the tunnel state of all VPN connections. | ||
* | ||
* @default average over 5 minutes | ||
*/ | ||
public static metricAllTunnelState(props?: cloudwatch.MetricCustomization): cloudwatch.Metric { | ||
return this.metricAll('TunnelSate', { statistic: 'avg', ...props }); | ||
} | ||
|
||
/** | ||
* Metric for the tunnel data in of all VPN connections. | ||
* | ||
* @default sum over 5 minutes | ||
*/ | ||
public static metricAllTunnelDataIn(props?: cloudwatch.MetricCustomization): cloudwatch.Metric { | ||
return this.metricAll('TunnelDataIn', { statistic: 'sum', ...props }); | ||
} | ||
|
||
/** | ||
* Metric for the tunnel data out of all VPN connections. | ||
* | ||
* @default sum over 5 minutes | ||
*/ | ||
public static metricAllTunnelDataOut(props?: cloudwatch.MetricCustomization): cloudwatch.Metric { | ||
return this.metricAll('TunnelDataOut', { statistic: 'sum', ...props }); | ||
} | ||
|
||
public readonly vpnId: string; | ||
public readonly customerGatewayId: string; | ||
public readonly customerGatewayIp: string; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"overrides": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't call these "overrides". We should think about them simply as configuration of the augmentation system that has some default values, so you don't have to supply them but you can, and I would avoid attaching any heuristics to them (i.e. "Base" suffix). So, maybe: {
"baseClass": "VpnConnectionBase",
"baseClassFile": "vpn",
"interface": "IVpnConnection"
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, will rename these. The current implementation doesn't attach anything to these overrides. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I'm following here. const baseClassName = (overrides && overrides.class) || l2ClassName + 'Base';
const interfaceName = (overrides && overrides.interface) || 'I' + l2ClassName;
const baseClassModule = `./${(overrides && overrides.module) || `${kebabL2ClassName}-base`}`; From above, if there's an override it's taken as is, no? Regarding the names in the JSON file:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yes, you are right. I guess |
||
"interface": "IVpnConnection", | ||
"class": "VpnConnection", | ||
"module": "vpn" | ||
}, | ||
"metrics": { | ||
"namespace": "AWS/VPN", | ||
"dimensions": { "VpnId": "this.vpnId" }, | ||
"metrics": [ | ||
{ | ||
"name": "TunnelState", | ||
"documentation": "The state of the tunnel. 0 indicates DOWN and 1 indicates UP." | ||
}, | ||
{ | ||
"name": "TunnelDataIn", | ||
"documentation": "The bytes received through the VPN tunnel.", | ||
"type": "count" | ||
}, | ||
{ | ||
"name": "TunnelDataOut", | ||
"documentation": "The bytes sent through the VPN tunnel.", | ||
"type": "count" | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,28 @@ export interface ResourceAugmentation { | |
* Metric augmentations for this resource type | ||
*/ | ||
metrics?: ResourceMetricAugmentations; | ||
|
||
/** | ||
* Overrides for this resource augmentation | ||
*/ | ||
overrides?: ResourceOverrides; | ||
} | ||
|
||
export interface ResourceOverrides { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to |
||
/** | ||
* The name of the resource class | ||
*/ | ||
class?: string; | ||
|
||
/** | ||
* The name of the resource interface | ||
*/ | ||
interface?: string; | ||
|
||
/** | ||
* The name of the module | ||
*/ | ||
module?: string; | ||
} | ||
|
||
export interface ResourceMetricAugmentations { | ||
|
@@ -57,4 +79,4 @@ export enum MetricType { | |
* property. The most useful aggregate of this type of metric is "Max". | ||
*/ | ||
Gauge = 'gauge' | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example/snippet on how to use?