### Install CloudKitty Client Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-source.html Clones and installs the CloudKitty command-line client. ```bash git clone https://opendev.org/openstack/python-cloudkittyclient.git cd python-cloudkittyclient pip install -c https://opendev.org/openstack/requirements/raw/branch/stable//upper-constraints.txt . ``` -------------------------------- ### Install CloudKitty packages Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-debian.html Install the API, processor, and dashboard components for CloudKitty. ```bash apt-get install cloudkitty-api cloudkitty-processor cloudkitty-dashboard ``` -------------------------------- ### Install CloudKitty Services Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-source.html Clones the repository and installs the package using specific version constraints. ```bash git clone https://opendev.org/openstack/cloudkitty.git cd cloudkitty pip install -c https://opendev.org/openstack/requirements/raw/branch/stable//upper-constraints.txt . ``` -------------------------------- ### Install CloudKitty Dashboard Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-source.html Clones and installs the dashboard module for Horizon. ```bash git clone https://opendev.org/openstack/cloudkitty-dashboard.git cd cloudkitty-dashboard pip install -c https://opendev.org/openstack/requirements/raw/branch/stable//upper-constraints.txt . ``` -------------------------------- ### Install CloudKitty Packages Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-rdo.html Installs the core CloudKitty API, processor, and UI packages using the package manager. ```bash dnf install openstack-cloudkitty-api openstack-cloudkitty-processor openstack-cloudkitty-ui ``` -------------------------------- ### Start DevStack Source: https://docs.openstack.org/cloudkitty/latest/admin/devstack.html Execute the stack script to initiate the DevStack deployment process. ```bash ./stack.sh ``` -------------------------------- ### Execute API GET Request Source: https://docs.openstack.org/cloudkitty/latest/developer/api/tutorial.html Example curl command to retrieve the validated output from the API endpoint. ```bash $ curl 'http://cloudkitty-api:8889/v2/example' {"message": "This is an example endpoint"} ``` -------------------------------- ### GET /v1/info/config Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get current configuration in Cloudkitty. ```APIDOC ## GET /v1/info/config ### Description Get current configuration in Cloudkitty. ### Method GET ### Endpoint /v1/info/config ``` -------------------------------- ### Define Hashmap Metrics Configuration Source: https://docs.openstack.org/cloudkitty/latest/user/rating/hashmap.html Example configuration showing how to define metrics with units, alternative names, and grouping. ```yaml metrics: cpu: unit: instance alt_name: instance # [...] image.size: unit: MiB # [...] ``` -------------------------------- ### Define Hashmap Fields and Metadata Source: https://docs.openstack.org/cloudkitty/latest/user/rating/hashmap.html Configuration example demonstrating how to specify groupby and metadata fields for metrics. ```yaml metrics: cpu: unit: instance alt_name: instance groupby: - id - project_id metadata: - flavor_id # [...] volume.size: unit: GiB groupby: - id - project_id metadata: - volume_type # [...] ``` -------------------------------- ### CloudKitty API Response Example Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Example JSON response showing the structure of total datapoints and a list of usage dataframes. ```json { "total": 3, "dataframes": [ { "usage": { "metric_one": [ { "vol": { "unit": "GiB", "qty": 1.2 }, "rating": { "price": 0.04 }, "groupby": { "group_one": "one", "group_two": "two" }, "metadata": { "attr_one": "one", "attr_two": "two" } } ], "metric_two": [ { "vol": { "unit": "GiB", "qty": 1.2 }, "rating": { "price": 0.04 }, "groupby": { "group_one": "one", "group_two": "two" }, "metadata": { "attr_one": "one", "attr_two": "two" } } ] }, "period": { "begin": "2019-07-23T12:28:10+00:00", "end": "2019-07-23T13:28:10+00:00" } }, { "usage": { "volume.size": [ { "vol": { "unit": "GiB", "qty": 1.9 }, "rating": { "price": 3.8 }, "groupby": { "project_id": "8ace6f139a1742548e09f1e446bc9737", "user_id": "b28fd3f448c34c17bf70e32886900eed", "id": "be966c6d-78a0-42cf-bab9-e833ed996dee" }, "metadata": { "volume_type": "" } } ] }, "period": { "begin": "2019-08-01T01:00:00+00:00", "end": "2019-08-01T02:00:00+00:00" } } ] } ``` -------------------------------- ### Upgrade system packages Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-debian.html Ensure all system packages are up to date before installing CloudKitty. ```bash apt update && apt dist-upgrade ``` -------------------------------- ### Group by Time and Project ID Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Example request and response for grouping summary data by time and project_id. ```bash curl "http://cloudkitty-api:8889/v2/summary?groupby=time&groupby=project_id&limit=3" ``` ```json { "total": 232, "columns": [ "begin", "end", "qty", "rate", "project_id" ], "results": [ [ "2019-10-01T06:00:00+02:00", "2019-10-01T07:00:00+02:00", 3.5533905029296875, 1.7766952514648438, "84631866b2d84db49b29828052bdc287" ], [ "2019-10-01T07:00:00+02:00", "2019-10-01T08:00:00+02:00", 3.5533905029296875, 1.7766952514648438, "84631866b2d84db49b29828052bdc287" ], [ "2019-10-01T08:00:00+02:00", "2019-10-01T09:00:00+02:00", 3.5533905029296875, 1.7766952514648438, "84631866b2d84db49b29828052bdc287" ] ] } ``` -------------------------------- ### Install RDO Repository Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-rdo.html Configures the RDO repository for the desired OpenStack release. Replace RELEASE with the specific release name. ```bash dnf install centos-release-openstack-RELEASE # RELEASE can be any supported release name like rocky ``` -------------------------------- ### Configure SQLAlchemy Database Connection Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/storage.html Example configuration for the SQLAlchemy storage backend using the database connection string. ```ini [database] connection = mysql+pymysql://cloudkitty_user:cloudkitty_password@mariadb_host/cloudkitty_database ``` -------------------------------- ### Use NUMBOOL mutation for instance uptime Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/collector.html Example of using NUMBOOL mutation to normalize CPU metrics for instance uptime. ```yaml metrics: cpu: unit: instance mutate: NUMBOOL groupby: - id metadata: - flavor_id ``` -------------------------------- ### List all rating modules response Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Example JSON response body returned when querying the list of all loaded rating modules. ```json { "modules": [ { "module_id": "noop" "description": "Dummy test module.", "enabled": true, "hot-config": false, "priority": 1 }, { "module_id": "hashmap", "description": "HashMap rating module.", "enabled": false, "hot-config": true, "priority": 2 } ] } ``` -------------------------------- ### Get help for a specific command Source: https://docs.openstack.org/cloudkitty/latest/admin/cli/cloudkitty-status.html Displays help information for a specific cloudkitty-status command. ```bash $ cloudkitty-status COMMAND --help ``` -------------------------------- ### GET /v1/storage/dataframes Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/samples/policy-yaml.html Return a list of rated resources for a time period and a tenant. ```APIDOC ## GET /v1/storage/dataframes ### Description Return a list of rated resources for a time period and a tenant. ### Method GET ### Endpoint /v1/storage/dataframes ``` -------------------------------- ### Implement a basic API resource class Source: https://docs.openstack.org/cloudkitty/latest/developer/api/tutorial.html A template for a new resource class inheriting from base.BaseResource, supporting GET and POST methods. ```python from cloudkitty.api.v2 import base class Example(base.BaseResource): def get(self): pass def post(self): pass ``` -------------------------------- ### Create a new CloudKitty pyscript Source: https://docs.openstack.org/cloudkitty/latest/user/rating/pyscripts.html Use the CLI to register a new script file. The script remains active from the start date until the end date, or indefinitely if no end date is provided. ```bash $ cloudkitty pyscript create my_awesome_script script.py ``` -------------------------------- ### Decorate Method for Query Parameter Retrieval Source: https://docs.openstack.org/cloudkitty/latest/developer/api/tutorial.html Example of decorating a method to retrieve parameters from the query string. ```python @api_utils.add_input_schema('query', { voluptuous.Required('fruit'): api_utils.SingleQueryParam(str), }) def post(self, fruit=None): ``` -------------------------------- ### POST /v1/rating/quote Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get an instant quote based on multiple resource descriptions. ```APIDOC ## POST /v1/rating/quote ### Description Get an instant quote based on multiple resource descriptions. ### Method POST ### Endpoint /v1/rating/quote ``` -------------------------------- ### Filter by Project ID and Group by Type Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Example request and response for filtering by a specific project and grouping results by type. ```bash curl "http://cloudkitty-api:8889/v2/summary?filters=project_id%3Afe9c35372db6420089883805b37a34af&groupby=type&groupby=project_id" ``` ```json { "columns": [ "begin", "end", "qty", "rate", "project_id", "type" ], "results": [ [ "2019-06-01T00:00:00Z", "2019-07-01T00:00:00Z", 2590.421676635742, 1295.210838317871, "fe9c35372db6420089883805b37a34af", "image.size" ], [ "2019-06-01T00:00:00Z", "2019-07-01T00:00:00Z", 1354, 3625, "fe9c35372db6420089883805b37a34af", "instance" ], [ "2019-06-01T00:00:00Z", "2019-07-01T00:00:00Z", 502, 502, "fe9c35372db6420089883805b37a34af", "ip.floating" ], [ "2019-06-01T00:00:00Z", "2019-07-01T00:00:00Z", 175.9, 351.8, "fe9c35372db6420089883805b37a34af", "volume.size" ] ], "total": 4 } ``` -------------------------------- ### Locate Python Packages Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-source.html Determines the installation path of Python packages for dashboard integration. ```bash PY_PACKAGES_PATH=`pip --version | cut -d' ' -f4` ``` -------------------------------- ### Execute API POST Request Source: https://docs.openstack.org/cloudkitty/latest/developer/api/tutorial.html Example curl command to submit a JSON body to the API endpoint. ```bash $ curl -X POST -H 'Content-Type: application/json' 'http://cloudkitty-api:8889/v2/example' -d '{"fruit": "banana"}' {"message": "Your fruit is a banana"} ``` -------------------------------- ### Initialize SQL Database Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/configuration.html Create the CloudKitty database and user using MySQL commands. ```bash mysql -uroot -p << EOF CREATE DATABASE cloudkitty; GRANT ALL PRIVILEGES ON cloudkitty.* TO 'CK_DBUSER'@'localhost' IDENTIFIED BY 'CK_DBPASSWORD'; EOF ``` -------------------------------- ### Extend Gnocchi Collector Configuration Source: https://docs.openstack.org/cloudkitty/latest/developer/collector.html Example implementation of a custom collector configuration using the Gnocchi collector as a reference. It extends the base metric schema with custom extra_args and validates the configuration. ```python from cloudkitty import collector GNOCCHI_EXTRA_SCHEMA = { Required('extra_args'): { Required('resource_type'): All(str, Length(min=1)), # Due to Gnocchi model, metric are grouped by resource. # This parameter allows to adapt the key of the resource identifier Required('resource_key', default='id'): All(str, Length(min=1)), Required('aggregation_method', default='max'): In(['max', 'mean', 'min']), }, } class GnocchiCollector(collector.BaseCollector): collector_name = 'gnocchi' @staticmethod def check_configuration(conf): conf = collector.BaseCollector.check_configuration(conf) metric_schema = Schema(collector.METRIC_BASE_SCHEMA).extend( GNOCCHI_EXTRA_SCHEMA) output = {} for metric_name, metric in conf.items(): met = output[metric_name] = metric_schema(metric) if met['extra_args']['resource_key'] not in met['groupby']: met['groupby'].append(met['extra_args']['resource_key']) return output ``` -------------------------------- ### Retrieve scope status response Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Example JSON response returned by the GET /v2/scope endpoint containing a list of scope configurations and their processing status. ```json { "results": [ { "collector": "gnocchi", "fetcher": "keystone", "scope_id": "7a7e5183264644a7a79530eb56e59941", "scope_key": "project_id", "last_processed_timestamp": "2019-05-09 10:00:00", "active": true }, { "collector": "gnocchi", "fetcher": "keystone", "scope_id": "9084fadcbd46481788e0ad7405dcbf12", "scope_key": "project_id", "last_processed_timestamp": "2019-05-08 03:00:00", "active": true }, { "collector": "gnocchi", "fetcher": "keystone", "scope_id": "1f41d183fca5490ebda5c63fbaca026a", "scope_key": "project_id", "last_processed_timestamp": "2019-05-06 22:00:00", "active": true } ] } ``` -------------------------------- ### GET /v2/dataframes Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get DataFrames. ```APIDOC ## GET /v2/dataframes ### Description Get DataFrames. ### Method GET ### Endpoint /v2/dataframes ``` -------------------------------- ### Initialize and Migrate Storage Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/configuration.html Commands to initialize storage and perform database migrations. ```bash cloudkitty-storage-init ``` ```bash cloudkitty-dbsync upgrade ``` -------------------------------- ### GET /v2/summary Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get a rating summary. ```APIDOC ## GET /v2/summary ### Description Get a rating summary. ### Method GET ### Endpoint /v2/summary ``` -------------------------------- ### GET /v2/rating/modules/{module_id} Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get specified module. ```APIDOC ## GET /v2/rating/modules/{module_id} ### Description Get specified module. ### Method GET ### Endpoint /v2/rating/modules/{module_id} ### Parameters #### Path Parameters - **module_id** (string) - Required - The ID of the module to retrieve. ``` -------------------------------- ### GET /v1/rating/modules/{module_id} Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get specified module. ```APIDOC ## GET /v1/rating/modules/{module_id} ### Description Get specified module. ### Method GET ### Endpoint /v1/rating/modules/{module_id} ### Parameters #### Path Parameters - **module_id** (string) - Required - The ID of the module. ``` -------------------------------- ### GET /v2/task/reprocesses Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get reprocessing schedule tasks for scopes. ```APIDOC ## GET /v2/task/reprocesses ### Description Get reprocessing schedule tasks for scopes. ### Method GET ### Endpoint /v2/task/reprocesses ``` -------------------------------- ### Configure CloudKitty Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-source.html Generates sample configuration files and copies them to the system configuration directory. ```bash mkdir /etc/cloudkitty tox -e genconfig cp etc/cloudkitty/cloudkitty.conf.sample /etc/cloudkitty/cloudkitty.conf cp etc/cloudkitty/policy.yaml /etc/cloudkitty cp etc/cloudkitty/api_paste.ini /etc/cloudkitty ``` -------------------------------- ### GET /v2/scope Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get the state of one or several scopes. ```APIDOC ## GET /v2/scope ### Description Get the state of one or several scopes. ### Method GET ### Endpoint /v2/scope ``` -------------------------------- ### Create and list hashmap groups Source: https://docs.openstack.org/cloudkitty/latest/user/rating/hashmap.html Create a new hashmap group for instance uptime and verify its creation by listing all groups. ```bash $ cloudkitty hashmap group create instance_uptime_flavor_id +---------------------------+--------------------------------------+ | Name | Group ID | +---------------------------+--------------------------------------+ | instance_uptime_flavor_id | 9a2ff37d-be86-4642-8b7d-567bace61f06 | +---------------------------+--------------------------------------+ $ cloudkitty hashmap group list +---------------------------+--------------------------------------+ | Name | Group ID | +---------------------------+--------------------------------------+ | instance_uptime_flavor_id | 9a2ff37d-be86-4642-8b7d-567bace61f06 | +---------------------------+--------------------------------------+ ``` -------------------------------- ### GET /v1/info/metrics/{metric_id} Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get specified metric information. ```APIDOC ## GET /v1/info/metrics/{metric_id} ### Description Get specified metric information. ### Method GET ### Endpoint /v1/info/metrics/{metric_id} ### Parameters #### Path Parameters - **metric_id** (string) - Required - The ID of the metric. ``` -------------------------------- ### GET /v1/info/services/{metric_id} Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Get specified service information. ```APIDOC ## GET /v1/info/services/{metric_id} ### Description Get specified service information. ### Method GET ### Endpoint /v1/info/services/{metric_id} ### Parameters #### Path Parameters - **metric_id** (string) - Required - The ID of the metric. ``` -------------------------------- ### Create a hashmap service Source: https://docs.openstack.org/cloudkitty/latest/user/rating/hashmap.html Register a new service named instance for the hashmap rating system. ```bash $ cloudkitty hashmap service create instance +----------+--------------------------------------+ | Name | Service ID | +----------+--------------------------------------+ | instance | b19d801d-e7d4-46f9-970b-3e6d60fc07b5 | +----------+--------------------------------------+ ``` -------------------------------- ### Configure Storage Backend Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/configuration.html Specify the storage version and driver in the configuration file. ```ini [storage] version = 2 backend = influxdb ``` -------------------------------- ### Perform upgrade readiness check Source: https://docs.openstack.org/cloudkitty/latest/admin/cli/cloudkitty-status.html Runs release-specific checks to ensure the environment is ready for an upgrade. ```bash cloudkitty-status upgrade check ``` -------------------------------- ### Create Hashmap Mapping Source: https://docs.openstack.org/cloudkitty/latest/user/rating/hashmap.html Sets the base price per gigabyte for a specific service and group. ```bash $ cloudkitty hashmap mapping create 0.001 \ -s 74ad7e4e-9cae-45a8-884b-368a92803afe \ -t flat -g 9736bbc0-8888-4700-96fc-58db5fded493 ``` -------------------------------- ### Enable Dashboard Module Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-source.html Links the dashboard configuration files into the Horizon enabled directory. ```bash # If horizon is installed by packages: ln -sf $PY_PACKAGES_PATH/cloudkittydashboard/enabled/_[0-9]*.py \ /usr/share/openstack-dashboard/openstack_dashboard/enabled/ # Directly from sources: ln -sf $PY_PACKAGES_PATH/cloudkittydashboard/enabled/_[0-9]*.py \ $PY_PACKAGES_PATH/openstack_dashboard/enabled/ ``` -------------------------------- ### GET /v2/task/reprocesses Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Retrieve a list of all reprocessing tasks. ```APIDOC ## GET /v2/task/reprocesses ### Description The endpoint used to retrieve all reprocessing tasks scheduled for a scope. ### Method GET ### Endpoint /v2/task/reprocesses ### Parameters #### Query Parameters - **scope_ids** (string) - Optional - The scope IDs to retrieve tasks for. - **order** (string) - Optional - The order in which tasks are returned (desc or asc). ### Response #### Success Response (200) - List of objects containing scope_id, reason, start_reprocess_time, end_reprocess_time, and current_reprocess_time. ### Response Example [ { "scope_id": "scope ID goes here", "reason": "The reason for this reprocessing for this scope", "start_reprocess_time": "2021-06-01 00:00:00+00:00", "end_reprocess_time": "2021-07-01 00:00:00+00:00", "current_reprocess_time": "2021-06-06 00:00:00+00:00" } ] ``` -------------------------------- ### Configure Fetcher Backend Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/configuration.html Specify the fetcher backend in the configuration file. ```ini [fetcher] backend = gnocchi ``` -------------------------------- ### Enable OpenStack repository with extrepo Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-debian.html Use extrepo to search for and enable the OpenStack repository on Debian systems. ```bash apt-get install extrepo extrepo search openstack extrepo enable openstack_epoxy apt-get update ``` -------------------------------- ### GET /v1/report/tenants Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Return the list of rated tenants. ```APIDOC ## GET /v1/report/tenants ### Description Return the list of rated tenants. ### Method GET ### Endpoint /v1/report/tenants ``` -------------------------------- ### GET /v2/rating/modules/ Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Retrieves the details of a specific rating module. ```APIDOC ## GET /v2/rating/modules/ ### Description Returns the details of one specific module. ### Method GET ### Endpoint /v2/rating/modules/ ### Response #### Success Response (200) - **module_id** (string) - The id of the module - **description** (string) - A quick description of the module - **enabled** (bool) - Boolean representing if the module is enabled - **hot_config** (bool) - Boolean representing if the module supports hot-config - **priority** (int) - Priority of the module, relative to other modules #### Response Example { "module_id": "sample_id", "description": "Sample extension", "enabled": true, "hot-config": false, "priority": 2 } ``` -------------------------------- ### GET /v2/rating/modules Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Retrieves a list of all loaded rating modules. ```APIDOC ## GET /v2/rating/modules ### Description Returns the list of all rating modules loaded. This method does not require any parameter. ### Method GET ### Endpoint /v2/rating/modules ### Response #### Success Response (200) - **modules** (list) - List of modules. #### Response Example { "modules": [ { "module_id": "noop", "description": "Dummy test module.", "enabled": true, "hot-config": false, "priority": 1 }, { "module_id": "hashmap", "description": "HashMap rating module.", "enabled": false, "hot-config": true, "priority": 2 } ] } ``` -------------------------------- ### GET /v2/rating/modules Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Returns the list of loaded modules in Cloudkitty. ```APIDOC ## GET /v2/rating/modules ### Description Returns the list of loaded modules in Cloudkitty. ### Method GET ### Endpoint /v2/rating/modules ``` -------------------------------- ### GET /v1/storage/dataframes Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Return the amount to pay for a given period. ```APIDOC ## GET /v1/storage/dataframes ### Description Return the amount to pay for a given period. ### Method GET ### Endpoint /v1/storage/dataframes ``` -------------------------------- ### GET /v1/report/total Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Return the summary to pay for a given period. ```APIDOC ## GET /v1/report/total ### Description Return the summary to pay for a given period. ### Method GET ### Endpoint /v1/report/total ``` -------------------------------- ### GET /v1/report/summary Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Return the summary to pay for a given period. ```APIDOC ## GET /v1/report/summary ### Description Return the summary to pay for a given period. ### Method GET ### Endpoint /v1/report/summary ``` -------------------------------- ### Registering a custom fetcher entrypoint Source: https://docs.openstack.org/cloudkitty/latest/developer/fetcher.html Add the custom fetcher to the project.entry-points.cloudkitty.fetchers section in pyproject.toml. ```toml [project.entry-points."cloudkitty.fetchers"] keystone = "cloudkitty.fetcher.keystone:KeystoneFetcher" source = "cloudkitty.fetcher.source:SourceFetcher" # [...] custom = "cloudkitty.fetcher.custom:CustomFetcher" ``` -------------------------------- ### Configure Database Connection Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/configuration.html Define the SQL connection string in the configuration file. ```ini [database] connection = mysql+pymysql://CK_DBUSER:CK_DBPASSWORD@DB_HOST/cloudkitty ``` -------------------------------- ### GET /v1/rating/reload_modules Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Trigger a rating module list reload. ```APIDOC ## GET /v1/rating/reload_modules ### Description Trigger a rating module list reload. ### Method GET ### Endpoint /v1/rating/reload_modules ``` -------------------------------- ### GET /v1/collector/states/{collector_id} Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Query the enable state of a collector. ```APIDOC ## GET /v1/collector/states/{collector_id} ### Description Query the enable state of a collector. ### Method GET ### Endpoint /v1/collector/states/{collector_id} ### Parameters #### Path Parameters - **collector_id** (string) - Required - The ID of the collector. ``` -------------------------------- ### Implement price calculation functions Source: https://docs.openstack.org/cloudkitty/latest/user/rating/pyscripts.html Create functions to calculate service usage costs and map them to service names. ```python # These functions return the price of a service usage on a collect period. # The price is always equivalent to the price per unit multiplied by # the quantity. def get_instance_price(item): if not item['metadata']['flavor_name'] in flavors: return 0 else: return (decimal.Decimal(item['vol']['qty']) * flavors[item['metadata']['flavor_name']]) def get_image_price(item): if not item['vol']['qty']: return 0 else: return decimal.Decimal(item['vol']['qty']) * image_mb_price def get_volume_price(item): if not item['vol']['qty']: return 0 else: return decimal.Decimal(item['vol']['qty']) * volume_gb_price # Mapping each service to its price calculation function services = { 'instance': get_instance_price, 'volume': get_volume_price, 'image': get_image_price } ``` -------------------------------- ### GET /v1/collector/mappings/{service_id} Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html Return a service to collector mapping. ```APIDOC ## GET /v1/collector/mappings/{service_id} ### Description Return a service to collector mapping. ### Method GET ### Endpoint /v1/collector/mappings/{service_id} ### Parameters #### Path Parameters - **service_id** (string) - Required - The ID of the service. ``` -------------------------------- ### Create Log Directory Source: https://docs.openstack.org/cloudkitty/latest/admin/install/install-source.html Creates the directory for CloudKitty log files. ```bash mkdir /var/log/cloudkitty/ ``` -------------------------------- ### GET /v2/dataframes Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Retrieves dataframes from the storage backend with optional pagination and filtering. ```APIDOC ## GET /v2/dataframes ### Description Get dataframes from the storage backend. ### Method GET ### Endpoint /v2/dataframes ### Parameters #### Query Parameters - **limit** (int) - Optional - For pagination. The maximum number of results to return. - **offset** (int) - Optional - For pagination. The index of the first element that should be returned. - **begin** (iso8601 timestamp) - Optional - Begin of the period for which the dataframes are required. - **end** (iso8601 timestamp) - Optional - End of the period for which the dataframes are required. - **filters** (dict) - Optional - Optional filters. ### Response #### Success Response (200) - Returns the requested dataframes. ``` -------------------------------- ### Initialize API Blueprint Source: https://docs.openstack.org/cloudkitty/latest/developer/api/tutorial.html Implement the init method in your module to register resources with the Flask application. ```python from cloudkitty.api.v2 import utils as api_utils def init(app): api_utils.do_init(app, 'example', [ { 'module': __name__ + '.' + 'example', 'resource_class': 'Example', 'url': '', }, ]) return app ``` -------------------------------- ### Create Instance Uptime Flavor Mapping Source: https://docs.openstack.org/cloudkitty/latest/user/rating/hashmap.html Maps an instance flavor to a specific cost within a hashmap group. Requires the flavor ID and group ID. ```bash $ openstack flavor show m1.tiny +----------------------------+----------------------------------------+ | Field | Value | +----------------------------+----------------------------------------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | access_project_ids | None | | disk | 20 | | id | 93195dd4-bbf3-4b13-929d-8293ae72e056 | | name | m1.tiny | | os-flavor-access:is_public | True | | properties | baremetal='false', flavor-type='small' | | ram | 512 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+----------------------------------------+ $ cloudkitty hashmap mapping create 0.01 \ --field-id 18aa50b6-6da8-4c47-8a1f-43236b971625 \ --value 93195dd4-bbf3-4b13-929d-8293ae72e056 \ -g 9a2ff37d-be86-4642-8b7d-567bace61f06 \ -t flat +--------------------------------------+--------------------------------------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+--------------------------------------+------------+--------------------------------------+------------+ | Mapping ID | Value | Created At | Start | End | Name | Description | Deleted | Created By | Updated By | Deleted By | Cost | Type | Field ID | Service ID | Group ID | Project ID | +--------------------------------------+--------------------------------------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+--------------------------------------+------------+--------------------------------------+------------+ | 9c2418dc-99d3-44b6-8fdf-e9fa02f3ceb5 | 93195dd4-bbf3-4b13-929d-8293ae72e056 | 2023-01-01T10:00:00 | 2023-01-01T10:00:00 | None | None | None | None | 7977999e2e2511e6a8b2df30b233ffcb | None | None | 0.01000000 | flat | 18aa50b6-6da8-4c47-8a1f-43236b971625 | None | 9a2ff37d-be86-4642-8b7d-567bace61f06 | None | +--------------------------------------+--------------------------------------+---------------------+---------------------+------+------+-------------+---------+----------------------------------+------------+------------+------------+------+--------------------------------------+------------+--------------------------------------+------------+ ``` -------------------------------- ### Initialize Blueprint and API Source: https://docs.openstack.org/cloudkitty/latest/_modules/cloudkitty/api/v2/utils.html Creates a Flask Blueprint and associated RESTful API instance with custom JSON serialization. ```python def _get_blueprint_and_api(module_name): endpoint_name = module_name.split('.')[-1] blueprint = flask.Blueprint(endpoint_name, module_name) api = flask_restful.Api(blueprint) # Using cloudkitty.json instead of json for serialization api.representation('application/json')(output_json) return blueprint, api ``` -------------------------------- ### Get Resource Metadata Source: https://docs.openstack.org/cloudkitty/latest/_modules/cloudkitty/collector.html Returns default metadata structure for a collected resource. ```python @classmethod def get_metadata(cls, resource_name): """Return metadata about collected resource as a dict. Dict object should contain: - "metadata": available metadata list, - "unit": collected quantity unit """ return {"metadata": [], "unit": "undefined"} ``` -------------------------------- ### Create Service Matching Rule Source: https://docs.openstack.org/cloudkitty/latest/user/rating/hashmap.html Registers a new service for hashmap rating. ```bash $ cloudkitty hashmap service create volume.size +-------------+--------------------------------------+ | Name | Service ID | +-------------+--------------------------------------+ | volume.size | 74ad7e4e-9cae-45a8-884b-368a92803afe | +-------------+--------------------------------------+ ``` -------------------------------- ### GET /v2/task/reprocesses/ Source: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html Retrieve details of a specific reprocessing task by scope ID. ```APIDOC ## GET /v2/task/reprocesses/ ### Description The endpoint used to retrieve a reprocessing task, useful for checking the progress of tasks. ### Method GET ### Endpoint /v2/task/reprocesses/ ### Parameters #### Path Parameters - **path_scope_id** (string) - Required - The scope ID to retrieve. ### Response #### Success Response (200) - **scope_id** (string) - The scope ID. - **reason** (string) - The reason for this reprocessing. - **start_reprocess_time** (iso8601 timestamp) - Start time. - **end_reprocess_time** (iso8601 timestamp) - End time. - **current_reprocess_time** (iso8601 timestamp) - Current progress time. ### Response Example { "scope_id": "scope ID goes here", "reason": "The reason for this reprocessing for this scope", "start_reprocess_time": "2021-06-01 00:00:00+00:00", "end_reprocess_time": "2021-07-01 00:00:00+00:00", "current_reprocess_time": "2021-06-06 00:00:00+00:00" } ``` -------------------------------- ### LIST /v1/info/services Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/policy.html List available services information in Cloudkitty. ```APIDOC ## LIST /v1/info/services ### Description List available services information in Cloudkitty. ### Method LIST ### Endpoint /v1/info/services ``` -------------------------------- ### Configure local.conf for CloudKitty Source: https://docs.openstack.org/cloudkitty/latest/admin/devstack.html Add these lines to your local.conf file to enable the required plugins and services for CloudKitty integration. ```ini [[local|localrc]] # ceilometer enable_plugin ceilometer https://opendev.org/openstack/ceilometer.git master # cloudkitty enable_plugin cloudkitty https://opendev.org/openstack/cloudkitty.git master enable_service ck-api,ck-proc ``` -------------------------------- ### Collector with Scope Filtering Source: https://docs.openstack.org/cloudkitty/latest/developer/collector.html An example of a collector that filters queries based on the configured scope key. ```python from oslo_config import cfg from cloudkitty.collector import BaseCollector CONF = cfg.CONF class MyCollector(BaseCollector): def __init__(self, **kwargs): super(MyCollector, self).__init__(**kwargs) def fetch_all(self, metric_name, start, end, project_id=None, q_filter=None): scope_key = CONF.collect.scope_key filters = {'start': start, 'stop': stop, scope_key: project_id} data = self.client.query( filters=filters, groupby=self.conf[metric_name]['groupby']) # Format data etc return output ``` -------------------------------- ### CloudKitty Configuration File Settings Source: https://docs.openstack.org/cloudkitty/latest/admin/configuration/samples/cloudkitty-conf.html Standard configuration options for CloudKitty, including API, service, and logging parameters. ```ini [DEFAULT] # # From cloudkitty.common.config # # Configuration file for WSGI definition of API. (string value) #api_paste_config = api_paste.ini # The strategy to use for auth. Supports noauth and keystone (string # value) # Possible values: # noauth - # keystone - #auth_strategy = keystone # Name of this node. This can be an opaque identifier. It is not # necessarily a hostname, FQDN, or IP address. However, the node name # must be valid within an AMQP key. (string value) # # This option has a sample default set, which means that # its actual default value may vary from the one documented # below. #host = # # From cotyledon # # Enables or disables logging values of all registered options when # starting a service (at DEBUG level). (boolean value) # Note: This option can be changed without restarting. #log_options = true # Specify a timeout after which a gracefully shutdown server will # exit. Zero value means endless wait. (integer value) # Note: This option can be changed without restarting. #graceful_shutdown_timeout = 60 # # From oslo.log # # If set to true, the logging level will be set to DEBUG instead of # the default INFO level. (boolean value) # Note: This option can be changed without restarting. #debug = false # The name of a logging configuration file. This file is appended to # any existing logging configuration files. For details about logging # configuration files, see the Python logging module documentation. # Note that when logging configuration files are used then all logging # configuration is set in the configuration file and other logging # configuration options are ignored (for example, log-date-format). # (string value) # Note that when logging configuration files are used then all logging # configuration is set in the configuration file and other logging # configuration options are ignored (for example, log-date-format). # (string value) # Note: This option can be changed without restarting. # Deprecated group/name - [DEFAULT]/log_config #log_config_append = # Defines the format string for %%(asctime)s in log records. Default: # %(default)s . This option is ignored if log_config_append is set. # (string value) #log_date_format = %Y-%m-%d %H:%M:%S # (Optional) Name of log file to send logging output to. If no default # is set, logging will go to stderr as defined by use_stderr. This # option is ignored if log_config_append is set. (string value) # Deprecated group/name - [DEFAULT]/logfile #log_file = # (Optional) The base directory used for relative log_file paths. # This option is ignored if log_config_append is set. (string value) # Deprecated group/name - [DEFAULT]/logdir #log_dir = # Use syslog for logging. Existing syslog format is DEPRECATED and # will be changed later to honor RFC5424. This option is ignored if # log_config_append is set. (boolean value) #use_syslog = false # Enable journald for logging. If running in a systemd environment you # may wish to enable journal support. Doing so will use the journal # native protocol which includes structured metadata in addition to # log messages.This option is ignored if log_config_append is set. # (boolean value) #use_journal = false # Syslog facility to receive log lines. This option is ignored if # log_config_append is set. (string value) #syslog_log_facility = LOG_USER # Use JSON formatting for logging. This option is ignored if # log_config_append is set. (boolean value) #use_json = false # Log output to standard error. This option is ignored if # log_config_append is set. (boolean value) #use_stderr = false # (Optional) Set the 'color' key according to log levels. This option # takes effect only when logging to stderr or stdout is used. This # option is ignored if log_config_append is set. (boolean value) #log_color = false # The amount of time before the log files are rotated. This option is # ignored unless log_rotation_type is set to "interval". (integer # value) #log_rotate_interval = 1 # Rotation interval type. The time of the last file change (or the # time when the service was started) is used when scheduling the next # rotation. (string value) # Possible values: # Seconds - # Minutes - # Hours - # Days - # Weekday - # Midnight - #log_rotate_interval_type = days # Maximum number of rotated log files. (integer value) #max_logfile_count = 30 # Log file maximum size in MB. This option is ignored if # "log_rotation_type" is not set to "size". (integer value) #max_logfile_size_mb = 200 # Log rotation type. (string value) # Possible values: # interval - Rotate logs at predefined time intervals. # size - Rotate logs once they reach a predefined size. # none - Do not rotate log files. #log_rotation_type = none ``` -------------------------------- ### List command categories Source: https://docs.openstack.org/cloudkitty/latest/admin/cli/cloudkitty-status.html Run without arguments to see available command categories. ```bash cloudkitty-status ```