Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Ops agent features
2.1.
Logging features include
2.1.1.
Monitoring features include
2.2.
Agent access requirements
3.
Installing Ops Agent on Individual VMs
3.1.
Installing the latest version of the agent
3.2.
Installing a specific version of the agent
3.3.
Upgrade the agent
3.4.
Uninstall the agent
4.
Managing Agent policies 
4.1.
Creating an Agent Policy
4.2.
Limitations
4.3.
Troubleshooting
4.3.1.
The ops-agent policy commands fail
4.3.2.
The policy is created but has no effect.
4.3.3.
The OS Config agent is installed, but Ops agents aren't
5.
Managing the agents using automation tools
5.1.
Ansible
5.2.
Chef
5.3.
Puppet
5.4.
Terraform
5.5.
Agent Policy using gcloud CLI
6.
Frequently Asked Questions
6.1.
Name two Linux operating systems that the agents support.
6.2.
Does the RHEL 6 operating system support monitoring agents?
6.3.
Mention any one use of the OS Config agent's log.
7.
Conclusion
Last Updated: Mar 27, 2024

Overview of Ops Agent

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Ops agent acts as the primary agent for collecting telemetry from the user's compute engine instances. It combines logging and metrics into a single agent. It uses Fluent Bit for logs that support high-throughput logging and OpenTelemtery Collector for metrics. It can also be used for supporting the parsing of log files from third-party applications.

Ops agent features

Following are some of the features of Ops agent:

Logging features include

  • Standard system logs
  • Custom logs files
  • JSON files
  • Plain text logs
  • Regex-based parsing
  • JSON-based parsing
  • Efficient resource management


Monitoring features include

  • System metrics without setup
  • Things included with metrics
    • Cpu metrics
    • Disk metrics
    • iis metrics
    • Interface metrics
    • Memory metrics
    • Swap metrics
    • Network metrics
    • Internal agent metrics like api_request_count, memory_usage, point_count, uptime

Agent access requirements

Access to the below-mentioned DNS name is required for installing the agent

  • Google Cloud package repository, which is available at packages.cloud.google.com


The following DNS names are required for running the agent


The following ports must be open on the machine to run the agent

  • 20201
  • 20202
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Installing Ops Agent on Individual VMs

Let's discuss the installation steps of Ops Agent:

Installing the latest version of the agent

  • Using SSH or a similar tool, open a terminal connection to your VM instance. You must ensure that you have sudo access.
  • Shift to a directory to which you have write access to.
  • To run, use the below command
curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
sudo bash add-google-cloud-ops-agent-repo.sh --also-install

Installing a specific version of the agent

  • Using SSH or a similar tool, open a terminal connection to your VM instance. You must ensure that you have sudo access.
  • Shift to a directory to which you have write access to.
Using the below command, download the agent installation script
curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
  • Install the agent and its package repository
  • To pin to a major version for production environments, use the below command:
sudo bash add-google-cloud-ops-agent-repo.sh --also-install \
  --version=MAJOR_VERSION.*.*
  • In order to install a specific version of the agent, use the below command:
sudo bash add-google-cloud-ops-agent-repo.sh --also-install \
  --version=MAJOR_VERSION.MINOR_VERSION.PATCH_VERSION

Upgrade the agent

  • If you wish to upgrade to the latest version of the agent, use the below command:
sudo bash add-google-cloud-ops-agent-repo.sh --also-install
  • If you wish to upgrade the agent to the latest point release of a specific version, use the below command:
sudo bash add-google-cloud-ops-agent-repo.sh --also-install \
  --version=MAJOR_VERSION.*.*

Uninstall the agent

The following command can be used to remove the ops agent and its related configuration files. The google cloud console might take up to an hour to report the changes

sudo bash add-google-cloud-ops-agent-repo.sh --uninstall

Managing Agent policies 

Agent policies have given the option to automate the installation and maintenance of the Google Cloud's operation suite agents across a fleet of VMs that matches the user's specified criteria. It allows the user to create a policy for their Google cloud project using just one command. The policy can govern existing or new VMs associated with that particular cloud project, ensuring proper installation and optional auto-upgrade of all the agents. 

Creating an Agent Policy

If you wish to create an agent policy using the Google Cloud CLI, follow the below steps:

  • Install the Google cloud cli. 
  • If not installed, install the beta component of the gcloud CLI:
gcloud components install beta
  • If you want to check the beta component for the installed, use the following command:
gcloud components list
  • In order to enable the APIs and to set the proper permissions use the following command: set-permissions.sh
  • To create a policy, use the command:
gcloud beta compute instances ops-agents policies create

Limitations

An additional setup is required to ensure the OS config agent that the policy on which it relies is installed on the VMs for a policy to take effect on VMs that predate OS config. If you wish to install the OS config agent on a fleet on VMs, follow the below steps:

  • The user must ensure that the set-permissions.sh script has been run in the Creating an agent policy section.
  • Choose all the VMs on which you want to install the OS config agent and list them in a CSV file. In order to get a list of all the other non Google-managed instances into a csv, run the following command:
gcloud compute instances list \
      --filter="-labels.list(show="keys"):goog-" \
      --format="csv(name,zone)" \
      | grep -v -x -F -f <(gcloud compute instances os-inventory list-instances \
          --format="csv(name,zone)") \
      | sed 's/$/,update/' > instances.csv


VMs that have an already installed and enabled OS config agent is filtered using the grep section. The goog- filters out compute engine VMs which are managed by GKE, App Engine, etc.

To filter the instances further based on zones or labels, change the –filter to:

"-labels.list(show="keys"):goog- AND zone:(ZONE_1,ZONE_2) AND labels.KEY_1:VALUE_1 AND labels.KEY_2=VALUE_2"

Troubleshooting

The ops-agent policy commands fail

In case the ops-agent policy commands fail, a corresponding validation error will appear. The errors can be corrected by fixing the command arguments and flags as suggested by the error message.

The following error can also appear:

  • Insufficient IAM permission

The user should ensure that the set-permissions.sh script has been run in the Creating an Agent Policy section for setting up the osconfig.guestPolicy specific IAM role.

  • Osconfig API is not enabled

The user must ensure that the set-permissions.sh script has been run in the Creating an Agent Policy section to grant/allow all the necessary permissions. 

To check if OS config API is enabled or not for the project, use the below command

gcloud services list --project project-id \
    | grep osconfig.googleapis.com
The output should be like this:
osconfig.googleapis.com Cloud OS Config API


The policy is created but has no effect.

To manage the packages for the Logging and Monitoring agents, OS Config agents are deployed to each Compute Engine instance. If the underlying OS Config agent is not installed, then the policy may seem to have no effect.

To check that the OS Config agent is installed, use the below command

gcloud compute ssh instance-id \
    --project project-id \
    -- sudo systemctl status google-osconfig-agent


The OS Config agent is installed, but Ops agents aren't

The OS Config agent's log can be used to check if there is any error when the OS Config agent applies the policies. This can be done both ways, either via Logs explorer or SSH into individual compute engine instances.

Use the below filter to view the OS Config agent logs in Logs Explorer

resource.type="gce_instance"
logName="projects/project-id/logs/OSConfigAgent"
To view the OS Config agent logs via SSH for Ubuntu
gcloud compute ssh instance-id \
    --project project-id \
    -- sudo cat /var/log/syslog \
      | grep "OSConfigAgent\|google-fluentd\|stackdriver-agent"

To view the OS Config agent logs via RDP for individual Compute engine windows instances, follow the below steps:

  • Login to windows after connecting to your instance using the RDP or any other similar tool
  • Search for logs with Source equal to OSConfigAgent after opening the Event Viewer app under the Windows logs -> Application

To verify if the OS Config metadata is enabled or not, use the below command

gcloud compute project-info describe \
    --project project-id \
    | grep "enable-osconfig\|enable-guest-attributes" -A 1
The output will look like this:
- key: enable-guest-attributes
  value: 'TRUE'
- key: enable-osconfig
  value: 'TRUE'

 Recommended Topic, Types of Agents in Artificial Intelligence.

Managing the agents using automation tools

Several ways are provided by the Google Cloud's operations suite to manage the Ops agent across your fleet of Compute engine Linux Vms:

Ansible

It can be used to install and configure the agent across your fleet of Linux VMs.

Chef

The chefbook can be used to install and configure the agent across your fleet of Linux VMs. It must be noted that for Windows VMs only the Ops agent is supported.

Puppet

The puppet module can be used to install and configure the agent across your fleet of Linux VMs. It must be noted that for Windows VMs only the Ops agent is supported.

Terraform

The Terraform module can be used to install and configure the agent on VMs with supported operating systems.

Agent Policy using gcloud CLI

The Google Cloud CLI can be used to create an agent policy that can govern new as well as existing VMs with supported operating systems, ensuring proper installation and optional auto-upgrade of all agents.

Frequently Asked Questions

Name two Linux operating systems that the agents support.

Rocky Linus 8 and CentOS7 are two of the many Linux operating systems supported by the agents.

Does the RHEL 6 operating system support monitoring agents?

No, monitoring agents aren't supported by the RHEL 6 operating system.

Mention any one use of the OS Config agent's log.

The OS Config agent's logs can be used to check if there are any errors when the OS Config agent applies policies.

Conclusion

In this article, we have extensively discussed the Overview of the Ops Agent.

After reading about Overview of the Ops Agent, are you not feeling excited to read/explore more articles on Google Cloud? Don't worry; Coding Ninjas has you covered. To learn about GCP certification: Google Cloud Platform, the difference between AWS, Azure & Google Cloud, and which platform is best: AWS vs. Google Cloud.

If you wish to enhance your skills in Data Structures and AlgorithmsCompetitive ProgrammingJavaScript, etc., you should check out our Guided path column at Coding Ninjas Studio. We at Coding Ninjas Studio organize many contests in which you can participate. You can also prepare for the contests and test your coding skills by giving the mock test series available. In case you have just started the learning process, and your dream is to crack major tech giants like Amazon, Microsoft, etc., then you should check out the most frequently asked problems and the interview experiences of your seniors that will surely help you in landing a job in your dream company. 

Do upvote if you find the blogs helpful.

Happy Learning!
 

Previous article
Advanced concepts of metrics in cloud monitoring
Next article
Managing Ops Agent
Live masterclass