-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #556 from beethovenxfi/v3-canary
V3 canary
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
CloudWatchClient, | ||
CloudWatchClientConfig, | ||
MetricDatum, | ||
PutMetricDataCommand, | ||
} from '@aws-sdk/client-cloudwatch'; | ||
import { env } from '../../app/env'; | ||
|
||
export interface NotificationsCloudwatchMetric { | ||
merticData: MetricDatum[]; | ||
nameSpace: string; | ||
} | ||
|
||
export class CloudwatchCronDurationMetricsPublisher { | ||
protected environment: string; | ||
protected configuration?: CloudWatchClientConfig; | ||
private client: CloudWatchClient; | ||
public namespace: string; | ||
|
||
constructor( | ||
namespace: string = 'default', | ||
environment: string = env.DEPLOYMENT_ENV, | ||
configuration?: CloudWatchClientConfig, | ||
) { | ||
this.namespace = namespace; | ||
this.environment = environment; | ||
this.client = new CloudWatchClient({ region: env.AWS_REGION, ...configuration }); | ||
} | ||
|
||
public async publish(metricName: string, count?: number): Promise<void> { | ||
const [major, minor, patch] = process.versions.node.split('.').map(Number); | ||
try { | ||
const command = new PutMetricDataCommand({ | ||
MetricData: [ | ||
{ | ||
MetricName: metricName, | ||
Dimensions: [ | ||
{ | ||
Name: 'Environment', | ||
Value: this.environment, | ||
}, | ||
{ | ||
Name: 'NodeVersion', | ||
Value: major.toString(), | ||
}, | ||
], | ||
Unit: 'None', | ||
Timestamp: new Date(), | ||
Value: count ? count : 1, | ||
}, | ||
], | ||
Namespace: this.namespace, | ||
}); | ||
|
||
await this.client.send(command); | ||
} catch (err) { | ||
// Sentry.captureException(`Failed to publish "${metricName}" in "${this.environment}: ${err}`); | ||
console.log(`Failed to publish "${metricName}" in "${this.environment}: ${err}`); | ||
} | ||
} | ||
} | ||
|
||
export const cronsDurationMetricPublisher = new CloudwatchCronDurationMetricsPublisher('backendCronsDuration'); |
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