# View metrics and quotas

## Viewing metrics in the console

You can [view your Cloud Run functions](https://console.cloud.google.com/functions/list)
with their execution times, execution counts, and memory usage in the
Google Cloud console. These metrics are also available in
[Cloud Monitoring](https://console.cloud.google.com/monitoring),
where you can set up custom alerting on these metrics. See the
[Cloud Monitoring documentation](https://docs.cloud.google.com/monitoring/docs.md.txt) for more information.

You can view the metrics for API calls in the
[API overview page](https://console.cloud.google.com/apis/api/cloudfunctions.googleapis.com/overview)
of the Google Cloud console.

Finally, you can view the quota metrics for both API calls and function
execution in the [API quotas page](https://console.cloud.google.com/apis/api/cloudfunctions.googleapis.com/quotas)
of the Google Cloud console. You can set up alerting on quota errors in
[Cloud Monitoring](https://console.cloud.google.com/monitoring)
by filtering executions that have an `out of quota`
value for the `STATUS` metric label. See [Introduction to Alerting](https://docs.cloud.google.com/monitoring/alerts.md.txt)
for more information.

## Reading metrics programmatically

The following snippet illustrates how you can also read metrics from your code.

### Node.js

```javascript
// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');

// Creates a client
const client = new monitoring.MetricServiceClient();

async function readTimeSeriesData() {
  /**
   * TODO(developer): Uncomment and edit the following lines of code.
   */
  // const projectId = 'YOUR_PROJECT_ID';
  // const filter = 'metric.type="compute.googleapis.com/instance/cpu/utilization"';

  const request = {
    name: client.projectPath(projectId),
    filter: filter,
    interval: {
      startTime: {
        // Limit results to the last 20 minutes
        seconds: Date.now() / 1000 - 60 * 20,
      },
      endTime: {
        seconds: Date.now() / 1000,
      },
    },
  };

  // Writes time series data
  const [timeSeries] = await client.listTimeSeries(request);
  timeSeries.forEach(data => {
    console.log(`${data.metric.labels.instance_name}:`);
    data.points.forEach(point => {
      console.log(JSON.stringify(point.value));
    });
  });
}
readTimeSeriesData();
```