GithubHelp home page GithubHelp logo

burnrate's Introduction

Burn Rate Alert

It is a Azure burn rate calculation on logic app.

Everyday at UTC 6:00 am, it grabs the daily cost of all resources used on the day before yesterday (TDBY) and also three days before (ThreeDayBefore) by using Azure Consumption API. Afterwards, it sums up each day's cost. The burn rate is calculated as an increase rate:

Burn Rate = (TDBY - ThreeDayBefore)/ThreeDayBefore

Step 1: Create a Logic App

Follow only steps in the section "Create your logic app" here https://docs.microsoft.com/en-us/azure/logic-apps/quickstart-create-first-logic-app-workflow.

Now you will have an empty logic app. Open it and click "blank logic app" in the templates.

Pick "code view", delete the content and copy paste the whole logicapptemplate.txt here https://github.com/wcex1994/burnrate/blob/master/logicapptemplate into the window. Now go back to the designer view.

Step 2: Subsciption list

In the "Sublist" variable, add in a list of subscription IDs that you would like to calculate the burn rate.

alt text

You can grab related information with the following PowerShell commands:

Login-AzureRmAccount
Get-AzureRmSubscription | Export-Csv "C:\SOME_PATH\Azure Subscription.csv"

Step 3: Managed Identity and IAM

In order to be authenticated and aurthorized to call the Azure Comsumption API, we use Managed Identity and Access Control (IAM). Notice there might be better methods depends on your scenario.

  1. Turn on the Managed Identity in the logic app:

    Go to your logic app --> identity --> click "On"

    alt text

  2. Grant your logic app "Contributor" role in the subscriptions that you would like to calculate the burn rate.

    Subscription --> IAM --> Add Role alt text

    Choose "Contributor" and search for your logic app name --> "Save"

    alt text

    If you have many subscriptons, you can also grant authorization by PowerShell, see https://docs.microsoft.com/en-us/azure/role-based-access-control/tutorial-role-assignments-user-powershell#grant-access.

Step 4: Add Action

In "condition 3" in the logic app designer view, edit threshold and actions. For example, you can send an email in outlook.

alt text

Further Adjustment

  1. Error control:

    E.g. If the cost of previous day is 0, then how does it work to calculate the burn rate, since we cannot divide something by 0.

  2. First day of month:

    The Consumption.UsageDetails.List API only returns current billing period's usage. Azure counts one month as a billing period. If you are on Feb 1st, then to calculate Jan 30th vs. Jan 31st burn rate, you would need to call Consumption.UsageDetails.ListByBillingPeriod API with '201901' as the billing period. See here https://docs.microsoft.com/en-us/rest/api/consumption/usagedetails/listbybillingperiod for more details.

  3. Recurrence:

    I would recommend to have recurrence three times a day (morning, afternoon and night) just to double check.

Additional Information

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.