-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMule_Agent_Monitoring.pl
102 lines (82 loc) · 2.96 KB
/
Mule_Agent_Monitoring.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# ! /usr/bin/perl
# Original Author: Occams Reiza
#
# Program Name: Mule Agent Monitoring
#
# Purpose: Get status of Mule Agents
#
# Dated Revisions: see RCS
# ---------------------------------------------------
use strict;
# Local Variable Definitions
my $HOSTNAME =`hostname`;
my $memused;
my $cpuused;
my $MULEHOME="/usr/local/mule-enterprise-standalone-3 .4. 0/";
my $MULEPIDFILE="$MULEHOME/bin/.muleee.pid";
my $MULEAPP"$MULEHOME/apps/agentmonitor-vl .0";
my $next_arg;
my $Startupcmd= "./etc/init.d/mule"
my @buffer;
$SIG{_DIE_} = 'DIE_handler';
my $pid;
my $pingStatus;
my $restarts =0;
#Redirect Output
open STDOUT, ">", "/tmp/PersonUpdateTopic.dat" or die "$0: open: $!";
open STDERR, ">&STDOUT" or die "$0: dup: $!";
print "Checking if the Ping Service deployed or not on $HOSTNAME\n";
if(-d $MULEAPP){
print "Found deployed Ping Service.....\n\n";
print "Pinging to the agent ping service on port 8686. . . . \n";
$pingStatus=`curl -s http://\$HOSTNAME:8686/ping`;
if ( $pingStatus= /PONG/) {
print "Ping Service is up and running as of ".substr($pingStatus,6)."\n";
}else {
print "Agent at $HOSTNAME is not responding ..... \n";
print "Ping Service is not deployed. \n";
`/bin/mail -s "WARN: Agent at $HOSTNAME is not responding...."
YourMonitoringAddressHere\@xxx.com< /tmp/PersonUpdateTopic.dat`;
}
print "Getting the Process Id of Mule Agent ..... \n";
open(FILE, $MULEPIDFILE) or die("\n");
chomp($pid = <FILE>);
close (FILE);
print "The PID is $pid\n";
}
# Check Process ID
print "Checking whether PID $pid is up and running . . . . \n";
if (`ps -aef | grep mule | grep java | grep $pid`) {
print "Process Id $pid is up and running... \n";
# Current Usage
chomp ($memused=`ps -p $pid -o sz | cut -d' ' -f1`);
chomp ($cpuused=`ps -p $pid -o sz,pcpu | cut -d' ' -f3`);
print "Current Memory Utilization by the PID $pid is $memused\n";
print "Current CPU Usage by the PID $pid is $cpuused\n";
if ( $memused >= 5394272) {
print " Current Memory Utilization by the PID $pid is over 90% , Restarting Agent";
&DIE_handler
}else {
print "Current Memory Utilization by the PID $pid is under 90% \n";
}
if ($cpuused >= 90.0 ) {
print "Current CPU Usage is over 90% , Restarting Agent\n";
&DIE_handler
}else {
print "Current CPU Usage is under 90% \n";
}
} else {
print "Process Id $pid is down";
`/bin/mail -s "WARN: Agent at $HOSTNAME is not responding. Process Id $pid is down"
YourMonitoringAddressHere\@xxx.com< /tmp/PersonUpdateTopic.dat`;
}
# Implement Starting Agent if neccessary
sub DIE_handler {
my($signal) = @_;
print "\nPID file $MULEPIDFILE does not exist, which may be due to the process being down or an incorrect PID file\n";
@buffer = (`$Startup_cmd`)
$restarts=$restarts + 1;
print "$HOSTNAME has been restarted $restarts times";
print "\n Restarting Mule Agent\n";
}
exit;