Easy monitoring of an Intersystems Cache shadow server

The other day our shadow server stopped working without any visible reason. So I was looking for an easy way to monitor the server. We are using Nagios as the monitoring solution. The problem was how to get the necessary information from the remote system and put it into Nagios. The plan was to trak the latency and the status of the shadow server. To be honest, I am not an application programmer and have no knowledge on how to write CSPs. I found a source on the internet, that explained a wee bit of how to request information in a macro. After hours of trial and error and bothering one of our developers, I finally wrote this script:

#include %occOptions
#include %occStatus
  s rs = ##class(%ResultSet).%New()
  s rs.ClassName="SYS.Shadowing.Shadow"
  s rs.QueryName = "List"
  d rs.Execute()
  while (rs.Next()) 
    s name = rs.GetData(1)
    s status = rs.GetData(2)
    s dStatus = ##class(%ShadowState).LogicalToDisplay(status)
    s host = rs.GetData(3)
    s port = rs.GetData(4)
    if (status = 1) {
      s latency = ##class(SYS.Shadowing.Shadow).GetLatency(name)
      s tLatency = ##class(SYS.Shadowing.Shadow).TranslateLatency(latency)
      w "Lat: ",tLatency,"#"
      w " ",!
      w "Stat: ",dStatus,"#"
      s tLatency = "N/A"

It returns the latency and the status in a format like the one below:
%SYS>d ^shadtest
Lat: 6 minutes#
Stat: processing#

I added the # to make it easier for me to separate the data in a bash script that I wrote as a plugin for Nagios nrpe.
Inside my bash script I am using this command line to execute the shadtest macro:
OUTPUT=`echo -e "USERNAME\nPASSWORD\nd ^shadtest\nh\n" | csession INSTNCENAME -U NAMESPACE`
You should have defined a user for this monitoring tasks with adapted permissions.
Now everything you need is in your OUTPUT variable and can be treated by a shell script or whatever you prefer.

I am sure that there are better ways to get these values, but I am fine with my solution and hope that it will help others.

About Juergen Caris

I am 54yo, MSc(Dist) and BSc in Computer Science, German and working as a Senior Server Engineer for the NHS Lothian. I am responsible for the patient management system, called TrakCare. I am a UNIX/Linux guy, working in this sector for more than 20 years now. I am also interested in robotics, microprocessors, system monitoring, Home automation and programming.
This entry was posted in Bash, Nagios. Bookmark the permalink.

5 Responses to Easy monitoring of an Intersystems Cache shadow server

  1. MadeleinHD says:

    Good web site! I truly love how it is simple on my eyes and the data are well written. I am wondering how I might be notified when a new post has been made. I’ve subscribed to your RSS feed which must do the trick! Have a great day!

    find out

  2. Colin Horwill says:

    Superb Juergen – many thanks – was just looking for a way to do this for ourselves (NHS A&A!) – this popped up on google (4th result!) – and will save me hours of work trying to figure it out myself!

  3. Ulysses says:

    This is very attention-grabbing, You are an overly skilled blogger.
    I’ve joined your rss feed and stay up for in search
    of extra of your great post. Also, I have shared your website in my social networks

  4. thanks for this article , good for read..

  5. this blog is very good and very useful .. thanks you for the information that has been given to me ..

    thank you also for being allowed to comment here ^^

Leave a Reply

Your email address will not be published.