# Prometheus provider

The **Prometheus provider** collects metrics from a Prometheus instance and makes them available to Akamas.

This provider includes support for several technologies. In any case, you can specify your own queries to gather any metric you want.

## Prerequisites

This section provides the minimum requirements that you should match before using the Prometheus provider.

### Supported versions <a href="#supported-versions" id="supported-versions"></a>

* Prometheus 1.x and 2.x.

### Network requirements <a href="#network-requirements" id="network-requirements"></a>

* Prometheus is reachable at a provided URL or IP address and port (the default Prometheus port is 9090)

## Supported Prometheus exporters <a href="#supported-prometheus-exporters" id="supported-prometheus-exporters"></a>

* [Node exporter](https://github.com/prometheus/node_exporter) (Linux system metrics)
* [JMX exporter](https://github.com/prometheus/jmx_exporter) (Java metrics)
* [cAdvisor](https://github.com/google/cadvisor/blob/master/docs/storage/prometheus.md) (Docker container metrics)
* [CloudWatch](https://github.com/prometheus/cloudwatch_exporter) exporter (AWS resources metrics)
* [Jmeter](https://github.com/johrstrom/jmeter-prometheus-plugin) (Web application metrics)

## Akamas supported version <a href="#akamas-supported-version" id="akamas-supported-version"></a>

* Versions < 2.0.0 are compatibile with Akamas untill version 1.8.0
* Versions >= 2.0.0 are compatible with Akamas from version 1.9.0

## Supported component types <a href="#supported-component-types" id="supported-component-types"></a>

* Ubuntu-16.04, Rhel-7.6
* java-openjdk-8, java-openjdk-11
* java-ibm-j9vm-6, java-ibm-j9vm-8, java-eclipse-openj9-11
* Container
* ec2
* Web Application

You can check [Prometheus provider metrics mapping](https://docs.akamas.io/akamas-docs/3.1.2/akamas-reference/telemetry-providers/prometheus-metrics-mapping) to see how component-types metrics are extracted by this provider

## Setup the data source <a href="#setup-the-data-source" id="setup-the-data-source"></a>

The Prometheus provider does not require a specific configuration of the Prometheus instance it uses, except for the need for setting the value of the `instance` label of each data point so that it matches the value of the `instance` property in a component; in this way, the Prometheus provider can know which data point refers to which component in a system.

Here’s an example configuration for Prometheus that sets the `instance` label:

{% code lineNumbers="true" %}

```yaml
# Custom global config
global:
  scrape_interval:     5s   # Set the scrape interval to every 15 seconds. The default is every 1 minute.
  evaluation_interval: 5s   # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# A scrape configuration containing exactly one endpoint to scrape:
scrape_configs:
# Node Exporter
- job_name: 'node'
  static_configs:
  - targets: ["localhost:9100"]
  relabel_configs:
  - source_labels: ["__address__"]
    regex: "(.*):.*"
    target_label: instance
    replacement: value_of_instance_property_in_the_component_the_data_points_should_refer_to
```

{% endcode %}

## Component configuration <a href="#component-configuration" id="component-configuration"></a>

Akamas reasons in terms of a system to be optimized and in terms of parameters and metrics of components of that system. To understand which metrics collected from Prometheus should refer to which component, the Prometheus provider looks up some properties in the components of a system grouped under `prometheus` property. These properties are:

* `instance`, which tells the provider "where" a component is
* `job` (optional), which filters the imported metrics by exporter identifier, useful when different components run on the same instance. If not provided, this value defaults to the one configured globally in the telemetry-instance definition.

Nested under this property you can also include any additional field your use case may require to further filter the imported metrics. These fields will be appended in queries to the list of label matches in the form `field_name=~'field_value'`, and can specify either exact values or patterns.

Notice: you should configure your Prometheus instances so that the Prometheus provider can leverage the `instance` property of components, as described in the [Setup datasource](#setup-the-data-source) section here above.

It is important that you add `instance` and, optionally, the `job` properties to the components of a system so that the Prometheus provider can gather metrics from them:

{% code lineNumbers="true" %}

```yaml
# Specification for a component, whose metrics should be collected by the Prometheus Provider
name: jvm1 # name of the component
description: jvm1 for payment services    # description of the component
properties:
  prometheus:
    instance: service0001  # instance of the component: where the component is located from the point of view of prom
    job: jmx               # job of the component: which prom exporter is gathering metrics from the component
```

{% endcode %}
