> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-xdr-3.x/cortex-xdr-3.x-documentation/data-management/broker-vm/manage-broker-vm/monitor-broker-vm-using-prometheus.md).

# Monitor Broker VM using Prometheus

You can enable local monitoring of the Broker VM to provide usage statistics in a Prometheus metrics format. You can tap in and export data by navigating to `http://<broker_vm_address>:9100/metrics/`. By default, monitoring is disabled.

<details>

<summary>Prerequisite</summary>

To monitor the Broker VM using Prometheus, ensure that you enable monitoring on the Broker VM. This is performed after configuring and registering your Broker VM, when you can edit existing configurations and define additional settings in the **Broker VMs** page.

1. Select **Settings** → **Configurations** → **Data Broker** → **Broker VMs**.
2. In the **Broker VMs** table, locate your Broker VM, right-click, and select **Configure**.

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><h3>Note</h3><p>For all Broker VM nodes added to a HA cluster, you can also <strong>Configure</strong> the Broker VM nodes from the <strong>Clusters</strong> tab.</p></div>
3. In the Broker VM **Configurations** page, select **Monitoring** from the left pane.
4. Clear the **Use Default (Disabled)** checkbox.
5. In the **Montoring** menu, select **Enabled**.
6. Click **Save**.

</details>

**How to set up Prometheus and Grafana to monitor the Broker VM**

Below is an example of how to set up Prometheus and Grafana to monitor the Broker VM. This is set up using a docker compose on an Ubuntu machine to monitor the CPU usage.

Perform the following procedures in the order listed below.

<details>

<summary>Task 1. Install Docker and Docker Compose</summary>

1. Update your Ubuntu system:

   ```programlisting
   sudo apt update
   ```
2. Install Docker:

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><h3>Note</h3><p>For more information on Docker, see the <a href="https://www.docker.com/">Docker website</a>.</p></div>

   ```programlisting
   sudo apt install docker.io
   ```
3. Start the Docker service:

   ```programlisting
   sudo systemctl start docker
   ```
4. Enable Docker to start on boot:

   ```programlisting
   sudo systemctl enable docker
   ```
5. Install Docker Compose:

   ```programlisting
   sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
   ```

   ```programlisting
   sudo chmod +x /usr/local/bin/docker-compose
   ```

</details>

<details>

<summary>Task 2. Create a Docker Compose file</summary>

This task includes setting up Prometheus and Grafana.

1. Create a file named `docker-compose.yml`, and open it for editing:

   ```programlisting
   vim docker-compose.yml
   ```
2. Add the following content to the file:

   ```programlisting
   version: '3.8'
   services:
     prometheus:
       image: prom/prometheus:latest
       container_name: prometheus
       restart: unless-stopped
       volumes:
        - ./prometheus.yml:/etc/prometheus/prometheus.yml
        - prometheus_data:/prometheus
      command:
        - '--config.file=/etc/prometheus/prometheus.yml'
        - '--storage.tsdb.path=/prometheus'
        - '--web.console.libraries=/etc/prometheus/console_libraries'
        - '--web.console.templates=/etc/prometheus/consoles'
        - '--web.enable-lifecycle'
        - '--log.level=debug'
      ports:
        - '9090:9090'
    grafana:
      image: grafana/grafana-enterprise
      container_name: grafana
      restart: unless-stopped
      ports:
       - '3000:3000'
      volumes:
        - grafana_data:/var/lib/grafana
   volumes:
     grafana_data: {}
     prometheus_data: {}
   ```
3. Save and close the file.

</details>

<details>

<summary>Task 3. Create a Prometheus configuration file</summary>

You need to configure Prometheus to scrape the Broker VM metrics by creating a Prometheus configuration file.

1. Create a Prometheus configuration file named `prometheus.yml` in the same directory as the `docker-compose.yml` file that you created above.
2. Open the `prometheus.yml` file for editing:

   ```programlisting
   vim prometheus.yml
   ```
3. Add the following content to the file:

   ```programlisting
   global:
     scrape_interval: 15s
     scrape_timeout: 10s
   scrape_configs:
     - job_name: 'prometheus'
       static_configs:
         - targets: ['<your server IP address>:9090']
     - job_name: 'node'
       static_configs:
         - targets: ['<Broker VM IP address>:9100']
   ```
4. Save and close the file.

</details>

<details>

<summary>Task 4. Run Docker Compose</summary>

1. In the terminal, run the following command from the project directory:

   ```programlisting
   docker-compose up -d
   ```
2. Verify that Prometheus is running correctly:

   ```programlisting
   docker-compose logs -f prometheus
   ```

</details>

<details>

<summary>Task 5. Access Grafana and Set Up Prometheus as a Data Source</summary>

1. Open a web browser and go to `http://<your server>:3000`.
2. Log in to Grafana using the default credentials.
   * Username: `admin`
   * Password: `admin`
3. Set up Prometheus as a data source:
   1. In the left pane, select **Administation** → **Data sources**.
   2. Click **Add data source**, and select **Prometheus**.
   3. Under **HTTP**, set the **URL** to `http://<your server IP address>:9090`.
   4. To verify the connection, click **Save & Test**.

</details>

<details>

<summary>Task 6. Create Dashboards in Grafana</summary>

You can now create dashboards in Grafana to visualize the data from Prometheus.

1. In Grafana, on the left pane, click **Dashboards**.
2. Select **New** and create a new dashboard.
3. Add a panel to the dashboard and configure the dashboard to display the Prometheus metrics that you want.
4. To monitor CPU usage, use the following metric:

   ```programlisting
   100 - (avg by (instance) (rate(node_cpu_seconds_total{job="node",mode="idle"}[1m])) * 100)
   ```

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-xdr-3.x/cortex-xdr-3.x-documentation/data-management/broker-vm/manage-broker-vm/monitor-broker-vm-using-prometheus.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
