## Overview

This template is designed to monitor Google Cloud Platform (hereinafter - GCP) by Zabbix.
It works without any external scripts and uses the script item.
The template currently supports the discovery of [Compute Engine](https://cloud.google.com/compute)/[Cloud SQL](https://cloud.google.com/sql) instances and Compute Engine project quota metrics.


## Setup

1. Enable the `Stackdriver Monitoring API` for the GCP project you wish to monitor.
>Refer to the [vendor documentation](https://cloud.google.com/monitoring/api/enable-api).
2. Create a service account in Google Cloud console for the project you have to monitor.
>Refer to the [vendor documentation](https://cloud.google.com/iam/docs/creating-managing-service-accounts).
3. Create and download the service account key in JSON format.
>Refer to the [vendor documentation](https://cloud.google.com/iam/docs/creating-managing-service-account-keys).
4. If you want to monitor Cloud SQL services - don't forget to activate the Cloud SQL Admin API.
>Refer to the [vendor documentation](https://cloud.google.com/sql/docs/mysql/admin-api) for the details.
5. Copy the `project_id`, `private_key_id`, `private_key`, `client_email` from the JSON key file and add them to their corresponding macros `GCP project ID`, `Private key id`, `Private key data`, `Client e-mail` in host wizard configuration fields.

**Additional information**:

    Make sure that you're creating the service account using the credentials with the `Project Owner/Project IAM Admin/service account Admin` role.

    The service account JSON key file can only be downloaded once: regenerate it if the previous key has been lost.

    The service account should have `Project Viewer` permissions or granular permissions for the GCP Compute Engine API/GCP Cloud SQL.

    You can copy and paste private_key string data from the Service Account JSON key file as is or replace the new line metasymbol (\n) with an actual new line.

>Please, refer to the [vendor documentation](https://cloud.google.com/iam/docs/manage-access-service-accounts) about the service accounts management.

**IMPORTANT!!!**

     Secret authorization token is defined as a plain text in host prototype settings by default due to Zabbix templates export/import limits: therefore, it is highly recommended to change the user macro `{$GCP.AUTH.TOKEN}` value type to `SECRET` for all host prototypes after the template `GCP by HTTP` import.

     All the instances/quotas/metrics discovered are related to a particular GCP project.
     To monitor several GCP projects - create their corresponding service accounts/Zabbix hosts.

     GCP Access Token is available for 1 hour (3600 seconds) after the generation request.

     To avoid a GCP token inconsistency between Zabbix database and Zabbix server configuration cache, don't set Zabbix server configuration parameter CacheUpdateFrequency to a value over 45 minutes and don't set the update interval for the GCP Authorization item to more than 1 hour (maximum CacheUpdateFrequency value).

Additional information about metrics and used API methods:

  [Compute Engine](https://cloud.google.com/monitoring/api/metrics_gcp#gcp-compute)

  [Cloud SQL](https://cloud.google.com/monitoring/api/metrics_gcp#gcp-cloudsql)