OCI Cost And Usage Snapshot Analyzer
Description
I built the OCI Cost And Usage Snapshot Analyzer as a lightweight Python automation tool that captures a point in time snapshot of what is currently running in an OCI compartment. Instead of pulling billing data, it focuses on resource usage metadata by collecting Compute instances and Block Volumes, then generating timestamped JSON and Markdown reports that can be uploaded to OCI Object Storage for easy auditing and sharing.
Codebase
Why This Is Useful
In many OCI environments, teams want a quick and repeatable way to answer: What resources exist right now in this compartment, what state are they in and how does the footprint change over time? A consistent snapshot is useful for operational reviews, governance checks and simple “before and after” comparisons when changes are made. This tool makes that easy by producing both a human readable Markdown report and a machine friendly JSON output in every run.
What The Tool Does
The tool performs a read-only inventory of two core resource types in a target compartment:
-
Compute instances: display name, lifecycle state, shape, OCID, availability domain
-
Block volumes: display name, size in GB, lifecycle state, OCID, availability domain
After collection, it writes:
-
A JSON snapshot (for diffing, automation, and extensions)
-
A Markdown snapshot (a simple table for quick review)
Finally, it uploads both artifacts to OCI Object Storage under a configurable prefix.
High Level Architecture
At a high level, the workflow is:
-
Load environment variables and OCI SDK config from the default OCI config file.
-
Collect compute and block volume inventory for a single compartment.
-
Generate a UTC timestamp and write reports to a local
reports/folder. -
Upload the JSON and Markdown artifacts into Object Storage using the bucket name and prefix you provide.
Prerequisites
You will need:
-
Python 3.x
-
Dependencies:
ociandpython-dotenv -
OCI credentials configured (standard OCI config file)
-
IAM permissions to list instances, list volumes and upload objects to your chosen Object Storage bucket (the bucket must already exist).
Expected Output
Each run generates two timestamped files in reports/:
-
cost_snapshot_<timestamp>_UTC.json -
cost_snapshot_<timestamp>_UTC.md
It then uploads those two objects to Object Storage under:
<OCI_OBJECT_PREFIX>/cost_snapshot_<timestamp>_UTC.*
Safety Notes
This tool is designed to be safe to run in production because it performs read only resource discovery (Compute and Block Volume listing). The only write activity is uploading the generated report files to Object Storage.
Comments
Post a Comment