topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Monday December 2, 2024, 5:44 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Using Skype to Monitor Remote Systems  (Read 18282 times)

timns

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,211
    • View Profile
    • Donate to Member
Using Skype to Monitor Remote Systems
« on: March 06, 2011, 09:58 AM »
Background

One of the options my company offers is SaaS  to companies who need a plug-in to help with their logistics operations. We provide a little network of servers that host several web services with various API's. Obviously, as part of this we have to offer support and are committed to fairly aggressive SLA's.

In order to help with this, I decided to implement a continual monitoring system to alert us of any systems falling over in our little farm. Being on a limited budget and an inveterate code tinkerer, I set up a little project to see if I could rustle something up. As far as I am aware, this is a novel approach to real-time systems monitoring. A sort of "poor man's Tivoli" if you like.

Approach

I have set up each machine in our cluster to monitor two others. I've found this to be the optimal arrangement. If we lose a node, we get a maximum of two other servers alerting us to the fact. Even multiple node failures will always ensure a manageable quantity of alert messages instead of being swamped.

WhoToWho.pngUsing Skype to Monitor Remote Systems

So what happens is that every minute, each machine asks its partner machines their status. This is achieved by a small self-written program installed as a Windows service. Every 60 seconds it wakes up and executes a simple call to each web service that it knows about. Depending on the result of this call, the software performs various logging operations and takes further actions if required.

In my case, our webservices will respond to the equivalent of a ping request, returning a brief status message.

One of three things can happen:

- no response: panic in the streets!
- bad response: check as soon as possible
- good response: back to sipping coffee

This diagram exemplifies the steps taken.

NetworkMonitor.pngUsing Skype to Monitor Remote Systems

I decided to keep it very simple: if we bump into an issue, the event is logged so we can trace back when things began to go wrong. But also, if there is an important state change, several of us on the support team are instantly notified by a Skype instant message right to our desktops. Our monitoring app can also dial out via Skype to whoever is on call.

And this is the part that I believe is quite unique. I utilised the Skype API so that we could use it to send messages to anyone who was currently interested in the status of our servers, without them having to be logged in. Or even have any type of account on the boxes. This means we can safely include end-users if they are interested in collating their own uptime stats.

SampleMessage.pngUsing Skype to Monitor Remote Systems

So after installing skype on our servers, all I had to do was write a little bit of code. This was almost pathetically easy: the entire monitoring application is perhaps 300 lines of Delphi code. Skype provides an API with some easy examples to show you how to hook in. Every 60 seconds the program awakens and firstly pings each node on its list. If successful it then makes a status enquiry to the web services themselves.

Code fragment from the app's OnCreate method: (constructor)
Code: Delphi [Select]
  1. Skype := TSkype.Create(self);
  2.     Skype.OnMessageStatus := SkypeMessageStatus;
  3.     try
  4.       Skype.Attach(8, False);
  5.       SendMessage('Bxxxxx Monitor started');
  6.     except
  7.       on e: Exception do begin
  8.         HandleException(e);
  9.       end;
  10.     end;

Code fragment showing how easy it is to send an IM:
Code: Delphi [Select]
  1. if Skype.AttachmentStatus <> 0 then
  2.   begin
  3.     try
  4.       Skype.Attach(8, false);
  5.     Skype.SendMessage(SkypeContacts, message);
  6.   except
  7.      on e: Exception do begin
  8.        HandleException(e);
  9.      end;
  10.   end;

... and to handle incoming messages:
Code: Delphi [Select]
  1. procedure TMainForm.SkypeMessageStatus(Sender: TObject;
  2.   const pMessage: IChatMessage;
  3.   Status: TChatMessageStatus);
  4. begin
  5.   case Status of
  6.     cmsReceived: Logger.Log('Recv ' + pMessage.FromHandle + ': ' + pMessage.Body);
  7.     cmsSent: Logger.Log('Sent ' + pMessage.Chat.DialogPartner + ': ' + pMessage.Body); // handle multiple partners

As you can see, what's really nice is that I can now write entries into any server's log file from my desktop, simply by sending an IM from my skype account to the destination server! We use this facility to annotate various activities and it provides a useful audit trail.

Sample from our log file:
Code: Text [Select]
  1. 9/25/2010 1:36:22 PM-I-Sent Timxxxxx: WARNING: Bxxxxx DOWN on node xxx.xxx.xxx.xxx
  2. 9/25/2010 1:36:22 PM-I-Recv Timxxxxx: Ok, I got this one
  3. 9/25/2010 1:36:25 PM-I-Sent Txxxxx: INFORMATION: Bxxxxx UP on node xxx.xxx.xxx.xxx
  4. 9/25/2010 1:36:27 PM-I-Recv Timxxxxx: Ping timeout. I blame the ISP ;)

Of course at this point you are saying to yourself "how do you keep skype running when you are not even logged into the servers?" and it's a good question. In order to keep skype running, and have it survive reboots without a re-login, I set up the program as a Windows service. To achieve this, I used the excellent XYNTservice program

In conclusion I believe this approach is very useful for small and budget conscious businesses who need some automated way to keep an eye on the health of their services. I've been using this technique for 9 months now and it has proven to be very reliable, and so far we have not missed a single occurence of downtime.

Summary of advantages
  • It is a lightweight, free solution
  • It has proven to be very stable
  • You get an instant message and/or a call immediately any problem is detected
  • You and your team can subscribe or unsubscribe to any of the servers contact lists in order to switch yourselves in and out of support (we use block/unblock)
  • It requires minimal development and configuration
  • The paradigm is scalable

Disadvantages
  • You have to have skype running. Personally I rely on skype a great deal, and encourage our userbase to contact us via skype for low-priority support.
  • If Skype goes down, as it famously did in early January 2011, you will have to find an alternative way to check your systems
  • I would not call it an Enterprise solution

If you're at all interested in more information just give me a shout. I would be happy to show you an instance of the system in action on a test server, and/or help you set up something similar for yourself.

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #1 on: March 06, 2011, 10:10 AM »
Very nice.

A good, inventive system, explained in a succinct way that even I could understand!

Thanks for sharing the idea, and for a post in the 'how-to' genre. I think that posts such as this have the potential to be very informative about a lot of things.

timns

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,211
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #2 on: March 06, 2011, 10:28 AM »
Thank you Chris.

I do realise it's a rather rarefied topic but I'm hoping that it's food for thought.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,913
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #3 on: March 06, 2011, 10:34 AM »
Cool stuff, i didn't realize how easy it was to interface code to skype.. makes one think of other program ideas..

DeVamp

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 122
  • Let the coding begin :-)
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #4 on: March 06, 2011, 03:47 PM »
Wow, cool stuff you realised. :-)

Would it be possible to have the Skype DLL's on a server without really installing skype.
That way, we could create a monitoring system on servers that arn't really ours, but where we install a particulair software. :-)

timns

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,211
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #5 on: March 06, 2011, 04:04 PM »
Wow, cool stuff you realised. :-)

Would it be possible to have the Skype DLL's on a server without really installing skype.
That way, we could create a monitoring system on servers that arn't really ours, but where we install a particulair software. :-)

Thank you!

Unfortunately skype has to be running for this to work. You can launch it from within your software, but this probably means it would have to be installed on the machine in question.

lotusrootstarch

  • Member
  • Joined in 2009
  • **
  • Posts: 160
  • People reckon I'll smash into Cody someday.
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #6 on: March 06, 2011, 10:45 PM »
Great tutorial. It's indeed a genius poor-man solution.  :Thmbsup:
Get my apps in Android Market! Go droids go! :)


timns

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,211
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #7 on: March 07, 2011, 09:30 AM »
@lotusrootstarch: very nice of you to say so.

I may make some small tweaks to the system over time. If so, I'll try to update the article accordingly.

JonBoy

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #8 on: March 29, 2011, 03:19 PM »
Wow, cool stuff you realised. :-)

Would it be possible to have the Skype DLL's on a server without really installing skype.
That way, we could create a monitoring system on servers that arn't really ours, but where we install a particulair software. :-)

Thank you!

Unfortunately skype has to be running for this to work. You can launch it from within your software, but this probably means it would have to be installed on the machine in question.

If not wishing to formally install someone else's program (i.e. Skype) on a machine and mess with the registry, perhaps the portable edition of Skype could be part of the package one puts on the server:
http://portableapps....ernet/skype_portable

Haven't read through XYNTservice documentation so don't know if there's a show-stopper right there.

What an intriguing notion - very inventive!

ddns

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #9 on: June 28, 2011, 02:10 AM »
Damm.  That is some impressive work - thanks for the excellent write-up.  Skype scripting and I do not get along.

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,544
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #10 on: June 28, 2011, 08:30 AM »
@timns: This seems redolent, to some extent, of the Tandem NonStop II (circa 1985) Guardian operating system. Each of the CPUs in a system group would keep broadcasting on a fast bus to all the other CPUs in the group an "I'm alive" message every 3.5 seconds or something very precise. If a processor failed to broadcast the message within the allotted elapsed time, then it was deemed to have failed and was excommunicated from the group, with subsequent transactions being rerouted/re-queued in the system to avoid the "failed" CPU.

mashmata

  • Participant
  • Joined in 2011
  • *
  • Posts: 9
    • View Profile
    • Donate to Member
Re: Using Skype to Monitor Remote Systems
« Reply #11 on: June 28, 2011, 08:58 AM »
Cool stuff, i didn't realize how easy it was to interface code to skype.. makes one think of other program ideas..

Quite... The possibilities are quite possibly limitless...:)
Remember: Don't Insult the Alligator till after you cross the river.