﻿# Install Prometheus Adapter

> [HTML Version](prometheus-adapter.html)

Prometheus Adapter is a component that connects metrics collected by the Prometheus service to the Kubernetes Horizontal Pod Autoscaler (HPA).



Prometheus Adapter provides access to user-defined and external metrics via the Kubernetes API. This allows you to automatically scale applications based on any Prometheus metrics: requests per second, accumulated messages in the RabbitMQ queue, response latency, and other user-defined indicators.



Installing the Prometheus Adapter is not required if you are using:



- [KEDA](install-keda.md) as this add-on already includes the necessary component for working with RabbitMQ metrics.

- Deckhouse with its built-in monitoring module. In this case, you can [configure the Deckhouse ServiceMetric resource](#deckhouse).



This article will cover how to install and configure Prometheus Adapter in a cluster.



Before starting the installation, make sure you have [monitoring tools](install-monitoring-tools.md) and [database monitoring (RabbitMQ)](monitoring-databases.md) installed.



To install the add-on, follow these steps:



1. [Download the Helm chart and configuration file](#download).

2. [Fill out the configuration file](#fill).

3. [Install the add-on using Helm in a Kubernetes cluster](#install).

4. [Configure BRIX to work with Prometheus Adapter](#connect).



**Important**: If you are using Prometheus Adapter together with Prometheus Operator, configure them to use the same Prometheus data source to collect application metrics.





## Step 1: Download the Helm chart and configuration file



To install via the Internet, obtain the `values-prometheus-adapter.yaml` configuration file by running the command:

````
helm repo add brix365 https://charts.brix365.com  
helm repo update  
helm show values brix365/prometheus-adapter > values-prometheus-adapter.yaml

````
Obtaining the configuration file for installation in an isolated enviroment without internet access

1. On a computer with internet access, download the latest version of the **prometheus-adapter** chart archive from the **brix365** repository. Use the following command:

````
helm repo add brix365 https://charts.brix365.com  
helm repo update  
helm pull brix365/prometheus-adapter

2. ````
Copy the resulting `prometheus-adapter-X.Y.Z.tgz` chart archive to the server where you will install it.

3. Unzip the `prometheus-adapter-X.Y.Z.tgz` chart on the server where you will install it.

4. Copy the default `values.yaml` configuration file to `values-prometheus-adapter.yaml`:

````
tar -xf prometheus-adapter-X.Y.Z.tgz  
cp prometheus-adapter/values.yaml values-prometheus-adapter.yaml
````

````


## Step 2: Fill out the configuration file

Fill out the `values-prometheus-adapter.yaml` configuration file to install Prometheus Adapter.



**Important**: Check the `url: http://monitoring-kube-prometheus-prometheus.monitoring.svc` parameter. It should point to your Prometheus service.



Sample configuration file for installing Prometheus Adapter

````
prometheus-adapter:  
  prometheus:  
    url: http://monitoring-kube-prometheus-prometheus.monitoring.svc  
    port: 9090  
  rules:  
    default: false  
    external:  
    - seriesQuery: 'rabbitmq\_queue\_messages\{queue\!=""\}'   
      name:   
        matches: "^rabbitmq\_queue\_messages\$"  
        as: "rabbitmq-queue-messages"   
      metricsQuery: 'rabbitmq\_queue\_messages\{<<.LabelMatchers>>\}'   
   - seriesQuery: 'rabbitmq\_queue\_messages\{queue="\_postman.\_new\_messages"\}'   
      name:   
        matches: "^rabbitmq\_queue\_messages\$"  
        as: "rabbitmq-queue-messages-postman"   
     metricsQuery: 'rabbitmq\_queue\_messages\{<<.LabelMatchers>>\}'

````
Where:

- `seriesQuery` is a Prometheus query to find metrics.

- `name.as` is the name under which the metric will be available in the Kubernetes API. You can check for the metric's presence using the command:

````
kubectl get --raw /apis/external.metrics.k8s.io/v1beta1

- ````
`metricsQuery` is a PromQL query to retrieve the value. The `<<.LabelMatchers>>` parameter will be automatically inserted for filtering by labels.



Filling in the connection parameters to a private registry for installation in an isolated enviroment without internet access

  
To connect to a private registry:



1. [Download BRIX images](downloadin-images-elma365.md) and place them in your local image registry.

2. Specify the address and path for the `image.repository` parameter.

3. In the `image.pullSecrets` parameter, specify the name of the secret with access permissions to the private registry. The secret must be manually created and Base64-encoded.



````
prometheus-adapter:  
\## connection parameters for the private registry  
image:  
\## address and path for private registry  
  repository: registry.example.com/prometheus-adapter  
\#   tag: "v0.12.0"  
  pullSecrets:   
    - myRegistryKeySecretName
````

````


## Step 3: Install the prometheus-adapter chart using Helm in the Kubernetes cluster

Install the **prometheus-adapter** chart in the **monitoring** namespace:



- For online installation use the command:

````
helm upgrade --install -n monitoring prometheus-adapter brix365/prometheus-adapter -f values-prometheus-adapter.yaml

- ````
To install without internet access, go to the repository with the downloaded chart and run the command:

````
helm upgrade --install prometheus-adapter ./prometheus-adapter -f values-prometheus-adapter.yaml -n monitoring

````


## Step 4: Configure BRIX to work with Prometheus Adapter



Prometheus Adapter enables the HPA mechanism to automatically scale BRIX application pods based on the load on the RabbitMQ message queue.



To use RabbitMQ metrics for HPA, enable the following parameters in the global configuration of the BRIX application. To do this, edit the `values-brix365.yaml` file used during installation.

````
Начало внимание

````
Before editing the `values-brix365.yaml` file, create a backup copy as incorrectly configured parameters may cause the BRIX application to malfunction.

````
Конец внимание

````


Configure the following parameters:



````
brix365:  
  global:  
    monitoring:  
      externalRmqMetrics: true       # Enable RabbitMQ Metrics for HPA   
      rmqExporterVhost: "brix365"    # Specify a vhost for the HPA metrics exporter (by default: "brix365")  
    autoscaling:  
      rabbitmqQueueLength: 500       # Maximum number of messages in the RabbitMQ queue for autoscaling

````
For more information about all the parameters in the` values-brix365.yaml` configuration file and how to work with them, see [Modify BRIX parameters](change-settings-enterprise.md).



## Configure the Deckhouse ServiceMetric resource for BRIX autoscaling



If you are using Deckhouse with the built-in monitoring module, you can use RabbitMQ queue metrics for pod autoscaling in BRIX. These metrics are collected using the Deckhouse ServiceMetric resource. The HPA will use these metrics to make scaling decisions.



To create the ServiceMetric resource:



1. Save the manifest to a file, such as `rabbitmq-metrics.yaml`:

````
apiVersion: deckhouse.io/v1beta1  
kind: ServiceMetric  
metadata:  
  name: rabbitmq-queue-messages  
spec:  
  query: |  
    sum(rabbitmq\_queue\_messages\{<<.LabelMatchers>>, queue\!=""\}) by (queue)  
\---  
apiVersion: deckhouse.io/v1beta1  
kind: ServiceMetric  
metadata:  
  name: rabbitmq-queue-messages-postman  
spec:  
  query: |  
    sum(rabbitmq\_queue\_messages\{<<.LabelMatchers>>, queue="\_postman.\_new\_messages"\}) by (queue)

````


2. Apply the manifest with the command:

````
kubectl apply -f rabbitmq-metrics.yaml

````
