Easily Identify VMs Without Ops Agent Installed Using GCPDiag

Utkarsh Sharma
Google Cloud - Community
3 min readApr 24, 2024

Ensuring that all virtual machines (VMs) within your Google Cloud Platform (GCP) environment have the Operations (Ops) Agent installed is crucial for maintaining robust monitoring and management capabilities. However, manually checking each VM can be time-consuming and prone to errors. Fortunately, GCP provides a powerful tool called GCPDiag, which simplifies this process by automating the verification of Ops Agent installation across all GCE VMs within your project.

Introducing GCPDiag

GCPDiag is a diagnostic tool designed to identify misconfigurations, security vulnerabilities, and best practice violations within your GCP environment. Leveraging a comprehensive set of pre-defined checks, it offers a streamlined approach to ensuring compliance and optimizing your cloud infrastructure.

Verifying Ops Agent Installation

One of the critical checks implemented by GCPDiag is the verification of Ops Agent installation on all GCE VMs. This check ensures that every VM within your project has the Ops Agent installed, enabling seamless monitoring and logging. https://gcpdiag.dev/rules/gce/BP/2021_002/

Running GCPDiag in Cloud Shell

One of the standout features of GCPDiag is its seamless integration with Cloud Shell. Cloud Shell provides a convenient, browser-based command-line interface (CLI) for managing your GCP resources. By running GCPDiag in Cloud Shell, We can perform Ops Agent checks without the need for any additional installations or configurations.

Step-by-Step Guide

Here’s a quick guide on how to use GCPDiag to identify VMs without Ops Agent installed:

  1. Access Cloud Shell: Navigate to the Cloud Shell within the GCP Console.
  2. Run GCPDiag Command: Execute the following command, replacing <project name> with your project's name:

gcpdiag lint --project <project name> --include=gce/BP/2021_002

3. Review Results: GCPDiag will scan your project for GCE VMs without Ops Agent installed and provide a clear report detailing any instances that require attention.

Additionally, GCPDiag offers the flexibility to format the results into CSV or JSON. Detailed documentation on this feature is available here.

To generate the results in CSV format, simply append --output csv to the command. For example:

gcpdiag lint --project <project name> --include=gce/BP/2021_002 --output csv > gcpdiag.report.csv

This command will output the results in CSV format, making it easy to analyze and share the findings.

Note: Please be aware that we must fulfill certain pre-requisites before running the tool. Details regarding these pre-requisites can be found here.

Just a heads up: the check confirms installation by querying the Ops Agent’s uptime metrics.(see implementation) It’s akin to the process suggested in this article.

Conclusion

With GCPDiag, ensuring compliance and best practices within your GCP environment has never been easier. By leveraging its Ops Agent check functionality, you can effortlessly identify VMs lacking the necessary monitoring capabilities. Whether you’re managing a small project or a large-scale deployment, GCPDiag is a valuable tool for maintaining the integrity and security of your cloud infrastructure.

--

--

Utkarsh Sharma
Google Cloud - Community

Senior Solutions Consultant @ Google | Talks about AWS | GCP | Azure | K8s | IaC | Terraform | CI/CD | Docker| Helm | Migration