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

# Monitor Connector Health

> How to gain observability into your Connector instances

Your Formal Connector deployment will require different resource requirements depending on the specifics of your setup. Factors like the number of active connections you expect to pass through the Connector at once, the policies you configure, the payload sizes of requests and responses, and more can affect the health of individual Connector instances.

There are two ways we help our customers get observability into their Connectors: **Logs** and **Metrics**.

## Logs

The Connector emits logs to stdout/stderr that can be captured in your log collector of choice.
For example, if deploying your [Connector on ECS Fargate using Terraform](https://github.com/formalco/terraform-provider-formal/blob/21a509320e912921700dda2269eae2629b5db49e/examples/deployments/aws/postgres/internal/postgres_proxy/ecs.tf#L69), use `logConfiguration` to route these logs to be sent to your observability tool of choice:

```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
resource "aws_ecs_task_definition" "ecs_task" {
  # ignoring other fields irrelevant to logs in this example
  container_definitions = jsonencode([
    {
      name      = var.name
      image     = var.container_image
      essential = true
      environment = [
        {
          name  = "DD_VERSION"
          value = "1.0.0"
        },
        {
          name  = "DD_ENV",
          value = "prod"
        },
        {
          name  = "DD_SERVICE"
          value = var.name
        },
        # specify other env vars here
      ],
      logConfiguration = {
        logDriver = "awsfirelens"
        options = {
          "Name"       = "datadog",
          "Host"       = "http-intake.logs.datadoghq.eu",
          "TLS"        = "on",
          "dd_source"  = var.name,
          "provider"   = "ecs",
          "dd_service" = var.name,
          "apikey"     = var.datadog_api_key
        }
      }
      dependsOn = [
        { "containerName" : "log_router", "condition" : "START" },
        { "condition" = "HEALTHY", "containerName" = "datadog-agent" }
      ]
    },
    {
      name              = "log_router"
      image             = "public.ecr.aws/aws-observability/aws-for-fluent-bit:stable"
      memoryReservation = 50,
      firelensConfiguration = {
        "type" = "fluentbit",
        "options" = {
          "enable-ecs-log-metadata" = "true"
        }
      },
    },
    {
      name  = "datadog-agent",
      image = "public.ecr.aws/datadog/agent:latest",
      portMappings = [
        {
          "containerPort" = 8126,
          "hostPort"      = 8126,
          "protocol"      = "tcp"
        }
        {
          # We need this for metrics
          "containerPort" = 4317,
          "hostPort"      = 4317,
          "protocol"      = "tcp"
        }
      ],
      environment = [{
        "name"  = "ECS_FARGATE",
        "value" = "true"
        },
        {
          "name"  = "DD_APM_ENABLED",
          "value" = "true"
        },
        {
          "name"  = "DD_LOGS_ENABLED",
          "value" = "true"
        },
        {
          "name"  = "DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL",
          "value" = "true"
        },
        {
          "name"  = "DD_APM_NON_LOCAL_TRAFFIC",
          "value" = "true"
        },
        {
          "name"  = "DD_API_KEY",
          "value" = var.datadog_api_key
        },
        {
          "name"  = "DD_SITE",
          "value" = "datadoghq.eu"
      }]
    }
  ])
}
```

## Metrics

The Connector emits metrics over [OTLP/gRPC](https://opentelemetry.io/docs/specs/otlp/) to an OpenTelemetry Collector such as [the Datadog Agent](https://docs.datadoghq.com/opentelemetry/setup/agent/) to [127.0.0.1 port 4317](https://opentelemetry.io/docs/specs/otlp/#otlpgrpc-default-port) by default. This endpoint can be customized via connector configuration settings. The Connector currently emits the following metrics:

* `formal.connector.instance.heartbeat`: A heartbeat gauge metric once every 30 seconds to verify Connector instance uptime.
* `formal.connector.memory.usage_percent`: A gauge of how much of the memory reserved by the Go runtime is in use. It is heap plus stack in use (`Alloc + StackInuse`) divided by total memory obtained from the OS (`Sys`). It does not use the container memory limit, the host memory, or `GOMEMLIMIT`, so values of 70-90% are normal even when the container uses little of its limit. To alert or autoscale on memory, use container or host memory usage against its limit instead. See [Sizing and Load Testing](https://docs.formal.ai/docs/guides/core-concepts/connectors/sizing.md#metrics-to-watch) for the signals to watch under load.
* `formal.connector.connections_opened`: A counter that is incremented every time the instance accepts a new TCP connection from a client.
* `formal.connector.connections_closed`: A counter that is incremented every time the instance closes a TCP connection from a client.
* `formal.connector.active_connections`: A gauge metric of the current number of open TCP client connections that the instance has.
* `formal.connector.resource_health_check`: A gauge metric of the latest health check result for each resource. The `status="success"` or `status="failure"` series matching the latest result is 1, and the other is 0.

### Deploying an OpenTelemetry Collector

By default the Connector sends metrics to an OpenTelemetry Collector at `127.0.0.1` port 4317, so a Collector on the same host works out of the box. For this setup, run the Datadog Agent as a container on that host (so it is reachable over 127.0.0.1) and set the `DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_GRPC_ENDPOINT=0.0.0.0:4317` environment variable.

You can also configure the Connector to send metrics to a different hostname and port using the Connector configuration settings, either from the Control Plane or with Terraform. In Terraform, use the `otel_endpoint_hostname` and `otel_endpoint_port` fields in your `formal_connector_configuration` resource to specify a custom OpenTelemetry endpoint. If nothing is listening on the configured endpoint, the Connector will refrain from sending metrics entirely.

**Note:** these metrics are not sent over TLS, so make sure the OpenTelemetry endpoint is in your trusted network.

## Datadog Dashboard

To visualize connector health in a single place, we provide a [template dashboard](https://docs.formal.ai/assets/json/connector_health_dashboard_datadog.json) for you to import into your Datadog instance.

![](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/connector_health_dashboard.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=64372b684cecb40d0280fde0678179e2)

* Download the [template JSON](https://docs.formal.ai/assets/json/connector_health_dashboard_datadog.json).
* Sign in to your [Datadog account](https://app.datadoghq.com/).
* Navigate to the [Dashboard List](https://app.datadoghq.com/dashboard/lists) page.
* Choose the **+ New Dashboard** button.

![](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/datadog_dashboard_list.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=8aa6e5674875179419981461692d983d)

* Enter a dashboard name.
* Choose the **New Dashboard** button.

![](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/datadog_create_dashboard_modal.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=202c9efe776c360ecd49d5c3846fdac0)

* In the new dashboard, choose the **Configure** button.
* Choose the **Import dashboard JSON** button.

![](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/datadog_dashboard_configure_pane.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=6ad58b809d3f263629a76b069a637af6)

* Upload the dashboard JSON file downloaded in the previous steps.

## Grafana Dashboard

If you use Grafana with Prometheus, we provide a [template dashboard](https://docs.formal.ai/assets/json/connector_health_dashboard_grafana.json) for you to import into your Grafana instance.

![](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/connector_health_dashboard_grafana.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=2cb3e7126ee45bad08544641e5571ae7)

This dashboard expects metrics to be collected via an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) configured with a Prometheus exporter, which Prometheus then scrapes.

* Download the [template JSON](https://docs.formal.ai/assets/json/connector_health_dashboard_grafana.json).
* Sign in to your Grafana instance.
* Navigate to **Dashboards** in the side menu.
* Choose the **New** button, then **Import**.
* Upload the dashboard JSON file or paste its contents.
* Select your Prometheus data source when prompted.
* Choose **Import**.


## Related topics

- [Operate Connectors](https://docs.formal.ai/docs/guides/core-concepts/connectors/operations.md)
- [Formal Connector](https://docs.formal.ai/docs/guides/core-concepts/connectors/introduction.md)
- [Connector](https://docs.formal.ai/docs/changelog/connector.md)
- [Resources](https://docs.formal.ai/docs/guides/core-concepts/resources/introduction.md)
- [Policy Operations](https://docs.formal.ai/docs/guides/policies/operations.md)


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