Category Archives: Google cloud

Freely Monitoring your Servers with Google Chat App Notifications

Monitoring:

Monitoring is considered one of the most important process in today’s world of Technology. Most Datacenters have their private monitoring systems with automation tools that would trigger failover, or Disaster Recovery in case of downtime being noticed and this is extremely costly operation.

What to Monitor?

CPU Usage, Memory Consumption, I/O, Network, Disk Usage, Process etc. Server Monitoring also helps in capacity planning by understanding the server’s system resource usage.

Other services can be monitored like Web Servers, FTP, Mail Servers or anything else if it’s publicly accessible.

Using UPTimeRobot Monitoring

image

Uptime Robot Monitoring is a free-commercial service that has rich monitoring features where you can monitor your services/servers on 1 minute interval and get alerted by Email, SMS, Phone Apps e.g. (Telegram, Google Chat, or Skype).

The Free version

In the free version Monitoring you can add services based on ports and protocols or Servers. This might look limited to some but since it’s free of charge it can be very useful for small or startup companies with couple of servers.

– Limited up to 50 Monitors.

– No SMS.

– Check interval is 5 mins.

– Logs are not kept

The Commercial Version:

image

In the commercial version you pay a small fee of 4.5$ a month, an you’d get the following:

– Up to 50 Monitors.

– 20 SMS.

– Check interval is 1 mins.

– Logs are kept for 2 years.

Adding a Server to Monitor:

After you create an account on UpTimeRobot.com you can easy add a site or a service to monitor right away and the monitoring will initiate after 5 minutes then it’ll report if the service,server you added is up or down.

Click on + Add New Monitor

image

Next add the website, In my case i’ll add my own website and see how it works and then choose Google Chat (Since I already have the integration on).

image

Once ready, click on create monitor

That should add the website directly into the List of monitored services:

image

If you click on the Monitor, you’ll get the stat figure of how long has your website been on/off

image

After waiting roughly 35 mins, I can see now that my website is up and running without any problem. The monitoring probe counts by milliseconds so you’ll be able to see if there’s any interruption in the connection to your website/server.

image

Integration with Google Chat

Requirements:

  • Google Suit.
  • Google Admin Account
  • Create a Google Chat Room
  • Configure WebHooks

The integration between Google chat and UpTimeRobot requires Google G Suits account

I will login to my G account with admin user

image

image

Next go to Chat admin console

Login with your admin account to google admin Console and then go to this link

https://chat.google.com/u/1/

image

Create a room, Call it UpTimeRobot

image

image

Once Created, Click on the … dots next to Now

image

Now Configure WebHooks

image

Call this UpTimeRobotContact and save

image

This should create a URL for you, Something that looks like this! This

https://chat.googleapis.com/v1/spaces/AAAAcUvSsqs/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=qSlBYydgUj2mqqC8o_DIDY_RqcMaiI%3D

image

Adding Members (To get notifications)

On the right side Add People and Bots

image

Add a user to receive notifications once any server or service is down.

image

Once you add a user, you’ll notice that the admin user’s notification below saying he/she added a user to the Room.

image

Uptime Robot Configuration:

In order for this to work we’ll have to finish the work on the UpTimeRobot portal

Inside Uptime Robot, create a new alert contact in My Settings>Alert Contacts>Add new>Google Hangouts Chat using the previously created Hangouts Chat web-hook URL.

image

image

image

When we choose the Google Hangouts Chat, We will have to give the following:

  • Friendly name for the monitor.
  • Provide the webhook URL which was created previously.
  • You can add a custom message to identify something related to the monitoring.
  • Enable notifications for, You can choose to get notifications only when the site/service is up or down or both.

image

image

After adding this, You need to download one or two apps to get alerts to your Cell Phone:

  • Google Chat
  • UPtime Robot

image

What do Alerts Look like?

As soon as your system goes down, Google Chat will sends you a push notification to your phone, if you’re using UpTime Robot and you’re logged in to the account then you’ll get another identical notification at the same time indicating your system’s status if it goes down or back up.

image

Like this you can add up to 50 monitors including all kinds of services, ports, protocols.

The notification also comes with an interesting tone so you could easily tell if the sound is for “System Down” or “System is up” kind of state.

This has personally helped me keep my system up 24/7 and interfere whenever there’s any downtime noticed.

I hope this article helps and in case you have any question please leave a comment or get in touch with me info@moh10ly.com

References:

https://blog.uptimerobot.com/new-feature-google-hangouts-chat-notifications/

https://chat.google.com/u/1/

Download VM (VHD) from Azure and uploading it to Google cloud and get it working..

In order to Download an Azure Virtual machine and make it possible to upload it and get it to work on Google cloud, I am going to export a working virtual machine with Ubuntu 15.4 server version on it with WordPress installed and functioning.

First I’ll have to have Azure PowerShell installed on my Windows PC before starting, If you don’t have it you can download it from the following link below.

1: Download the VHD from Azure.

First i’ll install Azure model from the following link

http://go.microsoft.com/fwlink/p/?linkid=320376&clcid=0x409

Launch the azure PowerShell as an administrator use the following cmdlet which will launch an Internet page that will direct you to login to your azure subscription to download a setting file.

Get-AzurePublishSettingsFile

clip_image001

The page will look like this and should automatically download the file to your Download folder…

 

Then when the file is downloaded, Navigate to the download folder and import the subscription using the following cmdlet

Import-AzurePublishSettingsFile ‘.\Visual Studio Premium with MSDN-10-9-2015-credentials.publishsettings’

Now I will get my Virtual machine’s storage blob link from the Azure portal, I’ll press on the arrow next to the VM’s name

clip_image004

I’ll click on Dashboard

clip_image005

Then scroll down to Disks

clip_image006

I’ll hover the mouse over the VHD link and copy it

clip_image007

clip_image008

Here’s my machine’s link

https://strlync01.blob.core.windows.net/vhds/moh10ly-Ubunut-Mohammed-2015-07-04.vhd

In a script like this I’ll add it as a source

$sourceVHD = “https://strlync01.blob.core.windows.net/vhds/moh10ly-Ubunut-Mohammed-2015-07-04.vhd

Then configure the destination which is going to be a path to my F root disk

$destinationVHD = “F:\ubuntu-downloaded.vhd”

Next I’ll start downloading with the following command

Save-AzureVhd -Source $sourceVHD -LocalFilePath $destinationVHD

clip_image009

Here the download has already started

clip_image010

clip_image011

2: Convert AZURE VM from VHD to RAW

Once the file downloading is finished, I’ll have to install VirtualBox from the following Link (it works on Windows 10 as well) and it’s needed as it has conversion tool.

http://download.virtualbox.org/virtualbox/5.0.2/VirtualBox-5.0.2-102096-Win.exe

I’ll install Oracle Virtual Box to the default installation path.

clip_image012

Next I’ll download the following tool VBOXHDTOOLS from the following link and install it.. (It uses UI instead of command line for the conversion)

http://sourceforge.net/projects/vboxhdtools/

clip_image013

Now to convert the machine from VHD To the extension that fits to Google cloud (RAW) I’ll have to run the VBOXHDBOX tool as an administrator

The tool comes normally in Spanish language, so I’ll transfer it to English

Click on Archivo – Confuracion – > Idioma -> English

clip_image014

Now I will choose the source VHD that I want to convert and the destination file and the type “RAW”

clip_image015

Once you click Clone, the conversion will start but will take some time depending on the size of the VM and the speed of your Disk (SATA or SSD)

clip_image016

When the conversion has finished and the RAW file is ready, we’ll have to do the following steps which is also documented In the below Google Link on how to import a virtualbox image

clip_image017

3: Import a VirtualBox image

From <https://cloud.google.com/compute/docs/images?hl=en#export_an_image_to_google_cloud_storage>

STEP:1 I’ll have to Download, install, and authenticate the Google Cloud SDK:

Since I am running a Windows machine then I won’t be able to use some commands in the document by google like Curl and Tar ..etc so I’ll have to download the Google cloud SDK from the following link and install it first…

https://cloud.google.com/sdk/

clip_image018

I’ll install python as well which is required for the Gcloud SDK

clip_image019

Once the installation is finished I’ll let it run the Google SDK shell

clip_image020

clip_image021

Second Step : Authenticate

I’ll login and authenticate my Google cloud account (trial account)

The moment you enter this command (gcloud auth login) in Google cloud SDK shell the browser will launch google chrome and ask for authentication from your google account.

So i will go ahead and type the following to authenticate, as soon as you press enter the default browser will launch and redirect your page to google authentication to setup your gcloud trial and get your authentication approval. 

> gcloud auth login

clip_image022

clip_image023

I’ll let it authenticate and continue

clip_image024

As you can see below we have been authenticated now and next we’ll be choosing the project (Like subscription in Azure).

clip_image025

Once authenticated, I’ll choose the project in my google cloud account which I want to export the VM to.

Third step : Selecting a Project 

I have 3 projects created there but I’ll chose one of them only (moh10ly)

I’ll have to use the following CMD to choose the project

gcloud config set project PROJECT

If you don’t know your Project name or you don’t have a project, you can do so from the google cloud console

https://console.developers.google.com

clip_image026

I’ll set the project now

> gcloud config set project as moh10ly

clip_image027

Fourth Step: Creating a storage Bucket

Now I’ll need to create a new storage bucket (storage account) where I will upload the VM to

To create new Google cloud Bucket (Storage) called moh10lybucket I’ll use the following cmd

> Gsutil mb gs://moh10lybucket

clip_image028

You can see if the bucket was created by navigating to your project’s Storage -> Cloud Storage -> Browser window

clip_image029

Now I’ll have to compress the RAW Virtual machine to TAR extension which is a must since Google doesn’t accept any other format and in order for it to be uploaded to Google Cloud Bucket that I have created.

Since TAR is a linux based tool then I will download and install CYGWIN tool to compress the machine according to the google’s documentation

To download Cygwin and install it on Windows use this link

https://www.cygwin.com/setup-x86_64.exe (This works also on Windows 10)

clip_image030

After downloading and installing the tool, I will have to copy the disk.raw to a location where I can easily access it in Cygwin to compress it

$ tar -Sczf vbox-image.tar.gz disk.raw

clip_image031

When you install Cygwin, it gives you the option to choose the installation path which is by default C:\ root directory, however I have chosen a different path for this program which is F:\ root in my case

clip_image032

So in order to access the Disk.raw file I’ll copy the file to F:\cygwin64\home

Once the file is copied there, you can launch Cygwin as an administrator and you can view the directory by typing (LS) command and enter

$ LS  (the LS should be small letters)

clip_image033

If the file is not there, then you must look in the newly created folder which is typically your Window’s User profile name and copy the file again there too.

Once the file is copied and you have access to it via the Terminal then you can start and compress the file to TAR as in the below screenshots.

The command is tar -Sczf vbox-image.tar.gz disk.raw

clip_image031[1]

When the compressing has finished, you will be able to see that the file is there and has its size decreased to 605 MB

clip_image034

Now since the file is ready to be uploaded, I will launch the Google SDK terminal and navigate to the path where the file is located (Or simply copy it to an easier location e.g. C:\) and upload the file to google cloud bucket using the following command line

> Gsutil cp vbox-image.tar.gz gs://moh10lybucket

What the command does is it actually copies the file with the command CP to the cloud storage which is gs://moh10lybucket (Make sure your google sdk terminal is already authenticated to your google cloud account).

clip_image035

Below the file started to upload … it took around 15 minutes for the upload to finish

clip_image036

Now I’ll have to import the file into the images store in order for it to be used from the google cloud bucket

Importing the fıle after uploading

I’ll use the following command

> Gcloud compute images create vbox-ubuntu –source-uri gs://moh10lybucket/vbox-image.tar.gz

clip_image037

Check in google images in google cloud if the image is imported and it is .. First image imported as in the below snapshot

clip_image038

Now I will deploy it as a VM and see if it works!

It did get imported and it works, You can access the ip below to see if my website is active or not!

clip_image039

Hope this was helpful.