Usage2ADW - Oracle Cloud Infrastructure Usage and Cost Reports to Autonomous Database with APEX Reporting
Usage2adw is a tool which uses the Python SDK to extract the usage reports from your tenant and load it to Oracle Autonomous Database.
Oracle Application Express (APEX) will be used for reporting.
DISCLAIMER – This is not an official Oracle application, It does not supported by Oracle Support, It should NOT be used for utilization calculation purposes, and rather OCI's official cost analysis and usage reports features should be used instead.
Developed by Adi Zohar, 2020-2024
OCI -> Menu -> Compute -> Instances
Create Instance
--> Name = UsageVM
--> Image = Oracle Linux 8
--> Shape = VM.Flex.E4 or Higher
--> Choose your network VCN and Subnet (any type of VCN and Subnet)
--> Assign public IP - Optional if on public subnet
--> Add your public SSH key
--> Press Create
Copy Instance Info:
--> Compute OCID to be used for Dynamic Group Permission
--> Compute IP
OCI -> Menu -> Identity -> Default Domain -> Dynamic Groups -> Create Dynamic Group
--> Name = UsageDownloadGroup
--> Desc = Dynamic Group for the Usage Report VM
--> Rule 1 = ANY { instance.id = 'OCID_Of_Step_1_Instance' }
OCI -> Menu -> Identity -> Policies
Choose Root Compartment
Create Policy
--> Name = UsageDownloadPolicy
--> Desc = Allow Dynamic Group UsageDownloadGroup to Extract Usage report script
--> Statement 1 = define tenancy usage-report as ocid1.tenancy.oc1..aaaaaaaaned4fkpkisbwjlr56u7cj63lf3wffbilvqknstgtvzub7vhqkggq
--> Statement 2 = endorse dynamic-group UsageDownloadGroup to read objects in tenancy usage-report
--> Statement 3 = Allow dynamic-group UsageDownloadGroup to inspect compartments in tenancy
--> Statement 4 = Allow dynamic-group UsageDownloadGroup to inspect tenancies in tenancy
--> Statement 5 = Allow dynamic-group UsageDownloadGroup to read autonomous-databases in compartment {APPCOMP}
--> Statement 6 = Allow dynamic-group UsageDownloadGroup to read secret-bundles in compartment {APPCOMP}
*** Please don't change the usage report tenant OCID, it is fixed for oc1, if you are running on oc2..oc9 please obtain the proper ocid.
OCI -> Menu -> Autonomous Data Warehouse
Create Autonomous Database
--> Compartment = Please Choose
--> Display Name = ADWCUSG
--> Database Name ADWCUSG
--> Workload = Data Warehouse
--> Deployment = Shared
--> Always Free = Optional (20GB storage is limited)
--> ECPU = 2 or OCPU = 1
--> Storage = 1
--> Auto Scale = No
--> (Please choose your own credentials)
--> Choose Network Access = Allow secure Access from Everywhere (you can use VCN as well which requires NSG)
--> Choose License Type
Using the SSH key you provided, SSH to the linux machine from step #1
ssh opc@UsageVM
sudo dnf module install python39
sudo alternatives --set python3 /usr/bin/python3.9
# Install Python required packages
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade oci oracledb requests
# Please refer to the download site for Manual installation = https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
4. install oracle instant client 19
sudo dnf install -y libnsl
sudo rpm -i --force --nodeps https://download.oracle.com/otn_software/linux/instantclient/1923000/oracle-instantclient19.23-basic-19.23.0.0.0-1.x86_64.rpm
sudo rpm -i --force --nodeps https://download.oracle.com/otn_software/linux/instantclient/1923000/oracle-instantclient19.23-sqlplus-19.23.0.0.0-1.x86_64.rpm
sudo rpm -i --force --nodeps https://download.oracle.com/otn_software/linux/instantclient/1923000/oracle-instantclient19.23-tools-19.23.0.0.0-1.x86_64.rpm
sudo rm -f /usr/lib/oracle/current
sudo ln -s /usr/lib/oracle/19.23 /usr/lib/oracle/current
# setup oracle home variables
# Add the below to $HOME/.bashrc:
export CLIENT_HOME=/usr/lib/oracle/current/client64
export PATH=$PATH:$CLIENT_HOME/bin
export TNS_ADMIN=$HOME/ADWCUSG
# Load the variables
source $HOME/.bashrc
cd $HOME
sudo yum install -y git
git clone https://github.com/oracle-samples/usage-reports-to-adw usage_reports_to_adw
cd usage_reports_to_adw
OCI -> Menu -> Indeitty and Security -> Vault
Use Existing Vault or Create new Vault
Use Existing Master Key or Create new Encryption Master Key
--> Bottom Left -> Secrets
--> Create new Secret with the database App Password
--> Write down the secret OCID
Please ensure that your password meets the following criteria:
- Length: Between 12 and 30 characters.
- The password cannot contain the username.
- Character types: Must include at least one uppercase letter, one lowercase letter, and one numeric character (e.g. 0-9).
- No dictionary words: Avoid using common words found in the dictionary.
- Symbols: If you wish to use symbols, you may only use the "#" symbol.
2 options to download the Autonomous Wallet:
Python Script
cd usage_reports_to_adw
python3 usage2adw_download_adb_wallet.py -dbid $database_ocid -secret secret_ocid -folder $HOME/ADWCUSG -zipfile $HOME/wallet.zip
OCI console
# On OCI -> MENU -> Autonomous Data Warehouse -> ADWCUSG
--> Service Console
--> Administration
--> Download Client Credential
--> Specify the Admin Password
--> Copy the Wallet wallet.zip to the Linux folder $HOME/ADWCUSG
# on Linux -> Unzip Wallet
cd $HOME/ADWCUSG
unzip wallet.zip
# Change directory of sqlnet.ora to $HOME/ADWCUSG
sed -i "s#?/network/admin#$HOME/ADWCUSG#" sqlnet.ora
sqlplus admin/<password>@adwcusg_low
# Choose your own password
SQL> create user usage identified by <password>;
SQL> grant connect, resource, dwrole, unlimited tablespace to usage;
SQL> exit
This script will ask for Database Name, Secret Id for Application Password and Extract Start Date
/home/opc/usage_reports_to_adw/usage2adw_setup.sh -setup_credential
This script will ask for:
- Database Name - the database connect string.
- Database Id (OCID) - the database ocid.
- Application Secret Id from KMS Vault.
- Application Secret Tenant Profile - The Tenancy profile (from oci config) in which the Secret Vault resides (For instance principle use 'local')
- Extract Start Date
- Tag Special Key 1 - Convert extract key to column #1
- Tag Special Key 2 - Convert extract key to column #2
# if you want to skip 14 to 18, execute the script /home/opc/usage_reports_to_adw/usage2adw_setup.sh -setup_app
# Load the data:
/home/opc/usage_reports_to_adw/shell_scripts/run_multi_daily_usage2adw.sh
OCI Console -> Autonomous Databases -> ADWCUSG -> Service Console
Development Menu -> Oracle APEX
Enter Admin Password - for first time setup
Database User = USAGE
Workspace Name = USAGE
Sign Out - Top Right Menu -> Sign Out
Login under USAGE Workspace
--> Workspace = USAGE
--> Username = USAGE
--> "USAGE Schema Password"
--> Press Continue
Specify your e-mail and name.
--> Apply Changes
Top 3rd Right Menu -> Manage Users and Groups
--> Create User
Fill:
--> Username
--> Email
--> Password
--> Confirm Password
--> Optional - Require to change passqword = No
--> Apply Changes
Right Click and Download usage2adw_demo_apex_app from github.
APEX Top Menu -> App Builder -> Import
--> Choose File = usage.demo.apex.sql (Download from github apex folder)
--> Press Next
--> Press Next
--> Press Install Application
--> Press Next
--> Press Install
Press Run application
Bookmark the page for future use.
Login = your end user username and password
# Amend the oracle instance client path run_multi_daily_usage2adw.sh according to your environment. i.e. 18.3 or later
$HOME/usage_reports_to_adw/shell_scripts/run_multi_daily_usage2adw.sh
# change execution permission
chmod +x $HOME/usage_reports_to_adw/shell_scripts/run_multi_daily_usage2adw.sh
# Test the execution
$HOME/usage_reports_to_adw/shell_scripts/run_multi_daily_usage2adw.sh
# add crontab that execute every night
0 0 * * * timeout 6h /home/opc/usage_reports_to_adw/shell_scripts/run_multi_daily_usage2adw.sh > /home/opc/usage_reports_to_adw/shell_scripts/run_multi_daily_usage2adw_crontab_run.txt 2>&1
Please Visit How To File
Copyright (c) 2024, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/