Consider this scenario,

You are having Mirth in your system. Which is actively running at-least 5 to 10 channels deployed. Each and every channel performs multiple operations within, and they are independent of each other.

Mirth allows a concept of setting alerts if there is a channel that is error, has messages filled in queue, has stopped due to heap space issues or halted. Mirth community edition will trigger an email to your personal mailing system if you run into any of these troubles.

Different Thought :

How about deploying a channel that will act as a tool, which will primarily monitor all the deployed channel and accumulates the status of those channels now and then and form that as an API.

How will it Help?

If you have a multiple mirth instances, which runs multiple channels, this channel can be deployed in each and every mirth instance and that will monitor  status of all the channels been deployed. Using this status accumulated API we can call it in a mobile or any web application to develop as a generalized reporting tool.

Pre-requisite:

  • MirthConnect : 3.4.1.8057 (latest version)

Channel Setup:
Source : Javascript Reader

  1. Create a New channel name it as your wish Here I have named MirthMonitor
  2. Click on Set Data Types button set the source connector inbound to Raw
  3. Outbound and Destination 1 to Raw
     – that’s it the channel setup is done for it.

Destination : Channel Writer

Source Transformer Code:

/*Get Deployed Channel ID’s*/
var getDeployedChannelIds = ChannelUtil.getDeployedChannelIds();
var getDeployedChannelIdsCount=getDeployedChannelIds.size();
/*Initialize Array*/
var Totaldata=[];
/*InitializeObject*/
var monitorObject={};
/*JSON Header*/
monitorObject.Date= DateUtil.getCurrentDate(“yyyyMMdd”);
monitorObject.ClientKey=UUIDGenerator.getUUID();
/*LoopIndependentChannelStatistics*/
for (var index = 0; index < getDeployedChannelIds.size(); index++) {
var ChannelID = getDeployedChannelIds.get(index);
monitorObject.ChannelStats={};
monitorObject.ChannelStats.Id=ChannelID;
monitorObject.ChannelStats.ChannelName=ChannelUtil.getChannelName(ChannelID);
monitorObject.ChannelStats.ReceivedCount=ChannelUtil.getReceivedCount(ChannelID);
monitorObject.ChannelStats.FilterCount=ChannelUtil.getFilteredCount(ChannelID);
monitorObject.ChannelStats.QueuedCount=ChannelUtil.getQueuedCount(ChannelID);
monitorObject.ChannelStats.ErrorCount=ChannelUtil.getErrorCount(ChannelID);
monitorObject.ChannelStats.SentCount=ChannelUtil.getSentCount(ChannelID);
Totaldata.push(monitorObject.ChannelStats);
}
monitorObject.ChannelStats=Totaldata;
/*PrintJsonData*/
var output= JSON.stringify(monitorObject);
logger.info(output);
channelMap.put(‘jsonOutput’,output);

Let us consider that we have deployed three channels in the mirth and are actually running actively. We are now deploying this channel which will run and monitor the status of other channels and produce the outputs in the JSON format.

channel monitor

Output of this channel monitor will be a JSON data as shown below, Here I have deployed three channels and the outputs are monitored and produced below in real-time  for every 5 seconds.

{
“Date”: “20160831”,
“ClientKey”: “1792cdf1-1926-4438-9d4b-715ac3e45c63”,
“ChannelStats”: [{
“Id”: “f9d9d3ed-59ce-46dd-93cf-309adf0709bb”,
“ChannelName”: “JSON to HL7V2”,
“ReceivedCount”: 31,
“FilterCount”: 0,
“QueuedCount”: 0,
“ErrorCount”: 10,
“SentCount”: 21
}, {
“Id”: “97968dc3-78ba-40e9-960d-b4bee41e961e”,
“ChannelName”: “MirthMonitor-Version2”,
“ReceivedCount”: 4,
“FilterCount”: 0,
“QueuedCount”: 0,
“ErrorCount”: 3,
“SentCount”: 0
}, {
“Id”: “9c1bb1e3-6a4f-4213-b8de-49c16f7ae7e4”,
“ChannelName”: “QRDA – Generator”,
“ReceivedCount”: 25,
“FilterCount”: 0,
“QueuedCount”: 0,
“ErrorCount”: 3,
“SentCount”: 22
}]
}

 

 

 

Leave a Comment