> ## Documentation Index
> Fetch the complete documentation index at: https://docs.open-metadata.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage Workflow Guide | OpenMetadata Ingestion Workflows

> Monitor usage patterns from queries and dashboards with workflow-based usage extraction.

# Usage Workflow

Learn how to configure the Usage workflow from the UI to ingest Query history data from your data sources.

This workflow is available ONLY for the following connectors:

* [BigQuery](https://docs.open-metadata.org/v2.1.x/connectors/database/bigquery.md)
* [Clickhouse](https://docs.open-metadata.org/v2.1.x/connectors/database/clickhouse.md)
* [Databricks](https://docs.open-metadata.org/v2.1.x/connectors/database/databricks.md)
* [Exasol](https://docs.open-metadata.org/v2.1.x/connectors/database/exasol.md)
* [MSSQL](https://docs.open-metadata.org/v2.1.x/connectors/database/mssql.md)
* [PostgreSQL](https://docs.open-metadata.org/v2.1.x/connectors/database/postgres.md)
* [Redshift](https://docs.open-metadata.org/v2.1.x/connectors/database/redshift.md)
* [Snowflake](https://docs.open-metadata.org/v2.1.x/connectors/database/snowflake.md)

If your database service is not yet supported, you can use this same workflow by providing a Query Log file!

Learn how to do so 👇

> [card] [Usage Workflow through Query Logs](https://docs.open-metadata.org/v2.1.x/connectors/ingestion/workflows/usage/usage-workflow-query-logs.md)
>
> Configure the usage workflow by providing a Query Log file.

## UI Configuration

Once the metadata ingestion runs correctly and we are able to explore the service Entities, we can add Query Usage information.

This will populate the **Queries** tab from the Table Entity Page.

![table-entity-page](https://mintcdn.com/openmetadata/h5dnF65itE_EGxYN/public/images/features/ingestion/workflows/usage/query-tab.png?fit=max\&auto=format\&n=h5dnF65itE_EGxYN\&q=85\&s=7d83027ead384cd1d96294c55f102c1c)

We can create a workflow that will obtain the query log and table creation information from the underlying database and feed it to OpenMetadata. The Usage Agent will be in charge of obtaining this data.

### Step 1: Add a Usage Agent

1. Navigate to **Connections** and select the service type.

2. Click the service you have added.

3. Open the **Agents** tab, click **Add Agent**, and select **Usage**.

   ![Add Agent menu with Usage highlighted](https://mintcdn.com/openmetadata/GIhJhQEz-bXdMLzp/public/images/v2.1.x/connectors/agents/add-agent-usage.png?fit=max\&auto=format\&n=GIhJhQEz-bXdMLzp\&q=85\&s=d975945ee8a621e5b8c814d7a5c0a72c)

4. Give the agent a recognisable name and click **Next**.

### Step 2: Configure the Agent

Configure the core parameters for the Usage agent:

![Usage Agent Setup](https://mintcdn.com/openmetadata/h5dnF65itE_EGxYN/public/images/features/ingestion/workflows/usage/usage-agent-setup.png?fit=max\&auto=format\&n=h5dnF65itE_EGxYN\&q=85\&s=ffde209b38ef8ae561939bcac1564ce2)

| **Field** | **Description** |
| :- | :- |
| **Query Log Duration** | How many days back to look in query logs to process usage data. Default is `1`. |
| **Stage File Location** | Absolute file path for the temporary file used to store query logs before processing. Default is `/tmp/query_log`. |
| **Filter Condition** | Optional condition to filter which queries are included from the query history. |
| **Result Limit** | Maximum number of query log results to process at a time. Default is `1000`. |
| **Query Log File Path** | File path to the query logs, if reading from a file rather than querying the source directly. |
| **Process Query Cost** | Toggle to enable processing of query cost data alongside usage. |

### Step 3: Schedule and Deploy

Choose how the usage agent should run:

![Schedule Usage Ingestion](https://mintcdn.com/openmetadata/h5dnF65itE_EGxYN/public/images/features/ingestion/workflows/usage/usage-schedule-ingestion.png?fit=max\&auto=format\&n=h5dnF65itE_EGxYN\&q=85\&s=d0bf9e53b541c19bbb1aac2379f5bccd)

* **Schedule**: Runs repeatedly based on a defined interval. Set the **Frequency** (Hourly, Daily, Weekly, Monthly, or Custom) and the **Time** to run.
* **On Demand**: Runs once when manually triggered.

Configure the remaining options:

* **Number of Retries**: How many times to retry if the ingestion fails.
* **Raise on Error**: Toggle on to surface errors immediately rather than silently skipping them.

Click **Add & Deploy** to save and activate the usage agent.

## YAML Configuration

In the [connectors](https://docs.open-metadata.org/v2.1.x/connectors.md) section we showcase how to run the metadata ingestion from a JSON/YAML file using the Airflow SDK or the CLI via metadata ingest. Running a usage workflow is also possible using a JSON/YAML configuration file.

This is a good option if you wish to execute your workflow via the Airflow SDK or using the CLI; if you use the CLI a usage workflow can be triggered with the command `metadata usage -c FILENAME.yaml`. The `serviceConnection` config will be specific to your connector (you can find more information in the [connectors](https://docs.open-metadata.org/v2.1.x/connectors.md) section), though the sourceConfig for the usage will be similar across all connectors.

## Query Usage

The Query Usage workflow will be using the `query-parser` processor.

After running a Metadata Ingestion workflow, we can run Query Usage workflow.
While the `serviceName` will be the same to that was used in Metadata Ingestion, so the ingestion bot can get the `serviceConnection` details from the server.

### 1. Define the YAML Config

This is a sample config for bigquery Usage:

**Source Configuration**

Configure the source type and service name for your usage workflow.

**Usage Config Type**

**type**: Set to `DatabaseUsage` for database usage ingestion.

**Query Log Duration**

**queryLogDuration**: Configuration to tune how far we want to look back in query logs to process usage data (in days).

**Stage File Location**

**stageFileLocation**: Temporary file name to store the query logs before processing. Absolute file path required.

Note that the location is a directory that will be cleaned at the end of the ingestion.

**Result Limit**

**resultLimit**: Configuration to set the limit for query logs.

**Query Log File Path**

**queryLogFilePath**: Configuration to set the file path for query logs. If instead of getting the query logs from the database we want to pass a file with the queries.

**Processor Configuration**

Choose the `query-parser` processor to parse and process the query logs.

**Stage Configuration**

Configure the staging location for table usage data before it's sent to OpenMetadata.

**Bulk Sink Configuration**

Configure the bulk sink for metadata usage ingestion.

```yaml theme={null}
source:
  type: bigquery-usage
  serviceName: bigquery
  sourceConfig:
    config:
      type: DatabaseUsage
      # Number of days to look back
      queryLogDuration: 7
      # This is a directory that will be DELETED after the usage runs
      stageFileLocation: <path to store the stage file>
      # resultLimit: 1000
      # If instead of getting the query logs from the database we want to pass a file with the queries
      # queryLogFilePath: path-to-file
processor:
  type: query-parser
  config: {}
stage:
  type: table-usage
  config:
    filename: /tmp/bigquery_usage
bulkSink:
  type: metadata-usage
  config:
    filename: /tmp/bigquery_usage
```

### 2. Run with the CLI

After saving the YAML config, we will run the command the same way we did for the metadata ingestion:

```bash theme={null}
metadata usage -c <path-to-yaml>
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.