mblabs-roccato-backend-commons 1.0.63 → 1.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/interfaces/aws.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const client_cloudwatch_1 = require("@aws-sdk/client-cloudwatch");
|
|
4
7
|
const client_cloudwatch_logs_1 = require("@aws-sdk/client-cloudwatch-logs");
|
|
8
|
+
const date_1 = __importDefault(require("../date"));
|
|
5
9
|
class AmazonCloudwatchService {
|
|
6
10
|
async createMetric({ credentials, data }) {
|
|
7
11
|
const client = new client_cloudwatch_1.CloudWatch({
|
|
@@ -18,20 +22,19 @@ class AmazonCloudwatchService {
|
|
|
18
22
|
bytes: 'Bytes',
|
|
19
23
|
none: 'None',
|
|
20
24
|
};
|
|
21
|
-
|
|
25
|
+
const payload = {
|
|
22
26
|
Namespace: data.namespace,
|
|
23
27
|
MetricData: [
|
|
24
28
|
{
|
|
25
29
|
MetricName: data.metric.title,
|
|
26
|
-
Dimensions: data.metric.dimensions
|
|
27
|
-
Name: dimension.name,
|
|
28
|
-
Value: dimension.value,
|
|
29
|
-
})),
|
|
30
|
+
Dimensions: data.metric.dimensions?.map(dimension => ({ Name: dimension.name, Value: dimension.value })) ?? [],
|
|
30
31
|
Value: data.metric.value,
|
|
31
32
|
Unit: UnitMap[data.metric.unit] || 'None',
|
|
33
|
+
Timestamp: data.metric.timestamp ?? date_1.default.getCurrentDate(),
|
|
32
34
|
},
|
|
33
35
|
],
|
|
34
|
-
}
|
|
36
|
+
};
|
|
37
|
+
await client.send(new client_cloudwatch_1.PutMetricDataCommand(payload));
|
|
35
38
|
}
|
|
36
39
|
async createLogEvent({ credentials, data }) {
|
|
37
40
|
const client = new client_cloudwatch_logs_1.CloudWatchLogs({
|
package/package.json
CHANGED
package/src/interfaces/aws.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { CloudWatch } from '@aws-sdk/client-cloudwatch';
|
|
1
|
+
import { CloudWatch, PutMetricDataCommand } from '@aws-sdk/client-cloudwatch';
|
|
2
2
|
import { CloudWatchLogs, StandardUnit } from '@aws-sdk/client-cloudwatch-logs';
|
|
3
3
|
|
|
4
4
|
import { AmazonCloudwatch, IAmazonCloudwatchService } from '../../interfaces';
|
|
5
|
+
import DateService from '../date';
|
|
5
6
|
|
|
6
7
|
class AmazonCloudwatchService implements IAmazonCloudwatchService {
|
|
7
8
|
async createMetric ({ credentials, data }: AmazonCloudwatch.CreateMetric.Request): Promise<void> {
|
|
@@ -21,20 +22,22 @@ class AmazonCloudwatchService implements IAmazonCloudwatchService {
|
|
|
21
22
|
none: 'None',
|
|
22
23
|
};
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
const payload = {
|
|
25
26
|
Namespace: data.namespace,
|
|
26
27
|
MetricData: [
|
|
27
28
|
{
|
|
28
29
|
MetricName: data.metric.title,
|
|
29
|
-
Dimensions: data.metric.dimensions
|
|
30
|
-
Name: dimension.name,
|
|
31
|
-
|
|
32
|
-
})),
|
|
30
|
+
Dimensions: data.metric.dimensions?.map(
|
|
31
|
+
dimension => ({ Name: dimension.name, Value: dimension.value })
|
|
32
|
+
) ?? [],
|
|
33
33
|
Value: data.metric.value,
|
|
34
34
|
Unit: UnitMap[data.metric.unit] || 'None',
|
|
35
|
+
Timestamp: data.metric.timestamp ?? DateService.getCurrentDate(),
|
|
35
36
|
},
|
|
36
37
|
],
|
|
37
|
-
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
await client.send(new PutMetricDataCommand(payload));
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
public async createLogEvent ({ credentials, data }: AmazonCloudwatch.CreateLogEvent.Request): Promise<void> {
|