Chapter 10. Subscription consumption
The Ansible Automation Platform metrics utility tool (metrics-utility
) is a command-line utility that is installed on a system containing an instance of automation controller.
When installed and configured, metrics-utility
gathers billing-related metrics from your system and creates a consumption-based billing report. Metrics-utility is especially suited for users who have multiple managed hosts and want to use consumption-based billing. Once a report is generated, it is deposited in a target location that you specify in the configuration file.
Metrics-utility collects two types of data from your system: configuration data and reporting data.
The configuration data includes the following information:
- Version information for automation controller and for the operating system
- Subscription information
- The base URL
The reporting data includes the following information:
- Job name and ID
- Host name
- Inventory name
- Organization name
- Project name
- Success or failure information
- Report date and time
To ensure that metrics-utility
continues to work as configured, clear your report directories of outdated reports regularly.
10.1. Configuring metrics-utility
10.1.1. On Red Hat Enterprise Linux
Prerequisites:
- An active Ansible Automation Platform subscription
Metrics-utility is included with Ansible Automation Platform, so you do not need a separate installation. The following commands gather the relevant data and generate a CCSP report containing your usage metrics. You can configure these commands as cronjobs to ensure they run at the beginning of every month. See How to schedule jobs using the Linux 'cron' utility for more on configuring using the cron syntax.
Procedure
In the cron file, set the following variables to ensure
metrics-utility
gathers the relevant data. To open the cron file for editing, run:crontab -e
Specify the following variables to indicate where the report is deposited in your file system:
export METRICS_UTILITY_SHIP_TARGET=directory export METRICS_UTILITY_SHIP_PATH=/awx_devel/awx-dev/metrics-utility/shipped_data/billing
Set these variables to generate a report:
export METRICS_UTILITY_REPORT_TYPE=CCSP export METRICS_UTILITY_PRICE_PER_NODE=11.55 # in USD export METRICS_UTILITY_REPORT_SKU=MCT3752MO export METRICS_UTILITY_REPORT_SKU_DESCRIPTION="EX: Red Hat Ansible Automation Platform, Full Support (1 Managed Node, Dedicated, Monthly)" export METRICS_UTILITY_REPORT_H1_HEADING="CCSP Reporting <Company>: ANSIBLE Consumption" export METRICS_UTILITY_REPORT_COMPANY_NAME="Company Name" export METRICS_UTILITY_REPORT_EMAIL="email@email.com" export METRICS_UTILITY_REPORT_RHN_LOGIN="test_login" export METRICS_UTILITY_REPORT_COMPANY_BUSINESS_LEADER="BUSINESS LEADER" export METRICS_UTILITY_REPORT_COMPANY_PROCUREMENT_LEADER="PROCUREMENT LEADER"
Add the following parameter to gather and store the data in the provided SHIP_PATH directory in the
./report_data
subdirectory:metrics-utility gather_automation_controller_billing_data --ship --until=10m
To configure the run schedule, add the following parameters to the end of the file and specify how often you want
metrics-utility
to gather information and build a report using cron syntax. In the following example, thegather
command is configured to run every hour at 00 minutes. Thebuild_report
command is configured to run every second day of each month at 4:00 AM.0 */1 * * * metrics-utility gather_automation_controller_billing_data --ship --until=10m 0 4 2 * * metrics-utility build_report
- Save and close the file.
To verify that you saved your changes, run:
crontab -l
You can also check the logs to ensure that data is being collected. Run:
cat /var/log/cron
The following is an example of the output. Note that time and date might vary depending on how your configure the run schedule:
May 8 09:45:03 ip-10-0-6-23 CROND[51623]: (root) CMDOUT (No billing data for month: 2024-04) May 8 09:45:03 ip-10-0-6-23 CROND[51623]: (root) CMDEND (metrics-utility build_report) May 8 09:45:19 ip-10-0-6-23 crontab[51619]: (root) END EDIT (root) May 8 09:45:34 ip-10-0-6-23 crontab[51659]: (root) BEGIN EDIT (root) May 8 09:46:01 ip-10-0-6-23 CROND[51688]: (root) CMD (metrics-utility gather_automation_controller_billing_data --ship --until=10m) May 8 09:46:03 ip-10-0-6-23 CROND[51669]: (root) CMDOUT (/tmp/9e3f86ee-c92e-4b05-8217-72c496e6ffd9-2024-05-08-093402+0000-2024-05-08-093602+0000-0.tar.gz) May 8 09:46:03 ip-10-0-6-23 CROND[51669]: (root) CMDEND (metrics-utility gather_automation_controller_billing_data --ship --until=10m) May 8 09:46:26 ip-10-0-6-23 crontab[51659]: (root) END EDIT (root)
Run the following command to build a report for the previous month:
metrics-utility build_report
The generated report will have the default name CCSP-<YEAR>-<MONTH>.xlsx and will be deposited in the ship path that you specified in step 2.
10.1.2. On OpenShift Container Platform from the Ansible Automation Platform operator
Metrics-utility is included in the OpenShift Container Platform image beginning with version 4.12. If your system does not have metrics-utility
installed, update your OpenShift image to the latest version.
Follow the steps below to configure the run schedule for metrics-utility
on OpenShift Container Platform using the Ansible Automation Platform operator.
Prerequisites:
- A running OpenShift cluster
- An operator-based installation of Ansible Automation Platform on OpenShift Container Platform.
Metrics-utility will run as indicated by the parameters you set in the configuration file. The utility cannot be run manually on OpenShift Container Platform.
10.1.2.1. Create a ConfigMap in the OpenShift UI YAML view
- From the navigation panel on the left side, select ConfigMaps, and then click the Create ConfigMap button.
- On the next screen, select the YAML view tab.
In the
YAML
field, enter the following parameters with the appropriate variables set:apiVersion: v1 kind: ConfigMap metadata: name: automationcontroller-metrics-utility-configmap data: METRICS_UTILITY_SHIP_TARGET: directory METRICS_UTILITY_SHIP_PATH: /metrics-utility METRICS_UTILITY_REPORT_TYPE: CCSP METRICS_UTILITY_PRICE_PER_NODE: '11' # in USD METRICS_UTILITY_REPORT_SKU: MCT3752MO METRICS_UTILITY_REPORT_SKU_DESCRIPTION: "EX: Red Hat Ansible Automation Platform, Full Support (1 Managed Node, Dedicated, Monthly)" METRICS_UTILITY_REPORT_H1_HEADING: "CCSP Reporting <Company>: ANSIBLE Consumption" METRICS_UTILITY_REPORT_COMPANY_NAME: "Company Name" METRICS_UTILITY_REPORT_EMAIL: "email@email.com" METRICS_UTILITY_REPORT_RHN_LOGIN: "test_login" METRICS_UTILITY_REPORT_COMPANY_BUSINESS_LEADER: "BUSINESS LEADER" METRICS_UTILITY_REPORT_COMPANY_PROCUREMENT_LEADER: "PROCUREMENT LEADER"
- Click .
- To verify that the ConfigMap was created and the metric utility is installed, select ConfigMap from the navigation panel and look for your ConfigMap in the list.
10.1.2.2. Deploy automation controller
Deploy automation controller and specify variables for how often metrics-utility
gathers usage information and generates a report.
- From the navigation panel, select Installed Operators.
- Select Ansible Automation Platform.
- In the Operator details, select the automation controller tab.
- Click *.
Select the YAML view option. The
YAML
now shows the default parameters for automation controller. The relevant parameters formetrics-utility
are the following:[cols="50%,50%",options="header"] |==== | *Parameter* | *Variable* | *`metrics_utility_enabled`* | True. | *`metrics_utility_cronjob_gather_schedule`* | @hourly or @daily. | *`metrics_utility_cronjob_report_schedule`* | @daily or @monthly. |====
-
Find the
metrics_utility_enabled
parameter and change the variable totrue
. -
Find the
metrics_utility_cronjob_gather_schedule
parameter and enter a variable for how often the utility should gather usage information (for example, @hourly or @daily). -
Find the
metrics_utility_cronjob_report_schedule
parameter and enter a variable for how often the utility generates a report (for example, @daily or @monthly). - Click .
10.2. Fetching a monthly report
10.2.1. On RHEL
To fetch a monthly report on RHEL, run:
scp -r username@controller_host:$METRICS_UTILITY_SHIP_PATH/data/<YYYY>/<MM>/ /local/directory/
The generated report will have the default name CCSP-<YEAR>-<MONTH>.xlsx and will be deposited in the ship path that you specified.
10.2.2. On OpenShift Container Platform from the Ansible Automation Platform operator
Use the following playbook to fetch a monthly consumption report for Ansible Automation Platform on OpenShift Container Platform:
- name: Copy directory from Kubernetes PVC to local machine hosts: localhost vars: report_dir_path: "/mnt/metrics/reports/{{ year }}/{{ month }}/" tasks: - name: Create a temporary pod to access PVC data kubernetes.core.k8s: definition: apiVersion: v1 kind: Pod metadata: name: temp-pod namespace: "{{ namespace_name }}" spec: containers: - name: busybox image: busybox command: ["/bin/sh"] args: ["-c", "sleep 3600"] # Keeps the container alive for 1 hour volumeMounts: - name: "{{ pvc }}" mountPath: "/mnt/metrics" volumes: - name: "{{ pvc }}" persistentVolumeClaim: claimName: automationcontroller-metrics-utility restartPolicy: Never register: pod_creation - name: Wait for both initContainer and main container to be ready kubernetes.core.k8s_info: kind: Pod namespace: "{{ namespace_name }}" name: temp-pod register: pod_status until: > pod_status.resources[0].status.containerStatuses[0].ready retries: 30 delay: 10 - name: Create a tarball of the directory of the report in the container kubernetes.core.k8s_exec: namespace: "{{ namespace_name }}" pod: temp-pod container: busybox command: tar czf /tmp/metrics.tar.gz -C "{{ report_dir_path }}" . register: tarball_creation - name: Copy the report tarball from the container to the local machine kubernetes.core.k8s_cp: namespace: "{{ namespace_name }}" pod: temp-pod container: busybox state: from_pod remote_path: /tmp/metrics.tar.gz local_path: "{{ local_dir }}/metrics.tar.gz" when: tarball_creation is succeeded - name: Ensure the local directory exists ansible.builtin.file: path: "{{ local_dir }}" state: directory - name: Extract the report tarball on the local machine ansible.builtin.unarchive: src: "{{ local_dir }}/metrics.tar.gz" dest: "{{ local_dir }}" remote_src: yes extra_opts: "--strip-components=1" when: tarball_creation is succeeded - name: Delete the temporary pod kubernetes.core.k8s: api_version: v1 kind: Pod namespace: "{{ namespace_name }}" name: temp-pod state: absent
10.3. Modifying the run schedule
You can configure metrics-utility
to run at specified times and intervals. Run frequency is expressed in cronjobs. See How to schedule jobs using the Linux ‘Cron’ utility for more information.
10.3.1. On RHEL
Procedure
From the command line, run:
crontab -e
After the code editor has opened, update the
gather
andbuild
parameters using cron syntax as shown below:*/2 * * * * metrics-utility gather_automation_controller_billing_data --ship --until=10m */5 * * * * metrics-utili ty build_report
- Save and close the file.
10.3.2. On OpenShift Container Platform from the Ansible Automation Platform operator
Procedure
-
From the navigation panel, select
. - On the next screen, select automation-controller-operator-controller-manager.
- Beneath the heading Deployment Details, click the down arrow button to change the number of pods to zero. This will pause the deployment so you can update the running schedule.
- From the navigation panel, select Installed Operators. From the list of installed operators, select Ansible Automation Platform.
- On the next screen, select the automation controller tab.
- From the list that appears, select your automation controller instance.
-
On the next screen, select the
YAML
tab. In the
YAML
file, find the following parameters and enter a variable representing how oftenmetrics-utility
should gather data and how often it should produce a report:metrics_utility_cronjob_gather_schedule: metrics_utility_cronjob_report_schedule:
- Click .
- From the navigation menu, select automation-controller-operator-controller-manager. and then select
- Increase the number of pods to 1.
To verify that you have changed the
metrics-utility
running schedule successfully, you can take one or both of the following steps:-
return to the
YAML
file and ensure that the parameters described above reflect the correct variables. -
From the navigation menu, select
and ensure that your cronjobs show the updated schedule.
-
return to the