This project enables you to build your own automated MongoDB Atlas Billing Dashboard. It includes a MongoDB Realm application which regularly imports data from the Atlas Billing API into your own Atlas cluster. It also includes a MongoDB Charts dashboard with visualizations of your billing data, which you can use as-is or extend to give you detailed insights into your Atlas usage.
Jump to setup instructions.
Setting up this solution involves a number of steps in the Atlas web portal, followed by some command line scripts to be run locally. Finally you will open MongoDB Charts to import the dashboard.
Atlas Billing
.BillingData
.Atlas Billing
is your active projectBilling App Deployment
Project Owner
role.Atlas Billing
is your active projectBilling API Access
Organization Billing Admin
and Organization Read Only
roles.Install the following prerequisites on your computer if they aren't already present:
Clone this repo to an appropriate directory on your computer:
git clone https://github.com/mongodb/atlas-billing.git
Change directory to the cloned project:
cd atlas-billing
Run the setup script
Using Powershell:
./setupBillingAppService.ps1
Using bash:
./setupBillingAppService.sh
When prompted, enter the public and private API keys for your Organization and Project, as well as the name of your cluster.
Wait for the script to complete, and then verify that data has been loaded into your cluster. Note that the app contains a trigger which will load new data into the cluster daily.
Atlas Billing
projectcharts_billing_template.charts
file from this repo, click Next.The App Services app in this repo contains one function, one trigger and some values & secrets. You can view and update the deployed app by clicking the App Services tab on the top Atlas nav.
getAll
: this function calls the getdata function for each organization. It can be updated to implement cross-organization billing.
processAll
: this function calls the processdata function for each organization. It can be updated to implement cross-organization billing.
getOrgData
: this function retrieves all invoice data related to a specific organization.
processData
: this function updates data and has additional categorization of the data to enhance the output in MongoDB Charts.
billing-org
: maps to the Org Id we want to gather Billing data from. Maps to billing-orgSecret
.
billing-username
: maps to the Public API key for the Org we want to gather Billing data from. Maps to billing-usernameSecret
.
billing-password
: maps to the Private API key for the Org we want to gather Billing data from. Maps to billing-passwordSecret
.
getAllTrigger
: runs at 7am GMT each morning to retrieve the billing data using the getAll
function above.
processAllTrigger
: runs at 7:30am GMT each morning to update the billing data using the processAll
function above.
Additional enhancements are possible such as:
Extend the Billing code to retrieve data from multiple MongoDB Atlas Orgs. Currently, this can be done manually by creating another set of values and secrets for the second organisation and updating the getall
and processall
functions.
For example, you can update getall
as follow to add another organisation:
exports = async function(){
const promises = [
context.functions.execute("getdata_latest", context.values.get("billing-org"), context.values.get("billing-username"), context.values.get("billing-password"))
.catch(err => { return err; }),
context.functions.execute("getdata_latest", context.values.get("SECOND-ORG-ID-VALUE"), context.values.get("SECOND-PUBLIC-API-VALUE"), context.values.get("SECOND-PRIVATE-API-VALUE"))
.catch(err => { return err; }),
];
const results = await Promise.all(promises);
return {"status": "complete!", "results": results };
};