Creating Charts and Alerts

This page explains how to use logs-based metrics in charts and alerting policies.

Using Metric Explorer

The fastest way to look at a graph of your logs-based metrics is to use Metrics Explorer:

  1. Visit the logs-based metrics page by clicking the following button:

    Go to Logs-based Metrics

  2. Find the metric you want to look at and choose View in Metrics Explorer in the menu at the right side of the metric's listing. You should see the Metrics Explorer window in Stackdriver Monitoring.

    Metrics Explorer

  3. Set the Metrics Explorer options:

    • Find resource type and metric: This should already be set to your metric and the resource type present in the metric's data.

    • Filter: If you wish, select metric labels to filter on.

    • Aggregation: Aggregation combines multiple time series into one.

      Tip: If you do not see any data in the graph, try setting one of the aggregation options.

Creating a logs-based metric chart

Create a chart in a Stackdriver Monitoring dashboard showing a logs-based metric. You can use either a counter metric or a distribution metric. Do the following:

  1. Visit Stackdriver Monitoring by clicking the following button:

    Go to Stackdriver Monitoring

  2. Select Dashboards > Create Dashboard in the left-side navigation list. You see a blank dashboard with a button to add a chart.

    Alternatively, select Dashboards > [YOUR_DASHBOARD] to add a chart to an existing dashboard.

  3. Click Add Chart in the top-right corner of the window. Fill out the form:

    • Title: Choose a name for the chart.
    • Resource Type: Choose Log Metrics.
    • Metric: Choose one of your user-defined logs-based metrics, which are prefixed by user/.

      You should see data in the Preview window. If not, try expanding the chart's time period to 1w (one week) or 1m (one month).

    • For distribution metrics, there is an option to generate a heatmap instead of a line chart. See Chart type near the bottom of the dialog:

      Stackdriver heatmap chart creation

    • Click Save. The use of the other fields for modifying charts is not covered here. For example, you can restrict charts according to your metric labels.

A sample chart creation dialog is shown below:

Stackdriver dashboard chart creation

Features for distribution metric charts

You create a chart of a distribution metric in the same way you create a counter chart, which is described in the previous section, Creating a logs-based metric chart.

In addition to the features shared by all charts, charts based on distribution metrics have the following features:

  • They can be visualized as heatmaps where the intensity of the color in a given bucket range in the y-axis corresponds to the number of data samples in that bucket.

  • They can be displayed as percentile lines by choosing an alignment option for the 5th, 50th, 95th, or 99th percentile values.

Monitoring charts have a View Logs button in their settings menu. Clicking the button takes you to the Logs Viewer for the time period seen in the chart.

View Logs is not only for logs-based metrics, but rather lets you look at log entries that are relevant to whatever metrics are being displayed in the chart.

Creating a simple alerting policy on a counter metric

To quickly create an alerting policy on a logs-based counter metric, do the following:

  1. Visit the logs-based metrics page by clicking the following button:

    Go to Logs-based Metrics

  2. Find the metric you want to look at and choose Create alert from metric in the menu at the right side of the metric's listing. You should see a pre-populated Add Metric Threshold Condition window in Stackdriver Monitoring.

  3. Fill in the Threshold value. Make any other adjustments needed. The panel shows the selected threshold and the recent value of the metric:

    Add metric threshold

  4. Click Save Condition, which displays the Create new alerting policy panel with your completed condition. You can add additional conditions if you wish.

  5. Fill in the Notifications, Documentation, and Name sections of the alerting policy.

  6. Click Save Policy.

For more information on alerting policies, see Introduction to Alerting. If you have a problem, see Troubleshooting.

Creating conditions with logs-based metrics

To add alerting conditions involving logs-based metrics into a new or existing alerting policy, do the following:

  1. Visit Stackdriver Monitoring by clicking the following button:

    Go to Stackdriver Monitoring

  2. Select Alerting > Create a Policy in the left-side navigation list. You see a blank dashboard with a button to add a chart.

    Alternatively, click Add Policy at the top of the alerting policy overview page.

  3. Create policy conditions:

    1. Click Add Condition.

    2. Choose a type of metric condition: Threshold, Absence, or Rate of Change.

    3. Target: For the resource type, choose Log Metrics

    4. Configuration: For the metric, choose one of the system or user-defined logs-based metrics. You can also specify the value of your metric labels. All logs-based metrics include a label, Log, that is the name of the associated log.

    5. Click Save Condition.

  4. Fill in the Notifications, Documentation, and Name sections of the alerting policy.

  5. Click Save Policy.

For more information on alerting policies, see Introduction to Alerting. If you have a problem, see Troubleshooting.

Was this page helpful? Let us know how we did:

Send feedback about...

Stackdriver Logging