web stats
Any ideas on how to monitor queued messages? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-26-2013, 06:41 AM
upstart33 upstart33 is offline
Mirth Guru
 
Join Date: Dec 2010
Location: Chicago, IL.
Posts: 461
upstart33 is on a distinguished road
Default Any ideas on how to monitor queued messages?

Hi,

I have been having a few problems with some of our client destinations within the last month that have caused various channels to have their messages begin to queue for extended periods of times without anyone noticing.

I was thinking about creating a channel that would see if any other channel had queued message and then send an email/alert to a few people. I know that I can probably try to query to Postgres database directly, but does anyone know of any Mirth functions/code/javascript/etc that I could use instead?
Reply With Quote
  #2  
Old 06-26-2013, 08:01 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,360
cory_cole is on a distinguished road
Default

We have an alerting channel that pulls from the database. It then sleeps for 3 mins and pulls again (to make sure it is not just a data dump). If it is still not decreasing, the channel runs some steps to attempt to fix the issue (stop/start channels, undeploy/redeploy channels). If any of these steps fix the issue, we still get the alert but the email we indicate which step fixed it. If nothing fixes it, the channel will run diagnostics (test connection to the ports, ping the site). The alert will email what steps need to be taken based on the results of the diagnostic.
Reply With Quote
  #3  
Old 06-26-2013, 12:29 PM
Chris.ACH Chris.ACH is offline
Mirth Newb
 
Join Date: Sep 2012
Posts: 20
Chris.ACH is on a distinguished road
Default

Do you mind sharing that channel?
Reply With Quote
  #4  
Old 06-26-2013, 01:03 PM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,360
cory_cole is on a distinguished road
Default

I will try to scale it down by tomorrow. We have things that are specific to us (i.e. naming conventions to prevent alerts on test channels, contact info, etc.)
Reply With Quote
  #5  
Old 06-26-2013, 02:41 PM
eduardoa eduardoa is offline
Mirth Employee
 
Join Date: Mar 2013
Location: Santa Fe Springs, California
Posts: 134
eduardoa is on a distinguished road
Default

http://www.mirthcorp.com/community/f...ead.php?t=4254
Reply With Quote
  #6  
Old 06-27-2013, 06:19 AM
upstart33 upstart33 is offline
Mirth Guru
 
Join Date: Dec 2010
Location: Chicago, IL.
Posts: 461
upstart33 is on a distinguished road
Default

Thanks. This seems to fit with what we need. I will have to tinker around with it, but it is doing what it is supposed to do.
Reply With Quote
  #7  
Old 06-27-2013, 06:26 AM
atibbits atibbits is offline
Mirth Guru
 
Join Date: May 2012
Location: Salina, KS
Posts: 381
atibbits is on a distinguished road
Default

Here is what I use to send out alerts for messages stuck in queue on specific channels:


Quote:
(Put this in the deploy script)

//This ensures that the alert will trigger if the condition occurs soon after deploying

var rightnow = new Date();
var newtime = rightnow - (3 * (1000 * 60 * 60))


globalMap.put(channelId + '_lastalert',newtime);
Quote:
(put this in the postprocessor)

// This script executes once after a message has been processed

//Check to see if the alert has already been sent within the given timeframe

var lastsent = globalMap.get(channelId + '_lastalert'); //last time an alert was sent
var rightnow = new Date(); //Current Datetime
var hLimit = 1; //Number of hours before resending an alert

var datediff = (rightnow - lastsent) / (1000 * 60 * 60); //calculates hours since last alert went out

if (datediff < hLimit) {

return;

} else {

//This is the bit that does the heavy lifting

var controller = Packages.com.mirth.connect.server.controllers.Chan nelStatisticsController.getInstance();
var channelName = Packages.com.mirth.connect.server.controllers.Chan nelController.getInstance().getDeployedChannelById (channelId).getName();
var stats = controller.getStatistics(channelId);


//I include all these so you can see what's available
var mSent = stats.getSent();
var mReceived = stats.getReceived();
var mQueued = stats.getQueued();
var mError = stats.getError();

var qAlarm = 10;


if (mQueued % qAlarm == 0 && mQueued != 0) //This checks the limit of queued messages in groups of (qAlarm) 10.

{

var emTo = 'name@address.com'; //This is the email address you want to send the alert to.
var emCC = 'name@address.com'; //This is any cc emails you want to include
var emFrom = 'channel@address.com'; //This is the "From" address that will appear on your email
var emSubj = 'Queue Alert for Channel (LIVE): ' + channelName; //This is the subject of the email
var emBody = 'Queued messages detected on channel (LIVE) ' + channelName + '.\n';
emBody = emBody + 'Current number of queued messages is ' + mQueued.toString() + '.\n';
emBody = emBody + 'This alert will not be resent for ' + hLimit.toString() + ' hours.\nPlease do not respond to this email. This address is not monitored.';


var smtpConn = SMTPConnectionFactory.createSMTPConnection(); //Opens email connection using email settings in your Mirth Connect Settings.

smtpConn.send(emTo,emCC,emFrom,emSubj,emBody);


globalMap.put(channelId + '_lastalert',rightnow);



}
}
You can change the var qAlarm amount to send the alert for groups of queues. For example, I have 10 in this example and that means that every time 10 new messages get added to the queue an alert is sent out (i.e. 10, 20, 30, etc...).
Reply With Quote
  #8  
Old 09-17-2013, 12:18 PM
Jaypell22 Jaypell22 is offline
OBX.1 Kenobi
 
Join Date: Jul 2011
Location: Upstate NY
Posts: 33
Jaypell22 is on a distinguished road
Thumbs up

Thank you atibbits, this is priceless!
Reply With Quote
  #9  
Old 05-17-2014, 09:24 PM
PrasenjitSatpathy PrasenjitSatpathy is offline
Mirth Newb
 
Join Date: Oct 2011
Posts: 10
PrasenjitSatpathy is on a distinguished road
Default

Cory - Can you share the channel?
Reply With Quote
  #10  
Old 05-17-2014, 09:25 PM
PrasenjitSatpathy PrasenjitSatpathy is offline
Mirth Newb
 
Join Date: Oct 2011
Posts: 10
PrasenjitSatpathy is on a distinguished road
Default

Can you share the channel?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:46 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation