services.x-prometheus

services:
  serviceA:
    x-prometheus:
      ContainersInsights: ContainersInsights

Allows to define some settings to make ECS integration to Prometheus easy.

At the moment, the integration focuses primarily in integration with ECS Insights integration and future version will add support for AWS AMP and other Prometheus clusters.

Tip

There are multiple examples of this features in the Labs for you to walk through

ContainersInsights Syntax Reference

EnableCWAgentDebug: bool
CollectEmf: bool
CollectForAppMesh: bool
CollectForJavaJmx: bool|ExporterConfig
CollectForNginx: bool|ExporterConfig
AutoAddNginxPrometheusExporter: bool
CustomRules: [ExporterConfig]

CollectEmf

This allows to turn on EMF Collection from the CW Agent container.

Hint

Same as CWAgentCollectEmf . See for more details.

CollectForAppMesh

Automatically enables and configure the scraping configuration for the envoy sidecar metrics collection. The discovery relies on the container for envoy to be named envoy . When using x-appmesh, the envoy container is added automatically and uses the right name.

CollectForJavaJmx

Default values

This allow to configure automatically the scraping configuration for the JMX endpoint.

When setting the value to true (boolean) then the following default properties are applied

JMX Prometheus Exporter Port

9404

Container label matcher

^.*jmx.*$

Container labes

job

CollectForNginx

When set to true, the following default values are used

JMX Prometheus Exporter Port

9113

Container label matcher

^.*nginx.*$

Container labes

job

AutoAddNginxPrometheusExporter

When set to true, saves you from having to add the nginx prometheus exporter and creates the sidecar for you automatically.

ExporterConfig

This property allows you to override the source_labels and label matcher for the discovery rule. This is useful if you have a container that performs the exporting job but is not using the default values

ExporterPort: int
ExporterPath: str
source_labels: [str]
label_matcher: str

ExporterPort

The port to use for scraping jobs. Default depends on the type of export

ExporterPath

The path at which perform the scraping. Default is /metrics

Hint

The source_labels and label_matcher are the same as ones defined in Custom Rules

source_labels

List of the docker labels to use to match container that are running an exporter against. Defaults to [job]

label_matcher

Regular expression that allows to identify the containers in a task that are exporting. The regular expression is matched against the values defined in source_labels

CustomRules

Custom rules allow you to determine a list of various extra scans to perform.

Hint

This is a lis of ExporterConfig , with a slight modification: the ExporterPort and at least 1 Rule is required.

Rule

- source_labels:
    - container_name
  label_matcher: str
  dimensions:
    - - ClusterName
      - TaskDefinitionFamily
  metric_selectors:
    - "^startsEnds$"

Examples

Simple NGINX service with nginx-prometheus-exporter side car auto-added to the task definition.
services:
  nginx:
    image: ${REGISTRY_URI}sc-ce-kafdrop-nginx:${IMAGE_TAG:-latest}
    volumes:
    - nginx:/etc/nginx/ssl:ro
    networks:
      - internal
    build:
      context: nginx
    deploy:
      labels:
        ecs.task.family: kafdrop
      replicas: 1
      resources:
        reservations:
          cpus: 0.2
          memory: 128M
    ports:
    - 443:443
    depends_on:
      - files-composer
    x-ecr:
      InterpolateWithDigest: true
    x-prometheus:
      ContainersInsights:
        CollectForNginx:
          ExporterPort: 9113
        AutoAddNginxPrometheusExporter: true
JAVA Application with the jmx exporter configured to export on arbitrary port 1234
services:
  kafdrop:
    image: public.ecr.aws/compose-x/amazoncorretto:11
    ports:
    - 9000:9000
    - target: 1234
      protocol: tcp
    x-prometheus:
      ContainersInsights:
        EnableCWAgentDebug: true
        CollectForJavaJmx:
          ExporterPort: 1234
    labels:
      job: jmx_prometheus_export
      jmx_prometheus_export: "true"
    environment:
      JMX_PORT: 8888
    volumes:
    - kafdrop:/app:ro
    depends_on:
      - nginx
    deploy:
      labels:
        ecs.task.family: kafdrop
      replicas: 1
      resources:
        reservations:
          cpus: 0.5
          memory: 1GB
    x-iam:
      PermissionsBoundary: ccoe/js-developer
    command: ["/bin/bash", "/app/start.sh"]
    networks:
      - internal

JSON Schema

Model

services.x-prometheus specification

services.x-prometheus

The services.x-prometheus specification for ComposeX

type

object

properties

  • ContainersInsights

type

object

properties

  • CollectEmf

Enables the CW Agent EMF Logs collection

type

boolean

  • EnableCWAgentDebug

Whether or not enable debug mode for the CloudWatch agent

type

boolean

default

False

  • ScrapingConfiguration

#/definitions/ScrapeConfigDef

  • CollectForAppmesh

Automatically adds envoy EMF Processor

type

boolean

  • CollectForJavaJmx

oneOf

#/definitions/ExporterConfig

Automatically adds JavaJMX/Catalina EMF Processor

type

boolean

  • CollectForNginx

oneOf

type

boolean

#/definitions/ExporterConfig

  • AutoAddNginxPrometheusExporter

If true, ECS Compose-X will automatically add nginx-prometheus-exporter sidecar. Requires CollectForNginx or CollectForNginxPlus to be true

type

boolean

default

False

  • CollectForNginxPlus

type

boolean

  • CustomRules

#/definitions/CustomRulesDef

additionalProperties

False

definitions

  • ScrapeConfigDef

type

object

properties

  • Interval

type

string

pattern

((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)

  • Timeout

type

string

pattern

((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)

  • ScrapingConfigurationFile

Path to a prometheus scraping configuration file.

type

string

  • ExporterConfig

type

object

properties

  • ExporterPort

Prometheus Exporter port

type

number

minimum

0

  • ExporterPath

Override path for metrics collection

type

string

pattern

^/[\x00-\x7F]+$

default

/metrics

  • source_labels

List of docker labels to match tne container to scrape for metrics

type

array

items

type

string

  • label_matcher

Regular expression to of values to match the source_labels against

type

string

additionalProperties

False

  • CustomRulesDef

type

array

items

type

object

properties

  • ExporterPort

#/definitions/ExporterConfig/properties/ExporterPort

  • ExporterPath

#/definitions/ExporterConfig/properties/ExporterPath

  • EmfProcessors

type

array

items

#/definitions/EmfProcessorDef

  • EmfProcessorDef

type

object

properties

  • source_labels

type

array

items

type

string

  • label_matcher

type

string

  • dimensions

type

array

items

type

array

items

type

string

  • metric_selectors

type

array

items

type

string

Definition

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "id": "services.x-prometheus",
  "$id": "services.x-prometheus.spec.json",
  "type": "object",
  "title": "services.x-prometheus specification",
  "description": "The services.x-prometheus specification for ComposeX",
  "additionalProperties": false,
  "properties": {
    "ContainersInsights": {
      "type": "object",
      "properties": {
        "CollectEmf": {
          "type": "boolean",
          "description": "Enables the CW Agent EMF Logs collection"
        },
        "EnableCWAgentDebug": {
          "type": "boolean",
          "description": "Whether or not enable debug mode for the CloudWatch agent",
          "default": false
        },
        "ScrapingConfiguration": {
          "$ref": "#/definitions/ScrapeConfigDef"
        },
        "CollectForAppmesh": {
          "type": "boolean",
          "description": "Automatically adds envoy EMF Processor"
        },
        "CollectForJavaJmx": {
          "oneOf": [
            {
              "$ref": "#/definitions/ExporterConfig"
            },
            {
              "type": "boolean",
              "description": "Automatically adds JavaJMX/Catalina EMF Processor"
            }
          ]
        },
        "CollectForNginx": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "$ref": "#/definitions/ExporterConfig"
            }
          ]
        },
        "AutoAddNginxPrometheusExporter": {
          "type": "boolean",
          "default": false,
          "description": "If true, ECS Compose-X will automatically add nginx-prometheus-exporter sidecar. Requires CollectForNginx or CollectForNginxPlus to be true"
        },
        "CollectForNginxPlus": {
          "type": "boolean"
        },
        "CustomRules": {
          "$ref": "#/definitions/CustomRulesDef"
        }
      }
    }
  },
  "definitions": {
    "ScrapeConfigDef": {
      "type": "object",
      "properties": {
        "Interval": {
          "type": "string",
          "pattern": "((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)"
        },
        "Timeout": {
          "type": "string",
          "pattern": "((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)"
        },
        "ScrapingConfigurationFile": {
          "type": "string",
          "description": "Path to a prometheus scraping configuration file."
        }
      }
    },
    "ExporterConfig": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "ExporterPort": {
          "type": "number",
          "minimum": 0,
          "description": "Prometheus Exporter port"
        },
        "ExporterPath": {
          "type": "string",
          "description": "Override path for metrics collection",
          "default": "/metrics",
          "pattern": "^/[\\x00-\\x7F]+$"
        },
        "source_labels": {
          "description": "List of docker labels to match tne container to scrape for metrics",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "label_matcher": {
          "type": "string",
          "description": "Regular expression to of values to match the source_labels against"
        }
      }
    },
    "CustomRulesDef": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "EmfProcessors",
          "ExporterPort"
        ],
        "properties": {
          "ExporterPort": {
            "$ref": "#/definitions/ExporterConfig/properties/ExporterPort"
          },
          "ExporterPath": {
            "$ref": "#/definitions/ExporterConfig/properties/ExporterPath"
          },
          "EmfProcessors": {
            "type": "array",
            "items": {
              "$ref": "#/definitions/EmfProcessorDef"
            }
          }
        }
      }
    },
    "EmfProcessorDef": {
      "type": "object",
      "required": [
        "source_labels",
        "dimensions",
        "metric_selectors",
        "label_matcher"
      ],
      "properties": {
        "source_labels": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "label_matcher": {
          "type": "string"
        },
        "dimensions": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "metric_selectors": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}