@cloud-carbon-footprint/aws
Version:
The core logic to get cloud usage data and estimate energy and carbon emissions from Amazon Web Services.
63 lines • 2.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@cloud-carbon-footprint/core");
const common_1 = require("@cloud-carbon-footprint/common");
const domain_1 = require("../domain");
const AWSInstanceTypes_1 = require("./AWSInstanceTypes");
class AWSComputeEstimatesBuilder extends core_1.FootprintEstimatesDataBuilder {
constructor(rowData, computeEstimator, emissionsFactors) {
super(rowData);
this.vCpuHours = rowData.vCpuHours;
this.region = rowData.region;
this.powerUsageEffectiveness = domain_1.AWS_CLOUD_CONSTANTS.getPUE(this.region);
this.computeProcessors = rowData.getComputeProcessors();
this.gpuComputeProcessors = rowData.getGPUComputeProcessors();
this.computeConstants = this.getComputeConstants();
this.computeFootprint = this.getComputeFootprint(computeEstimator, this.region, emissionsFactors);
}
getComputeUsage() {
return {
cpuUtilizationAverage: domain_1.AWS_CLOUD_CONSTANTS.AVG_CPU_UTILIZATION_2020,
vCpuHours: this.vCpuHours,
usesAverageCPUConstant: true,
};
}
getGpuComputeUsage() {
return {
cpuUtilizationAverage: domain_1.AWS_CLOUD_CONSTANTS.AVG_CPU_UTILIZATION_2020,
vCpuHours: this.gpuHours,
usesAverageCPUConstant: true,
};
}
getComputeConstants() {
return {
minWatts: domain_1.AWS_CLOUD_CONSTANTS.getMinWatts(this.computeProcessors),
maxWatts: domain_1.AWS_CLOUD_CONSTANTS.getMaxWatts(this.computeProcessors),
powerUsageEffectiveness: this.powerUsageEffectiveness,
replicationFactor: this.replicationFactor,
};
}
getGpuComputeConstants() {
return {
minWatts: domain_1.AWS_CLOUD_CONSTANTS.getMinWatts(this.gpuComputeProcessors),
maxWatts: domain_1.AWS_CLOUD_CONSTANTS.getMaxWatts(this.gpuComputeProcessors),
powerUsageEffectiveness: this.powerUsageEffectiveness,
replicationFactor: this.replicationFactor,
};
}
getComputeFootprint(computeEstimator, region, emissionsFactors) {
const computeEstimate = computeEstimator.estimate([this.getComputeUsage()], region, emissionsFactors, this.getComputeConstants())[0];
if (this.isGpuInstance()) {
const gpuComputeEstimate = computeEstimator.estimate([this.getGpuComputeUsage()], region, emissionsFactors, this.getGpuComputeConstants())[0];
computeEstimate.kilowattHours += gpuComputeEstimate.kilowattHours;
computeEstimate.co2e += gpuComputeEstimate.co2e;
return computeEstimate;
}
return computeEstimate;
}
isGpuInstance() {
return (0, common_1.containsAny)(Object.keys(AWSInstanceTypes_1.GPU_INSTANCES_TYPES), this.usageType);
}
}
exports.default = AWSComputeEstimatesBuilder;
//# sourceMappingURL=AWSComputeEstimatesBuilder.js.map