GithubHelp home page GithubHelp logo

[QUERY] I need to get cost per subscription, per resourcegroup, per resource for the last whole month and last 365 days to day. about azure-sdk-for-net HOT 8 OPEN

MCDPRO avatar MCDPRO commented on May 26, 2024
[QUERY] I need to get cost per subscription, per resourcegroup, per resource for the last whole month and last 365 days to day.

from azure-sdk-for-net.

Comments (8)

jsquire avatar jsquire commented on May 26, 2024

Thank you for your feedback. Tagging and routing to the team member best able to assist.

from azure-sdk-for-net.

MCDPRO avatar MCDPRO commented on May 26, 2024

Goodday, @ArthurMa1978 ,

do you have any advise or solution to my request.
thanks in advance.

Regards,
Mohamed Charif

from azure-sdk-for-net.

MCDPRO avatar MCDPRO commented on May 26, 2024

@jsquire and @ArthurMa1978 I would like an update please.

from azure-sdk-for-net.

ArthurMa1978 avatar ArthurMa1978 commented on May 26, 2024

@MCDPRO, our team is responsible for creating the SDK based on the provided Swagger spec. As such, our domain knowledge regarding the specific use cases for each API is limited.
Add @HarveyLink to assist with a sample; however, we cannot assure its accuracy.

from azure-sdk-for-net.

MCDPRO avatar MCDPRO commented on May 26, 2024

Goodday @HarveyLink

Any help concerning why not all columns are show in my Request to the API and if i can solve it with the SDK ?

kind regards,
Mohamed Charif

from azure-sdk-for-net.

mcgallan avatar mcgallan commented on May 26, 2024

Hi @MCDPRO , thank you for your feedback. Regarding the issue you mentioned, I will provide a runnable example. In Azure SDK, client.UsageQueryAsync() by default only has Number type UsageDate and String type Currency in columns. Therefore, we need to add aggregation in the dataset parameter so that columns can have the cost we need. Also, if you want to get the cost of the last complete month, TimeframeType.TheLastBillingMonth is a good choice. If you need to get it by year, the custom part in the original code is feasible. Here is a runnable example:

private static async Task GetCostForTimeFrame(ArmClient client, ResourceIdentifier id, TimeframeType timeFrame)
{
    try
    {
        var queryDataSet = new QueryDataset()
        {
            Granularity = GranularityType.Daily,
            Aggregation =
            {
                ["Cost"] = new QueryAggregation(function: FunctionType.Sum, name: "PreTaxCost")
                {
                }
            },
        };
        var query = new QueryDefinition(ExportType.Usage, timeFrame, queryDataSet);
        if (timeFrame == TimeframeType.Custom)
        {
            var today = DateTime.UtcNow;
            var startDate = new DateTime(today.Year, today.Month, 1).AddYears(-1);
            var endDate = new DateTime(today.Year, today.Month, 1).AddDays(-1);
            query.TimePeriod = new QueryTimePeriod(startDate, endDate);
        }

        var result = await client.UsageQueryAsync(id, query);

        var x = result.Value;
        var y = result.GetRawResponse();
        foreach (var row in result.Value.Rows)
        {

            Console.WriteLine($"Date: {row[1]}, Cost: {row[0].ToString()}");
        }

    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

It's worth mentioning that row[2] represents the currency unit of the cost. If needed, you can add it yourself. Also, please make sure to write the subscription, resourcegroup, and resource correctly. If you need to query the cost data for an entire year, please be aware of the API endpoint's request limit to avoid errors like "too many requests". You can refer to this document for further work, it will help you to use the SDK better. If you have any further questions, please reply to me under this issue. I will reply as soon as I see it to help you solve the problem better.

from azure-sdk-for-net.

github-actions avatar github-actions commented on May 26, 2024

Hi @MCDPRO. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

from azure-sdk-for-net.

github-actions avatar github-actions commented on May 26, 2024

Hi @MCDPRO, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

from azure-sdk-for-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.