From d2c4a09c2c06df7c2daa61458a6a7c877ff8b3fd Mon Sep 17 00:00:00 2001 From: bishal7679 Date: Mon, 9 Oct 2023 10:19:55 +0530 Subject: [PATCH] cost of s3 showing 0 is fixed Signed-off-by: bishal7679 --- .../public/assets/img/providers/azure.svg | 44 ++++---- dashboard/public/favicon.ico | Bin 15086 -> 15085 bytes providers/aws/s3/buckets.go | 100 +++++++++++++++--- 3 files changed, 109 insertions(+), 35 deletions(-) diff --git a/dashboard/public/assets/img/providers/azure.svg b/dashboard/public/assets/img/providers/azure.svg index 9288c7921..7151406b9 100644 --- a/dashboard/public/assets/img/providers/azure.svg +++ b/dashboard/public/assets/img/providers/azure.svg @@ -1,23 +1,23 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dashboard/public/favicon.ico b/dashboard/public/favicon.ico index 746f87c133a6ab8130798f717b50445612740229..dbb5a72c5a73e8aa4eefc17f129f11d3e4fc4f64 100644 GIT binary patch delta 12 TcmaD?`nGh#3gOKwg 0 { bucketSize = *metricsBucketSizebytesOutput.Datapoints[0].Average } sizeInTB := ConvertBytesToTerabytes(int64(bucketSize)) - monthlyCost := 0.0 + storageCostPerGB := 0.0 if sizeInTB <= 50 { - monthlyCost = (sizeInTB * 1000) * 0.023 + storageCostPerGB = (sizeInTB * 1024) * 0.023 } else if sizeInTB <= 450 { - monthlyCost = (sizeInTB * 1000) * 0.022 + storageCostPerGB = (sizeInTB * 1024) * 0.022 } else { - monthlyCost = (sizeInTB * 1000) * 0.021 + storageCostPerGB = (sizeInTB * 1024) * 0.021 } + // metrics for bucket usage + + metricsUsageOutput, err := cloudwatchClient.GetMetricStatistics(ctx, &cloudwatch.GetMetricStatisticsInput{ + StartTime: aws.Time(utils.BeginningOfMonth(time.Now())), + EndTime: aws.Time(time.Now()), + MetricName: aws.String("AllRequests"), + Namespace: aws.String("AWS/S3"), + Dimensions: []cloudwatchTypes.Dimension{ + { + Name: aws.String("BucketName"), + Value: bucket.Name, + }, + { + Name: aws.String("StorageType"), + Value: aws.String("StandardStorage"), + }, + }, + Unit: cloudwatchTypes.StandardUnitCount, + Period: aws.Int32(3600), + Statistics: []cloudwatchTypes.Statistic{ + cloudwatchTypes.StatisticSum, + }, + }) + if err != nil { + log.Warnf("Couldn't fetch usage metric for %s", *bucket.Name) + } + + requestCount := 0.0 + if metricsUsageOutput != nil && len(metricsUsageOutput.Datapoints) > 0 { + requestCount = *metricsUsageOutput.Datapoints[0].Sum + } + // requestCost := (requestCount / 1000) * 0.0004 + + monthlyCost := 0.0 + + requestCharges := awsUtils.GetCost(priceMap["AWS-S3-Requests"], requestCount/1000) // charges per 1000 request + monthlyCost = storageCostPerGB + requestCharges tagsResp, err := s3Client.GetBucketTagging(context.Background(), &s3.GetBucketTaggingInput{ Bucket: bucket.Name, })