Welcome Guest.   Make a donation to an author on the site November 27, 2014, 11:43:10 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Your Support Funds this Site: View the Supporter Yearbook.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Using Skype to Monitor Remote Systems  (Read 6531 times)
timns
Supporting Member
**
Posts: 1,209



Veni, vidi, debuggi

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« on: March 06, 2011, 09:58:59 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.



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.



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.



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)
Formatted for Delphi with the GeSHI Syntax Highlighter [copy or print]
  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:
Formatted for Delphi with the GeSHI Syntax Highlighter [copy or print]
  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:
Formatted for Delphi with the GeSHI Syntax Highlighter [copy or print]
  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:
Formatted for Generic Code with the GeSHI Syntax Highlighter [copy or print]
  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.
Logged

cranioscopical
Friend of the Site
Supporting Member
**
Posts: 4,196



see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: March 06, 2011, 10:10:25 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.
Logged

Chris
timns
Supporting Member
**
Posts: 1,209



Veni, vidi, debuggi

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #2 on: March 06, 2011, 10:28:11 AM »

Thank you Chris.

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

mouser
First Author
Administrator
*****
Posts: 33,702



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: March 06, 2011, 10:34:21 AM »

Cool stuff, i didn't realize how easy it was to interface code to skype.. makes one think of other program ideas..
Logged
DeVamp
Supporting Member
**
Posts: 103



Let the coding begin :-)

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #4 on: March 06, 2011, 03:47:22 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. :-)
Logged
timns
Supporting Member
**
Posts: 1,209



Veni, vidi, debuggi

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #5 on: March 06, 2011, 04:04:17 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.
Logged

lotusrootstarch
Member
**
Posts: 160



People reckon I'll smash into Cody someday.

View Profile Give some DonationCredits to this forum member
« Reply #6 on: March 06, 2011, 10:45:14 PM »

Great tutorial. It's indeed a genius poor-man solution.  Thmbsup
Logged

Get my apps in Android Market! Go droids go! smiley

timns
Supporting Member
**
Posts: 1,209



Veni, vidi, debuggi

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #7 on: March 07, 2011, 09:30:27 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.
Logged

JonBoy
Supporting Member
**
Posts: 6

View Profile Give some DonationCredits to this forum member
« Reply #8 on: March 29, 2011, 03:19:22 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.com/a...s/internet/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!
Logged
ddns
Participant
*
Posts: 4

View Profile Give some DonationCredits to this forum member
« Reply #9 on: June 28, 2011, 02:10:02 AM »

Damm.  That is some impressive work - thanks for the excellent write-up.  Skype scripting and I do not get along.
Logged
IainB
Supporting Member
**
Posts: 4,878


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #10 on: June 28, 2011, 08:30:51 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.
Logged
mashmata
Participant
*
Posts: 9


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #11 on: June 28, 2011, 08:58:31 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...smiley
Logged

Remember: Don't Insult the Alligator till after you cross the river.
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.102s | Server load: 0.08 ]