[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Defining a microservice\n\nThis document describes how to create custom services and services for some\nresources like GKE and Cloud Run.\n\n\nIn Cloud Monitoring, a *service* is a construct that you can\nassociate with SLOs and alerting policies. Several of the resources\nfor which you might create Monitoring services are also\nreferred to as *services* , but with different meanings, like\n[*GKE\nservices*](/kubernetes-engine/docs/concepts/service) or\n[*Cloud Run\nservices*](/run/docs/resource-model#services).\n\nMonitoring can recognize GKE- and\nCloud Run-based services as *candidates* for monitoring.\nTo create services for them, you indicate which candidates you want to be\ntreated as Monitoring services; Monitoring\ncreates the necessary infrastructure for you.\n\nYou can also define arbitrary custom services.\n\nIdentify or create a service\n----------------------------\n\nTo identify candidate services, or to create custom services, go to the\n**Define service** pane:\n\n1. In the Google Cloud console, go to the\n **SLOs** page:\n\n [Go to **SLOs**](https://console.cloud.google.com/monitoring/services)\n\n \u003cbr /\u003e\n\n If you use the search bar to find this page, then select the result whose subheading is\n **Monitoring**.\n2. On the **Services Overview** page, do one of the following:\n\n - Click *add* **Define service**.\n\n - In the **Current status** pane, click the **Define service** link:\n\nFrom the **Define service** pane, you can do the following:\n\n- Create services from a list of candidate services.\n- Define custom services.\n\nThe following sections describe these options.\n\nCreate services\n---------------\n\nCloud Monitoring can identify potential services of the following\ntypes:\n\n- Cloud Service Mesh services\n- Istio on Google Kubernetes Engine services\n- App Engine services\n- GKE namespaces\n- GKE services\n- GKE workloads\n- Cloud Run service\n\nBecause there might be many of these potential services,\nMonitoring doesn't assume you want them all to be treated\nas services with SLOs. To indicate which of the potential services\nMonitoring should treat as services, you use either the\nGoogle Cloud console or the API.\n\n### Use the Google Cloud console to create services\n\nTo create a service by using the Google Cloud console, do the following:\n\n1. On the **Services Overview** page, click **Define service**.\n\n2. Select **Service Candidates**.\n\n There might be a large number of candidate services in the list. You can\n filter the list as follows:\n 1. Click *filter_list* **Filter table**. A list of filter options is\n displayed.\n\n 2. Select one of the options on the filter list. The selected option appears\n in the filter bar.\n\n 3. Click next to the option in the filter bar and start typing. Values\n that match are provided on a list. Select a value from the list.\n\n3. Click a candidate service from the list of potential services.\n\n When you click an entry, the following fields are filled in for you:\n - The display name is set to the name the entry in the list. You can\n change this value.\n\n - A block of JSON code for the configuration of the new service is\n generated from the candidate. Do not change this value.\n\n4. Click **Submit** . When your service is created, a **Success**\n notice is displayed.\n\n### Use the API to create a service\n\nYou can also create services using the [SLO API](/monitoring/api/ref_v3/rest/v3/services),\nwhich is part of the Cloud Monitoring API.\n\nTo create a service programmatically, post a configuration object like one of\nthe following to the [`services.create` method](/monitoring/api/ref_v3/rest/v3/services/create): \n\n### GKE namespace\n\n\nUse the [`GkeNamespace`](/monitoring/api/ref_v3/rest/v3/services#GkeNamespace) structure, for example: \n\n```\n{\n \"displayName\": \"test-kube-namespace\",\n \"gkeNamespace\": {\n \"location\": \"us-central1-c\",\n \"clusterName\": \"cluster-1\",\n \"namespaceName\": \"test-kube-namespace\"\n }\n}\n```\n\n\u003cbr /\u003e\n\n### GKE service\n\n\nUse the [`GkeService`](/monitoring/api/ref_v3/rest/v3/services#GkeService) structure, for example: \n\n```\n{\n \"displayName\": \"test-kube-service\",\n \"gkeService\": {\n \"location\": \"us-central1-c\",\n \"clusterName\": \"cluster-1\",\n \"namespaceName\": \"kube-system\",\n \"serviceName\": \"test-kube-service\"\n }\n}\n```\n\n\u003cbr /\u003e\n\n### GKE workload\n\n\nUse the [`GkeWorkload`](/monitoring/api/ref_v3/rest/v3/services#GkeWorkload) structure, for example: \n\n```\n{\n \"displayName\": \"frontend-a\",\n \"gkeWorkload\": {\n \"location\": \"us-central1-b\",\n \"clusterName\": \"cluster-2\",\n \"namespaceName\": \"default\",\n \"topLevelControllerType\": \"Deployment\",\n \"topLevelControllerName\": \"frontend-a\"\n }\n}\n```\n\n\u003cbr /\u003e\n\n### Cloud Run\n\n\nUse the [`CloudRun`](/monitoring/api/ref_v3/rest/v3/services#CloudRun) structure, for example: \n\n```\n{\n \"displayName\": \"test-cloudrun-service\",\n \"cloudRun\": {\n \"serviceName\": \"test-cloudrun-service\",\n \"location\": \"us-central1\"\n }\n}\n```\n\n\u003cbr /\u003e\n\n### Cloud Service Mesh\n\n\nUse the [`MeshIstio`](/monitoring/api/ref_v3/rest/v3/services#MeshIstio) structure, for example: \n\n```\n{\n \"displayName\": \"test-mesh-istio-service\",\n \"meshIstio\": {\n \"meshUid\": \"mesh-identifier\"\n \"serviceName\": \"test-mesh-istio-service\",\n \"serviceNamespace\": \"default\"\n }\n}\n```\n\n\u003cbr /\u003e\n\n### Istio on GKE\n\n\nUse the [`clusterIstio`](/monitoring/api/ref_v3/rest/v3/services#ClusterIstio) structure, for example: \n\n```\n{\n \"displayName\": \"test-cluster-istio-service\",\n \"clusterIstio\": {\n \"serviceName\": \"test-cloud-service\",\n \"clusterName\": \"cluster-2\",\n \"serviceNamespace\": \"default\",\n \"location\": \"us-central1\"\n }\n}\n```\n\n\u003cbr /\u003e\n\n### App Engine\n\n\nUse the [`AppEngine`](/monitoring/api/ref_v3/rest/v3/services#AppEngine) structure, for example: \n\n```\n{\n \"displayName\": \"test-mesh-istio-service\",\n \"appEngine\": {\n \"\"moduleId\": \"id-of-the-service\"\n }\n}\n```\n\n\u003cbr /\u003e\n\nFor more information about managing services programmatically, see the\nfollowing documents:\n\n- [Constructs in the API](/stackdriver/docs/solutions/slo-monitoring/api/api-structures).\n- [Working with the API](/stackdriver/docs/solutions/slo-monitoring/api/using-api).\n\nCreate a custom service\n-----------------------\n\nWhen no other service type meets your needs, create\na custom service. With a custom service, you can arbitrarily group SLOs\ntogether in a way that is meaningful for your environment or create SLOs\non business metrics that don't correspond to an existing microservice.\n\n### Use the Google Cloud console to create a custom service\n\nTo define a custom service by using the Google Cloud console, do the following:\n\n1. Click **Define service** on the **Services Overview** page to bring up\n the **Define service** pane.\n\n2. Select **Custom Service**.\n\n3. Enter a display name for your custom service.\n\n4. Click **Submit** . When your service is created, a **Success**\n notice is displayed.\n\n### Use the API to create a custom service\n\nTo define a custom service by using the [SLO API](/monitoring/api/ref_v3/rest/v3/services),\npost a [`Custom`](/monitoring/api/ref_v3/rest/v3/services#Custom) configuration object like the following\nto the [`services.create` method](/monitoring/api/ref_v3/rest/v3/services/create): \n\n```\n{\n \"displayName\": \"hello-world-service\",\n \"custom\": {}\n}\n```\n\nFor more information about managing services programmatically, see [Working\nwith the API](/stackdriver/docs/solutions/slo-monitoring/api/using-api).\n\nWhat's next\n-----------\n\nAfter you identify or create a new service, you can do the following:\n\n- 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](/stackdriver/docs/solutions/slo-monitoring/ui/create-slo).\n- 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](/stackdriver/docs/solutions/slo-monitoring/ui/svc-dashboard)."]]