# Monitoring with Grafana

Connect self-hosted Grafana or Grafana Cloud to the Prometheus endpoint and build dashboards from its queries.

Grafana is the most common way to display the numbers from Zato's [Prometheus endpoint](https://zato.io/docs/monitoring/index.html) as dashboards - request rates, latencies, error breakdowns and everything else the platform measures, on one screen that the whole team looks at.

The setup has two parts, and the first one is shared with every other monitoring tool - a Prometheus-compatible scraper collects metrics from Zato, and Grafana queries what the scraper collected. If you have not connected a scraper yet, do that first with the [Prometheus guide](https://zato.io/docs/monitoring/index.html), it takes about 15 minutes.

## Self-hosted Grafana {#self-hosted-grafana}

With your own Grafana and your own Prometheus server, the whole integration is one data source:

- In Grafana, go to **Connections** -> **Data sources** and add a **Prometheus** data source
- Point it at your Prometheus server's address, e.g. `http://prometheus:9090`
- Click **Save and test**

That is all - every query from the [Prometheus guide](https://zato.io/docs/monitoring/index.html) now works in Grafana panels.

## Grafana Cloud {#grafana-cloud}

With Grafana Cloud, there is no Prometheus server of your own to run - Grafana Cloud hosts one for you and its collector ships metrics into it. From your Grafana Cloud portal, open the Prometheus service to find the connection details:

The collector - Grafana Alloy - scrapes Zato's `/metrics` endpoint like any Prometheus would and remote-writes the samples to your cloud stack. The scrape configuration is the same as in the Prometheus guide, plus the remote write block with the URL and credentials from the portal:

```text
prometheus.scrape "zato" {
  targets = [{"__address__" = "zato-server:11223"}]

  metrics_path    = "/metrics"
  scrape_interval = "15s"

  basic_auth {
    username = "metrics"
    password = "your-zato-metrics-password"
  }

  forward_to = [prometheus.remote_write.grafana_cloud.receiver]
}

prometheus.remote_write "grafana_cloud" {
  endpoint {
    url = "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push"

    basic_auth {
      username = "123456"
      password = "your-grafana-cloud-token"
    }
  }
}
```

Once samples arrive, confirm the connection by querying any Zato metric:

## Building the dashboard {#building-the-dashboard}

Create a new dashboard and add panels with the queries you already know. The four below make a complete first screen:

**Request rate per channel** - a time series panel:

```promql
sum by (channel_name) (rate(zato_rest_channel_requests_total[5m]))
```

**p99 latency per channel** - a time series panel, with the unit set to seconds:

```promql
histogram_quantile(0.99,
  sum by (channel_name, le) (rate(zato_rest_channel_request_duration_seconds_bucket[5m]))
)
```

**Error ratio** - a stat panel with thresholds, green below 1%, red above:

```promql
sum(rate(zato_rest_channel_requests_total{status_code=~"4xx|5xx"}[5m]))
  /
sum(rate(zato_rest_channel_requests_total[5m]))
```

**Who caused the errors** - a time series panel split by the `error_source` label, which tells you directly whether a spike came from your services, from an external system they call, from authentication or from rate limiting:

```promql
sum by (error_source) (rate(zato_rest_channel_requests_total{error_source!="none"}[5m]))
```

Beyond REST channels, the same pattern extends to everything else the endpoint exposes - service invocations, outgoing connections, pub/sub throughput and scheduler job outcomes. The [metric reference](https://zato.io/docs/monitoring/prometheus-reference.html) lists every metric with its labels and example queries.

## Alerting {#alerting}

Grafana's alert rules work on the same queries - the burn-rate SLO alert from the [Prometheus guide](https://zato.io/docs/monitoring/index.html) can be pasted into a Grafana alert rule as it is.

## Learn more {#learn-more}

- [Monitoring overview](https://zato.io/docs/monitoring/) - An overview of metrics, dashboards and tracing
- [Datadog](https://zato.io/docs/monitoring/datadog.html) - The OpenMetrics check, dashboards and monitors from API traffic data
- [Health checks](https://zato.io/docs/admin/health-checks.html) - Have Zato ping your outgoing connections instead of waiting for traffic to fail
- [Audit log](https://zato.io/docs/admin/audit-log/) - The record of every message, and what you can do with it afterwards
- [Production checklist](https://zato.io/docs/admin/production-checklist.html) - What to confirm before an environment takes real traffic
