Creating a service-level indicator

If you create custom services, then you must also create service-level objectives (SLOs) for them. There are no pre-defined SLOs for custom services.

You can also create custom SLOs for automatically detected services, but that is less common.

SLOs are built on top of metrics that measure performance and are used as service-level indicators (SLIs). For custom SLOs, you must identify the metrics you want to use in your SLIs.

If you are not creating custom SLOs, you can skip this page.

Characteristics of suitable metric types

There are two types of SLOs you can create for your services:

  • Request-based SLOs.
  • Windows-based SLOs.

SLOs are based on the metric types you choose as SLIs. The values in metrics types are classified by how they are related to each other. This classification is called the metric kind, and it has three possible values, GAUGE, DELTA, and CUMULATIVE. For more information, see MetricKind.

For request-based SLOs, your SLI represents a ratio of good requests to total requests. The metric kind you of your SLI must be DELTA or CUMULATIVE. You can't use GAUGE metrics in request-based SLOs.

For windows-based SLOs, your SLI represents a count of good outcomes in a given period. The acceptable metric kinds depends on how you structure the SLIs. For more information, see Structures for windows-based SLIs.

For more information on the types of SLOs, see Concepts in service monitoring.

You can use metric types provided by Stackdriver Monitoring, or you can use custom metric types you've created, as long as the values are suitable for the SLI you want to create.

Finding suitable metric types

The information about metric types, including the metric kind, can be found in a variety of places:

  • The metric-selector UI used in tools like Metrics Explorer displays a hover-card for the highlighted metric type. This tool works for custom and built-in metrics.

    For example, the following screenshot shows the hover-card for the metric type loadbalancing.googleapis.com/https/request_count as seen in Metrics Explorer:

    A load-balancing metric in Metrics Explorer with hover-card showing metric kind.

    With Metrics Explorer, you can also configure the metric to mimic what the Service Monitoring API does, and you can get a JSON representation of that configuration. This is very useful in creating an SLI manually.

  • The pages in the Metrics list contain tables for each service that detail the metric types associated with the services. These tables include all the built-in metric types, but don't show custom metric types.

    For example, the following screenshot shows the entry for the metric type type loadbalancing.googleapis.com/https/request_count as seen in the list of loadbalancing metrics. These entries often provide more detail than the hover-cards in Metrics Explorer.

    A load-balancing metric in the reference table.

Building the SLI

For service monitoring, metric data is processed in specific ways, which you can replicate in Metrics Explorer. This page assumes you are familiar with using Metrics Explorer. If you need more information, see Metrics Explorer.

To build a request-based SLI based on a time-series ratio, you need two time series: one that represents all requests, and one that represents good (or bad) requests. This type of SLI has the following structure:

  "requestBased": {
    "goodTotalRatio": {
      "totalServiceFilter": [TO_BE_IDENTIFIED],
      "goodServiceFilter": [TO_BE_IDENTIFIED],
    }
  }

To get the value for the goodServiceFilter field:

  1. Select the monitored-resource type and metric type. Remember that the metric kind must be DELTA or CUMULATIVE. This might return many different time series.

    For example, select the http_lb_rule resource type and the loadbalancing.googleapis.com/https/request_count metric type.

  2. Use the Filter field to set the label response_code_class to 200. This filters out any time series with other values for this label. There still might be multiple time series that match.

  3. Choose the sum aggregator to create a single time series. The chart on the Metrics Explorer page displays the resulting time series.

  4. Click More Options above the chart, and select View as JSON from the menu.

    This gives you the JSON that describes the chart. It will include something like the following:

    "dataSets": [
      {
        "timeSeriesFilter": {
          "filter": "metric.type="loadbalancing.googleapis.com/https/request_count" resource.type="http_lb_rule" metric.label."response_code_class"="200""
          "perSeriesAligner": "ALIGN_RATE",
          "crossSeriesReducer": "REDUCE_SUM",
          "secondaryCrossSeriesReducer": "REDUCE_NONE",
          "minAlignmentPeriod": "60s",
          "groupByFields": [],
          "unitOverride": "1"
        },
        "targetAxis": "Y1",
        "plotType": "LINE"
      }
    ],
    

The piece you are interested in is the value of the filter field embedded in the dataSets object:

"filter": "metric.type="loadbalancing.googleapis.com/https/request_count" resource.type="http_lb_rule" metric.label."response_code_class"="200""

To build out the SLI structure:

  1. Insert this value into the SLI structure as the value of the goodServiceFilter field.

  2. Also insert this value into the SLI structure as the value of the totalServiceFilter, but then remove the label part of the filter, metric.label.\"response_code_class\"=\"200\".

The resulting service-level indicator follows:

  "requestBased": {
    "goodTotalRatio": {
      "totalServiceFilter": "metric.type="loadbalancing.googleapis.com/https/request_count" resource.type="http_lb_rule"",
      "goodServiceFilter": "metric.type="loadbalancing.googleapis.com/https/request_count" resource.type="http_lb_rule" metric.label."response_code_class"="200"",
    }
  }

You can then insert this SLI into an SLO, for example:

{
   "serviceLevelIndicator": {
      "requestBased": {
        "goodTotalRatio": {
          "totalServiceFilter": "metric.type="loadbalancing.googleapis.com/https/request_count" resource.type="http_lb_rule"",
          "goodServiceFilter": "metric.type="loadbalancing.googleapis.com/https/request_count" resource.type="http_lb_rule" metric.label."response_code_class"="200"",
        }
     }
   },
   "goal": 0.98,
   "calendarPeriod": "WEEK",
   "displayName": "98% Successful requests in a in calendar week"
}

You can use this to create an SLO, as described in Creating an SLO.

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

Send feedback about...

Stackdriver Monitoring