Skip to content

Monitoring Private Message Queues for windows application in AWS.

0

Hello,

I want to ask if there is a way in AWS to create a monitor to check for the private message queues that we can see in windows systems under 'Services and Applications' in Computer management. Ideally, for the system health to be good all the queues should be zero, so I want to create a monitor that will alert us if the value is not zero for any of the queue.

1 Answer
0

Yes, you can monitor private message queues (MSMQ) on Windows systems using AWS services by leveraging a combination of CloudWatch, CloudWatch Agent, and Custom Scripts. Since AWS does not natively integrate with MSMQ, you'll need to implement a custom solution to extract MSMQ queue metrics and push them to AWS for monitoring.

Solution Overview

  1. Extract MSMQ queue statistics using PowerShell
  2. Send the metrics to Amazon CloudWatch
  3. Set up an alarm in CloudWatch to notify when the queue depth is non-zero

Step 1: Extract MSMQ Queue Depth Using PowerShell

On your Windows server, use PowerShell to retrieve the number of messages in a private queue:

$queues = Get-MSMQQueue -Private
foreach ($queue in $queues) {
   $queueName = $queue.QueueName
   $messageCount = $queue.MessageCount

   # Send data to CloudWatch
   Write-Host "Queue: $queueName, Messages: $messageCount"

   # Push to CloudWatch (via AWS CLI)
   aws cloudwatch put-metric-data --namespace MSMQ --metric-name "$queueName-MessageCount" --value $messageCount --  dimensions QueueName=$queueName --region your-region
}

This script retrieves all private queues, extracts message counts, and sends them to Amazon CloudWatch.


Step 2: Automate the Script Execution

  1. Save the script as MonitorMSMQ.ps1 on the server.
  2. Create a scheduled task in Windows Task Scheduler:

Open Task Scheduler

Create a new task

Set the trigger to run the script every minute (or your preferred frequency)

Use powershell.exe -File "C:\Path\To\MonitorMSMQ.ps1"

This will ensure the script runs periodically and updates CloudWatch.


Step 3: Set Up a CloudWatch Alarm

  1. Go to AWS CloudWatch Console → Metrics → Custom Namespace (MSMQ).
  2. Find the metric with the name {QueueName}-MessageCount.
  3. Click on Create Alarm.
  4. Set the threshold condition:

Threshold type: Static

Condition: Greater than 0

Period: 1 minute (or the frequency of your script)

  1. Choose an SNS topic to receive notifications.

Step 4: Optional - Send Alerts to AWS SNS

If you don’t already have an SNS topic, create one:

  1. Go to AWS SNS Console → Create Topic.
  2. Add an Email or Lambda function as a subscriber.
  3. Configure the CloudWatch Alarm to send alerts to this SNS topic.

Alternative Approach: Using CloudWatch Agent

If you have the AWS CloudWatch Agent installed on your Windows system, you can configure it to push Performance Counter Data from MSMQ to CloudWatch. You'd need to modify the CloudWatch Agent’s config.json file to include MSMQ counters.

Example:

{
  "metrics": {
    "append_dimensions": {
        "InstanceId": "${instance_id}"
    },
    "metrics_collected": {
        "MSMQ": {
            "metrics": [
                { "name": "Messages in Queue", "unit": "Count" }
            ],
            "measurement": [
                { "name": "MSMQ Queue Depth", "rename": "MSMQMessageCount" }
            ]
        }
    }
  }
}

Run:

Start-Service AmazonCloudWatchAgent


Summary

Best for quick implementation → Use PowerShell + AWS CLI + CloudWatch

More scalable solution → CloudWatch Agent with MSMQ metrics

Alerts & notifications → Set up CloudWatch Alarms with SNS

This solution ensures that if any MSMQ queue has messages pending (i.e., count > 0), an alarm will be triggered in AWS CloudWatch, and you will receive an alert via SNS.

AWS

answered a year ago

  • Thank you so much, Fabio. We don't have AWS CLI installed in our systems for security reasons but we do have cloudwatch agent installed. I did understand the CLI procedure, but not the example you gave for updating the cloudwatch config file. Kind of hesitant to do just anything, as I have read that it is not possible to delete a custom namespace once it is created.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.