This document describes how to create custom services and services for some
resources like GKE and Cloud Run.


In Cloud Monitoring, a *service* is a construct that you can
associate with SLOs and alerting policies. Several of the resources
for which you might create Monitoring services are also
referred to as *services*, but with different meanings, like
[*GKE services*](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/service.md.txt) or
[*Cloud Run services*](https://docs.cloud.google.com/run/docs/resource-model.md.txt#services).

Monitoring can recognize GKE- and
Cloud Run-based services as *candidates* for monitoring.
To create services for them, you indicate which candidates you want to be
treated as Monitoring services; Monitoring
creates the necessary infrastructure for you.

You can also define arbitrary custom services.

## Identify or create a service

To identify candidate services, or to create custom services, go to the
**Define service** pane:

1. In the Google Cloud console, go to the
   ![](https://docs.cloud.google.com/static/monitoring/images/services-icon.png) **SLOs** page:

   [Go to **SLOs**](https://console.cloud.google.com/monitoring/services)

   <br />

   If you use the search bar to find this page, then select the result whose subheading is
   **Monitoring**.
2. On the **Services Overview** page, do one of the following:

   - Click **Define service**.

   - In the **Current status** pane, click the **Define service** link:

     ![Create custom and user-identified services by using **Define service**.](https://docs.cloud.google.com/static/stackdriver/docs/solutions/slo-monitoring/images/svcmon-msvc-define-svc.png)

From the **Define service** pane, you can do the following:

- Create services from a list of candidate services.
- Define custom services.

The following sections describe these options.

## Create services

Cloud Monitoring can identify potential services of the following
types:

- Cloud Service Mesh services
- Istio on Google Kubernetes Engine services
- App Engine services
- GKE namespaces
- GKE services
- GKE workloads
- Cloud Run service

Because there might be many of these potential services,
Monitoring doesn't assume you want them all to be treated
as services with SLOs. To indicate which of the potential services
Monitoring should treat as services, you use either the
Google Cloud console or the API.

### Use the Google Cloud console to create services

To create a service by using the Google Cloud console, do the following:

1. On the **Services Overview** page, click **Define service**.

2. Select **Service Candidates**.

   ![Potential services are listed on the **Service Candidates** tab.](https://docs.cloud.google.com/static/stackdriver/docs/solutions/slo-monitoring/images/svcmon-msvc-candidate-tab.png)

   There might be a large number of candidate services in the list. You can
   filter the list as follows:
   1. Click **Filter table**. A list of filter options is
      displayed.

   2. Select one of the options on the filter list. The selected option appears
      in the filter bar.

   3. Click next to the option in the filter bar and start typing. Values
      that match are provided on a list. Select a value from the list.

3. Click a candidate service from the list of potential services.

   When you click an entry, the following fields are filled in for you:
   - The display name is set to the name the entry in the list. You can
     change this value.

   - A block of JSON code for the configuration of the new service is
     generated from the candidate. Do not change this value.

4. Click **Submit** . When your service is created, a **Success**
   notice is displayed.

### Use the API to create a service

You can also create services using the [SLO API](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt),
which is part of the Cloud Monitoring API.

To create a service programmatically, post a configuration object like one of
the following to the [`services.create` method](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services/create.md.txt):

### GKE namespace


Use the [`GkeNamespace`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt#GkeNamespace) structure, for example:

```
{
  "displayName": "test-kube-namespace",
  "gkeNamespace": {
    "location": "us-central1-c",
    "clusterName": "cluster-1",
    "namespaceName": "test-kube-namespace"
  }
}
```

<br />

### GKE service


Use the [`GkeService`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt#GkeService) structure, for example:

```
{
  "displayName": "test-kube-service",
  "gkeService": {
    "location": "us-central1-c",
    "clusterName": "cluster-1",
    "namespaceName": "kube-system",
    "serviceName": "test-kube-service"
  }
}
```

<br />

### GKE workload


Use the [`GkeWorkload`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt#GkeWorkload) structure, for example:

```
{
  "displayName": "frontend-a",
  "gkeWorkload": {
    "location": "us-central1-b",
    "clusterName": "cluster-2",
    "namespaceName": "default",
    "topLevelControllerType": "Deployment",
    "topLevelControllerName": "frontend-a"
  }
}
```

<br />

### Cloud Run


Use the [`CloudRun`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt#CloudRun) structure, for example:

```
{
  "displayName": "test-cloudrun-service",
  "cloudRun": {
    "serviceName": "test-cloudrun-service",
    "location": "us-central1"
  }
}
```

<br />

### Cloud Service Mesh


Use the [`MeshIstio`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt#MeshIstio) structure, for example:

```
{
  "displayName": "test-mesh-istio-service",
  "meshIstio": {
    "meshUid": "mesh-identifier"
    "serviceName": "test-mesh-istio-service",
    "serviceNamespace": "default"
  }
}
```

<br />

### Istio on GKE


Use the [`clusterIstio`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt#ClusterIstio) structure, for example:

```
{
  "displayName": "test-cluster-istio-service",
  "clusterIstio": {
    "serviceName": "test-cloud-service",
    "clusterName": "cluster-2",
    "serviceNamespace": "default",
    "location": "us-central1"
  }
}
```

<br />

### App Engine


Use the [`AppEngine`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt#AppEngine) structure, for example:

```
{
  "displayName": "test-mesh-istio-service",
  "appEngine": {
    ""moduleId": "id-of-the-service"
  }
}
```

<br />

For more information about managing services programmatically, see the
following documents:

- [Constructs in the API](https://docs.cloud.google.com/stackdriver/docs/solutions/slo-monitoring/api/api-structures.md.txt).
- [Working with the API](https://docs.cloud.google.com/stackdriver/docs/solutions/slo-monitoring/api/using-api.md.txt).

## Create a custom service

When no other service type meets your needs, create
a custom service. With a custom service, you can arbitrarily group SLOs
together in a way that is meaningful for your environment or create SLOs
on business metrics that don't correspond to an existing microservice.

### Use the Google Cloud console to create a custom service

To define a custom service by using the Google Cloud console, do the following:

1. Click **Define service** on the **Services Overview** page to bring up
   the **Define service** pane.

2. Select **Custom Service**.

   ![Use the **Custom Service** tab to define arbitrary services.](https://docs.cloud.google.com/static/stackdriver/docs/solutions/slo-monitoring/images/svcmon-msvc-custom-tab.png)
3. Enter a display name for your custom service.

4. Click **Submit** . When your service is created, a **Success**
   notice is displayed.

### Use the API to create a custom service

To define a custom service by using the [SLO API](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt),
post a [`Custom`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services.md.txt#Custom) configuration object like the following
to the [`services.create` method](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/services/create.md.txt):

```
{
  "displayName": "hello-world-service",
  "custom": {}
}
```

For more information about managing services programmatically, see [Working
with the API](https://docs.cloud.google.com/stackdriver/docs/solutions/slo-monitoring/api/using-api).

## What's next

After you identify or create a new service, you can do the following:

- Create an SLO for your new service. You must define at least one SLO for your new service for the service to be useful. For more information, see [Creating an SLO](https://docs.cloud.google.com/stackdriver/docs/solutions/slo-monitoring/ui/create-slo.md.txt).
- Go to the dashboard for your new service. For a new service, the dashboard is empty, but you can define SLOs from the dashboard. For more information, see [Using microservice dashboards](https://docs.cloud.google.com/stackdriver/docs/solutions/slo-monitoring/ui/svc-dashboard.md.txt).