@cloud-carbon-footprint/gcp
Version:
The core logic to get cloud usage data and estimate energy and carbon emissions from Google Cloud Platform.
42 lines • 1.97 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 GCPRegions_1 = require("./GCPRegions");
const BillingExportTypes_1 = require("./BillingExportTypes");
const MachineTypes_1 = require("./MachineTypes");
class BillingExportRow extends core_1.BillingDataRow {
constructor(init) {
super(init);
this.cloudProvider = 'GCP';
if (!this.region)
this.region = GCPRegions_1.GCP_REGIONS.UNKNOWN;
this.vCpuHours = this.getVCpuHours();
this.gpuHours = this.usageAmount / 3600;
this.timestamp = new Date(init.timestamp.value);
if ((0, common_1.containsAny)(BillingExportTypes_1.SERVICES_TO_OVERRIDE_USAGE_UNIT_AS_UNKNOWN, this.serviceName))
this.usageUnit = 'Unknown';
if (this.isCloudComposerCompute() || this.isKubernetesCompute())
this.machineType = MachineTypes_1.SHARED_CORE_PROCESSORS.E2_MEDIUM;
if (this.usageType.includes('Pod mCPU Requests'))
this.usageAmount = this.usageAmount / 1000;
}
getVCpuHours() {
if (this.isCloudComposerCompute())
return ((this.usageAmount / 3600) *
(0, common_1.configLoader)().GCP.VCPUS_PER_CLOUD_COMPOSER_ENVIRONMENT);
if (this.isKubernetesCompute())
return ((this.usageAmount / 3600) * (0, common_1.configLoader)().GCP.VCPUS_PER_GKE_CLUSTER);
return this.usageAmount / 3600;
}
isCloudComposerCompute() {
return (this.usageType.includes('Cloud Composer Compute CPUs') ||
this.usageType.includes('Cloud Composer vCPU') ||
this.usageType.includes('Cloud Composer SQL vCPU'));
}
isKubernetesCompute() {
return this.usageType.includes('Kubernetes Clusters');
}
}
exports.default = BillingExportRow;
//# sourceMappingURL=BillingExportRow.js.map