---
title: "Forecasting examples | Grafana Cloud documentation"
description: "This guide provides examples of common forecasting patterns, including traffic analysis, application behavior monitoring, and capacity planning."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Forecasting examples

This guide provides examples of common forecasting patterns, including traffic analysis, application behavior monitoring, and capacity planning.

The examples demonstrate three common ways to use forecasts:

1. Analyze expected behavior and trends.
2. Compare current behavior with the expected forecast.
3. Predict future capacity risk.

## Forecast traffic

The traffic forecast in this example tracks the total number of HTTP requests per minute:

promql ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```promql
sum(rate(http_requests_total[$__rate_interval]) * 60)
```

Traffic often follows recurring patterns, such as daily or weekly usage cycles. Forecasting request volume can help you understand seasonal demand, identify unusual changes, and anticipate periods of higher or lower traffic.

[](/media/docs/grafana-cloud/machine-learning/screenshot-traffic-latency-example.png)

> Tip
> 
> You can explore [this forecast example in Grafana Play](https://play.grafana.org/a/grafana-ml-app/metric-forecast/6476ac3f-9589-4f63-93ee-5eeb7f2839b5?tech=docs&pg=ml-examples&plcmt=callout-tip&cta=traffic-forecast-example).

This example also demonstrates that a useful forecast doesn’t always need an alert. An unexpected increase or decrease in traffic isn’t necessarily a problem by itself. If a traffic change degrades the system, [alerts based on symptoms](/docs/grafana-cloud/observe-and-act/alert-and-measure-reliability/alerting/guides/best-practices/) such as latency or errors can detect the impact.

Use the traffic forecast as additional context to understand demand patterns and determine whether an unexpected change requires further investigation.

## Detect anomalies in application behavior

This example forecasts application behavior by tracking the percentage of requests that produce a successful event.

Success ratios such as successful events divided by total events are also used in [event-based SLOs](/docs/grafana-cloud/observe-and-act/alert-and-measure-reliability/slo/sli-examples/#event-based-slis). They can be useful forecast signals because they describe the relationship between two application events rather than the absolute volume of traffic.

![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```none
Success ratio = rate of successful events (over a period)
                /
                rate of total events (over a period)
```

For example, a service might continue receiving its normal request volume while producing fewer successful outcomes:

- A traffic forecast might not detect the change because traffic remains normal.
- A success-ratio forecast can reveal that the application produces fewer successful outcomes.

[](/media/docs/grafana-cloud/machine-learning/screenshot-success-ratio-example.png)

> Tip
> 
> You can explore [this forecast example in Grafana Play](https://play.grafana.org/a/grafana-ml-app/metric-forecast/1338b3ea-a945-4574-bed3-fd3bed41d256?tech=docs&pg=ml-examples&plcmt=callout-tip&cta=application-behavior-forecast-example).

In the demo application, the ratio represents the percentage of incoming HTTP requests that produce a successful recommendation.

A sustained decrease can indicate that the recommendation service is producing fewer recommendations than expected, even when the overall request rate remains normal. This makes the ratio useful for detecting changes in application behavior that are not visible from traffic volume alone.

#### Alert when the success ratio falls below the expected range

A forecast can act as an adaptive baseline for the signal.

With a static threshold, the alert always evaluates the success ratio against the same value. **With a forecast-based alert, the expected value can change over time based on seasonal patterns**. The alert can therefore detect when the current value deviates from what is normally expected at that point in time.

In this example, the alert compares the current success ratio (`:actual`) with the lower bound of the forecasted range (`:predicted{ml_forecast="yhat_lower"}`):

promql ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```promql
success_ratio_forecast:actual
<
ignoring (ml_forecast)
success_ratio_forecast:predicted{ml_forecast="yhat_lower"}
```

*For query details, refer to [Alerting on forecasts](/docs/grafana-cloud/ai-tools/dynamic-alerting/forecasting/query-and-alerting/#alerting-on-forecasts).*

The condition is met when the current ratio falls below the lower forecast bound. The application still produces successful events, but at a rate that is unusually low compared with its expected behavior.

This alert example fires only when the ratio remains below the lower forecast bound for a sustained period, configured by the [alert rule pending period](/docs/grafana-cloud/observe-and-act/alert-and-measure-reliability/alerting/fundamentals/alert-rule-evaluation/#pending-period). This helps filter out short-lived deviations and focuses the alert on persistent changes in application behavior.

> Tip
> 
> You can explore [this alert example in Grafana Play](https://play.grafana.org/alerting/grafana/dfse46eoqk1s0f/view?tech=docs&pg=ml-examples&plcmt=callout-tip&cta=application-behavior-forecast-alert-example).
> 
> **Alert description**: The percentage of incoming HTTP requests producing recommendations has remained below the expected forecast range for at least 20 minutes. Investigate request traffic, recommendation-service errors, recent deployments, and changes in application behavior.

This pattern is useful when a signal varies over time and a static threshold would miss deviations or generate alerts during normal changes in behavior.

## Detect future capacity risk

You can also use forecasts for **capacity planning** to estimate when a system resource might approach its limit and how its usage is trending over time.

How far you can plan ahead depends on the amount of [training data](/docs/grafana-cloud/ai-tools/dynamic-alerting/forecasting/model-options/#data-range). A longer training window can capture recurring patterns and longer-term trends, and it also supports a longer forecast horizon.

In Grafana Machine Learning, forecasted data is generated for up to half of the training data range:

- With `90` days of training data, the forecast provides up to `45` days of future data.
- With `20` days of training data, the forecast provides up to `10` days of future data.

In contrast to the previous examples, the following capacity-planning examples **alert on future predictions** instead of comparing the current state with the forecast range.

Because the following examples forecast bounded percentages, they configure [Trend Upper and Lower Limits](/docs/grafana-cloud/ai-tools/dynamic-alerting/forecasting/model-options/#trend-upper-and-lower-limits) to keep the forecast within its actual bounds of `[0, 100]`. Without these limits, a forecast can grow beyond the natural bounds of the signal and produce unrealistic values, such as a percentage exceeding `100`.

### Forecast database utilization

This forecast tracks PostgreSQL connection usage as a percentage of the configured connection limit.

promql ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```promql
100 * sum(pg_stat_activity_count)
/
sum(pg_settings_max_connections)
```

[](/media/docs/grafana-cloud/machine-learning/screenshot-db-utilization-forecast-example.png)

> Tip
> 
> You can explore [this forecast example in Grafana Play](https://play.grafana.org/a/grafana-ml-app/metric-forecast/218960cf-3fc0-4d0f-925d-aebf6be22e66?tech=docs&pg=ml-examples&plcmt=callout-tip&cta=db-utilization-forecast-example).

This example demonstrates capacity planning for a bounded resource. Instead of waiting until connection utilization reaches a critical threshold, you can use the forecast to detect if the database is expected to reach that threshold in the future.

1. The forecast uses `30` days of training data, which provides up to `15` days of future forecasted data.
2. The alert queries the forecast over the next `7` days.

[](/media/docs/grafana-cloud/machine-learning/forecast-alert-window3.svg)

In this example, the alert queries the upper forecast bound over the next `7` days and returns its maximum value. The alert fires if the upper forecast bound is expected to exceed `80%` at any point during the seven-day window.

![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```none
maximum `yhat_upper` over the next 7 days > 80%
```

[](/media/docs/grafana-cloud/machine-learning/screenshot-db-utilization-forecast-alert-example.png)

> Tip
> 
> You can explore [this alert example in Grafana Play](https://play.grafana.org/alerting/grafana/efsdlcw28libke/view?tab=query&tech=docs&pg=ml-examples&plcmt=callout-tip&cta=db-utilization-forecast-alert-example).

The alert queries the upper forecast bound (`:predicted{ml_forecast="yhat_upper"}`) to account for prediction uncertainty.

You can tune how conservative the alert is in two ways:

1. Adjust the forecast value in the query with a multiplier. For example, use `* 1.2` to add a 20% margin to the forecast value.
2. Configure the [Uncertainty Interval Width option](/docs/grafana-cloud/ai-tools/dynamic-alerting/forecasting/model-options/#uncertainty-interval-width) to control the confidence interval used to calculate the upper and lower forecast bounds.

### Forecast memory utilization per service

This forecast predicts memory utilization across multiple Kubernetes Deployments.

This is a multidimensional forecast: a single forecast definition produces a separate forecast for each dimension (`{deployment="$service-name"}`).

Each forecasted series represents memory utilization for a particular service (Kubernetes Deployment) and is independent of the other services.

[](/media/docs/grafana-cloud/machine-learning/screenshot-memory-forecast-example.png)

> Tip
> 
> You can explore [this forecast example in Grafana Play](https://play.grafana.org/a/grafana-ml-app/metric-forecast/c28bbafa-2709-4749-9952-ac7dd4d96660?tech=docs&pg=ml-examples&plcmt=callout-tip&cta=memory-utilization-forecast-example).

Like the database utilization example, the alert queries the future prediction and evaluates the upper forecast bound.

![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```none
maximum `yhat_upper` over the next day > 80%
```

The alert fires if forecasted memory utilization is expected to exceed 80% at any point during the next day. For alert query details, refer to the [database utilization alert example](#forecast-database-utilization).

The main difference from the previous example is that this is a multidimensional forecast. A separate forecast is created for each dimension (`{deployment="$service-name"}`).

The alert rule is also [multidimensional](/docs/grafana-cloud/observe-and-act/alert-and-measure-reliability/alerting/examples/multi-dimensional-alerts/), so each service produces a separate alert instance. Each alert instance is associated with a particular service and evaluates that service’s independent forecast.

[](/media/docs/grafana-cloud/machine-learning/screenshot-memory-forecast-alert-example.png)

> Tip
> 
> You can explore [this alert example in Grafana Play](https://play.grafana.org/alerting/grafana/ffsd52gxk0e80f/view?tab=query&tech=docs&pg=ml-examples&plcmt=callout-tip&cta=memory-utilization-forecast-alert-example).

This pattern lets you monitor future capacity across multiple services with a single multidimensional forecast.
