UNPKG

@cloud-carbon-footprint/aws

Version:

The core logic to get cloud usage data and estimate energy and carbon emissions from Amazon Web Services.

97 lines 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("@cloud-carbon-footprint/common"); const StorageUsageMapper_1 = require("./StorageUsageMapper"); const CostMapper_1 = require("./CostMapper"); class EBS { constructor(serviceWrapper) { this.serviceWrapper = serviceWrapper; this.serviceName = 'EBS'; this.getDiskType = (awsGroupKey) => { if (awsGroupKey.endsWith('VolumeUsage.gp2') || awsGroupKey.endsWith('VolumeUsage.piops')) return StorageUsageMapper_1.DiskType.SSD; if (awsGroupKey.endsWith('VolumeUsage.st1') || awsGroupKey.endsWith('VolumeUsage.sc1') || awsGroupKey.endsWith('VolumeUsage')) return StorageUsageMapper_1.DiskType.HDD; this.ebsLogger.warn('Unexpected Cost explorer Dimension Name: ' + awsGroupKey); return StorageUsageMapper_1.DiskType.UNKNOWN; }; this.ebsLogger = new common_1.Logger('EBS'); } async getEstimates(start, end, region, emissionsFactors, constants) { const usage = await this.getUsage(start, end, region); return (0, StorageUsageMapper_1.getEstimatesFromCostExplorer)(region, usage, emissionsFactors, constants); } async getUsage(startDate, endDate, region) { const params = { TimePeriod: { Start: startDate.toISOString().substr(0, 10), End: endDate.toISOString().substr(0, 10), }, Filter: { And: [ { Dimensions: { Key: 'USAGE_TYPE_GROUP', Values: [ 'EC2: EBS - SSD(gp2)', 'EC2: EBS - SSD(io1)', 'EC2: EBS - HDD(sc1)', 'EC2: EBS - HDD(st1)', 'EC2: EBS - Magnetic', ], }, }, { Dimensions: { Key: 'REGION', Values: [region] } }, ], }, Granularity: 'DAILY', Metrics: ['UsageQuantity'], GroupBy: [ { Key: 'USAGE_TYPE', Type: 'DIMENSION', }, ], }; return await (0, StorageUsageMapper_1.getUsageFromCostExplorer)(params, this.getDiskType, this.serviceWrapper); } async getCosts(start, end, region) { const params = { TimePeriod: { Start: start.toISOString().substr(0, 10), End: end.toISOString().substr(0, 10), }, Filter: { And: [ { Dimensions: { Key: 'USAGE_TYPE_GROUP', Values: [ 'EC2: EBS - SSD(gp2)', 'EC2: EBS - SSD(io1)', 'EC2: EBS - HDD(sc1)', 'EC2: EBS - HDD(st1)', 'EC2: EBS - Magnetic', ], }, }, { Dimensions: { Key: 'REGION', Values: [region] } }, ], }, Granularity: 'DAILY', Metrics: ['AmortizedCost'], GroupBy: [ { Key: 'USAGE_TYPE', Type: 'DIMENSION', }, ], }; return await (0, CostMapper_1.getCostFromCostExplorer)(params, this.serviceWrapper); } } exports.default = EBS; //# sourceMappingURL=EBS.js.map