Monitoring your API

This page describes how you can monitor the health of APIs you own by using the logs and metrics Cloud Endpoints maintains for you automatically. When users make requests to your API, Endpoints logs information about the requests and responses. Endpoints also tracks three of the four golden signals of monitoring: latency, traffic, and errors. These usage and performance metrics help you monitor your API.

Before you begin

You must deploy your API and send requests to it in order to generate logs and metrics for viewing. If you don't have anything set up yet, try the Endpoints quickstart.

API overview

When you are debugging an issue with your service or just want to ensure that everything is running fine, go to your API's overview:

  1. In the Google Cloud console, go to the Endpoints > Services page for your project:

    Go to the Endpoints Services page

  2. If you have more than one API, click the one you want to monitor.

  3. Ensure you are on the Overview tab.

Graphs

At the top are graphs for some of the metrics, so you can spot any spikes and drops right away. You can:

  • In the top-right of the first graph, use the Select graphs drop-down list to show graphs for metrics you are interested in, and remove the ones you don't want to view. Each entry in the drop-down list has a question-mark that you can hold your pointer over to to see a description of the metric it displays.

  • In the top-right corner of the overview, adjust the graphs by selecting from the various time spans. This adjusts the time range of values displayed in these graphs, which also alters the point granularity.

Methods table

When you are ready to drill down further, scroll below the graphs for a table with metrics for individual methods in your API. You can:

  • In the top-right of the table, use the Select columns drop-down list to show the metrics you are interested in and remove the ones you don't want displayed. Entries here also have the question-mark that you can hold your pointer over to see a description.

  • In the top-right corner of the overview, select a time span for the metric values in the table by using the time span picker. This picks a time span for both the graphs and the table.

Logs

When you spot an issue in the metrics, go to the Logs Explorer page in the Google Cloud console to see logs of the requests and responses for your API.

  • To see logs for individual methods of your API, in the table click View logs.

  • To see logs for all methods in your API, in the bottom-right corner click View all logs.

  • To locate Endpoints logs directly from the Logs Explorer page:

    1. In the Google Cloud console, go to the Stackdriver > Logging page:

      Go to the Logs Explorer page

    2. Select Produced API, SERVICE_NAME, where SERVICE_NAME is the name of the Endpoints service.

See the Endpoints logs reference for details on the structure of the logs in the Logs Explorer.

Learn what else you can do with the logs:

  • Get started using the Logs Explorer.

    Build queries to specify the set of log entries that you want to view, such as getting all requests with a latency greater than 300 milliseconds.

  • Configure and manage sinks to route your logs to supported destinations This lets you stream logs to BigQuery for further analysis, save the raw logs to Cloud Storage, or send them to Pub/Sub messaging topics.

Filter for a specific consumer project

To see metrics for a specific consumer project, your API consumers must send an API key when making a request. Because Endpoints uses the API key to identify the project that the calling application is associated with, the API key must have been created in the API consumer's Google Cloud project. To learn how to restrict access to your API by using an API key, see the following:

To filter metrics for a specific consumer project:

  1. Get the project number of the API consumer's project. If you don't have permission to access the API consumer's project, ask someone who has permission to get the project number for you.

  2. In the Google Cloud console, go to the Endpoints > Services page for your project.

    Go to the Endpoints Services page

  3. In the top-left corner of the Overview page, enter the project number in the Filter by Project Number field.

  4. Click Filter.

The metrics on the page update to reflect traffic only from the specified project.

Alerting

Metrics collected by Endpoints are also available in Cloud Monitoring. You can use Monitoring to set up alerting on latency, traffic, and errors. The only golden signal that you cannot set up an alert for using Endpoints metrics is saturation. The metrics that you need to monitor for saturation depend on your application. See the list of metrics available in Cloud Monitoring for metrics that you can use to set up alerting on saturation.

To set up alerting:

  1. In the Google Cloud console, select the Google Cloud project with your Endpoints monitored API which is associated with the account.

    Go to Google Cloud console

  2. By using the navigation pane, select Monitoring.

  3. Create an alerting policy to set up alerts for the golden signals by using the following:

    • Latency

      1. For Condition Type, enter Metric Threshold.
      2. For Resource Type, enter Produced API.
      3. For the metric, enter Request latencies.
      4. Enter the threshold you want to alert on and follow the rest of the Alerts guide.
    • Traffic

      1. For Condition Type, enter Metric Threshold.
      2. For Resource Type, enter Produced API.
      3. For the metric, enter Request count.
      4. Enter the threshold you want to alert on and follow the rest of the Alerts guide.
    • Errors

      1. For Condition Type, enter Metric Threshold.
      2. For Resource Type, enter Produced API.
      3. For the metric, enter Request count.
      4. For response-code-class, enter 5xx.
      5. Enter the threshold you want to alert on and follow the rest of the Alerts guide.

What's next