How to install monitoring agent while deploying vm

169 views
Skip to first unread message

Himanshu Lande

unread,
Mar 16, 2020, 4:51:19 AM3/16/20
to gce-discussion
I want to deploy monitoring agent while deploying VM but VM gets deployed and monitoring agent doesnt get installed in the OS (windows or linux).
I am pushing this code in metadata ----- 
"cd $env:UserProfile;(New-Object Net.WebClient).DownloadFile("https://repo.stackdriver.com/windows/StackdriverMonitoring-GCM-46.exe", ".\StackdriverMonitoring-GCM-46.exe").\StackdriverMonitoring-GCM-46.exe"

-----

Still i am facing issue. How can i execute this in powershell when vm gets deployed and this code will get executed in powershell in a newly deployed VM.

Thank you.

Frederic Gervais

unread,
Mar 16, 2020, 10:11:02 AM3/16/20
to gce-discussion
Hello Himanshu,

What you can do as mentioned here [1], is to specify the script with the “windows-startup-script-ps1” metadata key. This will make it so the script will be run with PowerShell and not CMD.

Regards,

Frederic

Himanshu Lande

unread,
Mar 16, 2020, 10:59:00 AM3/16/20
to gce-discussion
Hi Frederic,

Thanks for the reply,

But i tried that but still the monitoring agent doesnt get installed.
Could you please try from your end and if its working could you please provide me the code.

Br,
Himanshu

Mary Koes

unread,
Mar 16, 2020, 11:04:31 AM3/16/20
to Himanshu Lande, Morgan McLean, gce-discussion

--
© 2018 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Compute Engine Discussion Google Group (gce-dis...@googlegroups.com) to participate in discussions with other members of the Google Compute Engine community and the Google Compute Engine Team.
---
You received this message because you are subscribed to the Google Groups "gce-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gce-discussio...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gce-discussion/7fd0daaa-38a9-4434-83ff-7f815b102f2e%40googlegroups.com.

Cameron Thomas Otway

unread,
Mar 17, 2020, 3:44:46 PM3/17/20
to gce-discussion
Hello Himanshu, 

As Frederic mentioned, configuring a startup script with the correct metadata-keys is a start in the right direction. As for the actual code, perhaps you can leverage Stack Overflow or Server Fault for the scripting side of things. Something Similar to Start-BitsTransfer "https://dl.google.com/cloudagents/windows/StackdriverLogging-v1-11.exe"   is probably what you need. 

Tomás Grover

unread,
Mar 20, 2020, 11:10:35 AM3/20/20
to gce-discussion
Hello, Himanshu.

I think this can help you.

I have tested this 2 entries against Windows instances (Win Server 2016 and 2019) and for both cases it works fine.

So when you are settting up your Windows instance use the following in the Metadata section:
Key field: sysprep-specialize-script-ps1
Value field:
Write-Host "Install Monitoring agent"
cd C:\Users\Public\Downloads\
invoke-webrequest https://repo.stackdriver.com/windows/StackdriverMonitoring-GCM-46.exe -OutFile StackdriverMonitoring-GCM-46.exe;
.\StackdriverMonitoring-GCM-46.exe  /S;

When you spin your instance this startup script in PowerShell will do the job for you.

If you are looking for the same in linux environment, I have found this (but I didn't have the time to test it).

When you are setting up your instance in the Startup Script section, you can use the following:
#! /bin/bash
sudo bash add-monitoring-agent-repo.sh

#CentOS/RHEL
sudo yum install -y stackdriver-agent
sudo service stackdriver-agent start

#Debian/Ubuntu
sudo apt-get update
sudo apt-get install stackdriver-agent -Y

#Restarting the service works for both
sudo service stackdriver-agent start


Remember to take out the part related to the OS you will be using.
This also the option to run it in a SuSe OS, you can find more in this link [1]

I hope this can help.

Regards,

[1] - https://cloud.google.com/monitoring/agent/install-agent#joint-install

Reply all
Reply to author
Forward
0 new messages