├── .gitignore
├── inc
└── Module-Build
│ └── Module
│ └── Build
│ ├── ModuleInfo.pm
│ ├── Dumper.pm
│ ├── Platform
│ ├── VOS.pm
│ ├── Amiga.pm
│ ├── Default.pm
│ ├── MPEiX.pm
│ ├── EBCDIC.pm
│ ├── RiscOS.pm
│ ├── os2.pm
│ ├── cygwin.pm
│ ├── aix.pm
│ ├── darwin.pm
│ ├── Unix.pm
│ └── MacOS.pm
│ ├── Config.pm
│ ├── PodParser.pm
│ └── YAML.pm
├── config
├── websphere
│ ├── appstate.cfg
│ ├── threads.cfg
│ ├── jca.cfg
│ ├── jms.cfg
│ ├── jdbc.cfg
│ └── http.cfg
├── common.cfg
├── threads.cfg
├── websphere.cfg
├── metrics.cfg
├── glassfish.cfg
├── weblogic.cfg
├── jboss.cfg
└── wildfly.cfg
├── t
├── 70_pod_syntax.t
├── j4p_test.cfg
├── 20_alias.t
├── lib
│ ├── ProductTest
│ │ ├── Test2Handler.pm
│ │ └── Test1Handler.pm
│ └── It.pm
├── 50_config.t
├── 60_parse_name.t
├── 10_handler.t
├── 40_check_jmx4perl.t
└── 30_request.t
├── it
├── t
│ ├── 90_search.t
│ ├── 02_http_header.t
│ ├── 40_alias.t
│ ├── 59_check_timeout.t
│ ├── 60_bulk_request.t
│ ├── 83_write.t
│ ├── 10_base.t
│ ├── 84_exec.t
│ ├── 99_discovery.t
│ ├── 51_check_relative.t
│ ├── 01_version.t
│ ├── 56_check_value.t
│ ├── 30_naming.t
│ ├── 50_check_base.t
│ ├── 85_path_escaping.t
│ ├── 70_overloaded_method.t
│ ├── 55_check_incremental.t
│ ├── 52_check_operation.t
│ ├── 54_check_unit.t
│ ├── 64_check_perfdata.t
│ ├── 53_check_non_numeric.t
│ ├── 95_cors.t
│ ├── 80_read.t
│ ├── 58_check_multi_config.t
│ └── 57_check_config.t
├── check_jmx4perl
│ ├── base.cfg
│ ├── multi_check.cfg
│ └── base.pl
└── it.pl
├── examples
├── memory.pl
├── memory.sh
├── remote.pl
└── threadDump.pl
├── docker
├── Dockerfile
└── README.md
├── MANIFEST.SKIP
├── lib
└── JMX
│ └── Jmx4Perl
│ ├── Agent
│ └── Jolokia
│ │ ├── Verifier
│ │ ├── PGPKey.pm
│ │ ├── MD5Verifier.pm
│ │ ├── SHA1Verifier.pm
│ │ ├── ChecksumVerifier.pm
│ │ └── OpenPGPVerifier.pm
│ │ └── Logger.pm
│ ├── Nagios
│ ├── MessageHandler.pm
│ └── CactiJmx4Perl.pm
│ ├── Product
│ ├── Hadoop.pm
│ ├── ActiveMQ.pm
│ ├── JBoss.pm
│ ├── Terracotta.pm
│ ├── Geronimo.pm
│ ├── Jonas.pm
│ ├── Resin.pm
│ ├── SpringDM.pm
│ ├── Tomcat.pm
│ ├── Unknown.pm
│ ├── Websphere.pm
│ ├── Glassfish.pm
│ ├── Jetty.pm
│ └── Weblogic.pm
│ ├── Alias
│ └── Object.pm
│ ├── J4psh
│ └── Command
│ │ ├── Global.pm
│ │ └── Server.pm
│ ├── Util.pm
│ └── Response.pm
├── TODO
└── scripts
├── cacti_jmx4perl
└── j4psh
/.gitignore:
--------------------------------------------------------------------------------
1 | Build
2 | _build
3 | blib
4 | MYMETA.yml
5 | docs
6 | x
7 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/ModuleInfo.pm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rhuss/jmx4perl/HEAD/inc/Module-Build/Module/Build/ModuleInfo.pm
--------------------------------------------------------------------------------
/config/websphere/appstate.cfg:
--------------------------------------------------------------------------------
1 | # ---------------------------------------
2 | # Check of the application state
3 | #
4 | # $0: application name
5 |
6 | MBean WebSphere:j2eeType=J2EEApplication,J2EEName=${0},*
7 | Attribute state
8 |
9 | Critical = ${1:1}
10 | Label = $0 : status = %v
11 | Name = $0-state
12 |
13 |
14 |
--------------------------------------------------------------------------------
/t/70_pod_syntax.t:
--------------------------------------------------------------------------------
1 | #!perl
2 |
3 | use Test::More;
4 |
5 | unless($ENV{RELEASE_TESTING}) {
6 | Test::More::plan(skip_all => 'these tests are for release candidate testing');
7 | }
8 |
9 | unless(eval "use Test::Pod; 1") {
10 | plan skip_all => "Test::Pod required for testing POD";
11 | }
12 |
13 | all_pod_files_ok(grep { !/PGPKey/ } all_pod_files(qw(blib script)));
14 |
--------------------------------------------------------------------------------
/it/t/90_search.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More qw(no_plan);
5 | use JMX::Jmx4Perl;
6 | use JMX::Jmx4Perl::Request;
7 | use Data::Dumper;
8 | #use Test::More tests => $ENV{JMX4PERL_PRODUCT} ? 2 : 1;
9 |
10 | # Check for escaped pattern:
11 |
12 | my $jmx = It->new(verbose => 0)->jmx4perl;
13 | my $mbeans = $jmx->search("jolokia.it:type=escape,*");
14 | for my $m (@$mbeans) {
15 | my $value = $jmx->get_attribute($m,"Ok");
16 | is($value,"OK",$m);
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/examples/memory.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | use JMX::Jmx4Perl;
3 | use strict;
4 | my $jmx = new JMX::Jmx4Perl(url => "http://localhost:8080/jolokia");
5 | my $memory = $jmx->get_attribute("java.lang:type=Memory","HeapMemoryUsage");
6 | my ($used,$max) = ($memory->{used},$memory->{max});
7 | if ($memory->{used} / $memory->{max} > 0.9) {
8 | print "Memory exceeds 90% (used: $used / max: $max = ",int($used * 100 / $max),"%)\n";
9 | system("/etc/init.d/tomcat restart");
10 | sleep(120);
11 | }
12 |
--------------------------------------------------------------------------------
/examples/memory.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | base_url="http://localhost:9090/jolokia"
4 | memory_url="${base_url}/read/java.lang:type=Memory/HeapMemoryUsage"
5 | used=`wget -q -O - "${memory_url}/used" | sed 's/^.*"value":"\([0-9]*\)".*$/\1/'`
6 | max=`wget -q -O - "${memory_url}/max" | sed 's/^.*"value":"\([0-9]*\)".*$/\1/'`
7 | usage=$((${used}*100/${max}))
8 | if [ $usage -gt 5 ]; then
9 | echo "Memory exceeds 80% (used: $used / max: $max = ${usage}\%)";
10 | exit 1;
11 | else
12 | exit 0;
13 | fi
14 |
--------------------------------------------------------------------------------
/t/j4p_test.cfg:
--------------------------------------------------------------------------------
1 | # ================================================================
2 | # Sample configuration for jmx4perl
3 |
4 |
5 | Url = http://localhost:8888/j4p
6 | Product = JBoss
7 | # User = roland
8 | # Password = test
9 | # Proxy_User = ....
10 | # Proxy_Password = ....
11 |
12 |
13 | Url = http://localhost:8899/j4p
14 | Product = Weblogic
15 | User = roland
16 | Password = test
17 | # Proxy_User = ....
18 | # Proxy_Password = ....
19 |
20 |
--------------------------------------------------------------------------------
/it/check_jmx4perl/base.cfg:
--------------------------------------------------------------------------------
1 | # ================================================
2 | # Base definitions:
3 |
4 | # Check for relative memory checks
5 |
6 | Use = base_relative_threshold($0,$1)
7 | Use = base_relative_label
8 | Label = (base) $BASE
9 | Unit = B
10 |
11 |
12 |
13 | Critical = ${0:90}
14 | Warning = ${1:80}
15 |
16 |
17 |
18 | Label = (grandpa) %.2r% used (%.2v %u / %.2b %w)
19 |
--------------------------------------------------------------------------------
/it/t/02_http_header.t:
--------------------------------------------------------------------------------
1 | use It;
2 | use Data::Dumper;
3 | use Test::More tests => 2;
4 |
5 | my $it = new It(verbose => 0);
6 | my $agent = $it->userAgent;
7 | my $j4p = $it->jmx4perl;
8 | my $resp = $agent->get($j4p->url() . "/version");
9 | my $date = $resp->date;
10 | my $expire = $resp->expires;
11 | #print Dumper($resp);
12 | #print "Date: $date\nExpires: $expire\n";
13 | ok($expire <= $date,"expires must be less or equal date");
14 | ok($resp->header('Expires') =~ /\w{3}, \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT/,"RFC-1123 Format matched");
15 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Dumper.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Dumper;
2 | use strict;
3 | use vars qw($VERSION);
4 | $VERSION = '0.34';
5 |
6 | # This is just a split-out of a wrapper function to do Data::Dumper
7 | # stuff "the right way". See:
8 | # http://groups.google.com/group/perl.module.build/browse_thread/thread/c8065052b2e0d741
9 |
10 | use Data::Dumper;
11 |
12 | sub _data_dump {
13 | my ($self, $data) = @_;
14 | return ("do{ my "
15 | . Data::Dumper->new([$data],['x'])->Purity(1)->Terse(0)->Dump()
16 | . '$x; }')
17 | }
18 |
19 | 1;
20 |
--------------------------------------------------------------------------------
/t/20_alias.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use strict;
4 | use warnings;
5 | use FindBin qw($Bin);
6 | use lib qq($Bin/lib);
7 | use Data::Dumper;
8 |
9 | use Test::More tests => 6;
10 |
11 | BEGIN { use_ok("JMX::Jmx4Perl::Alias"); }
12 |
13 | # Check names
14 | is(MEMORY_HEAP->name,"memory:heap","Name");
15 |
16 | # Check by name
17 | for $_ (qw(memory:heap:used MEMORY_HEAP_USED)) {
18 | my $heap = JMX::Jmx4Perl::Alias->by_name($_);
19 | ok(MEMORY_HEAP_USED == $heap,"Equality");
20 | ok($heap->isa("JMX::Jmx4Perl::Alias::Object"),"isa");
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/it/t/40_alias.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More tests => 2;
5 | #use Test::More tests => $ENV{JMX4PERL_PRODUCT} ? 2 : 1;
6 |
7 | BEGIN { use_ok("JMX::Jmx4Perl::Alias"); }
8 |
9 | my $jmx = new It()->jmx4perl;
10 |
11 | my @aliases = JMX::Jmx4Perl::Alias->all;
12 | eval {
13 | for my $alias (@aliases) {
14 | if ($jmx->supports_alias($alias) && $alias->type eq "attribute") {
15 | #print $alias->alias,": ",$jmx->get_attribute($alias),"\n";
16 | $jmx->get_attribute($alias);
17 | }
18 | }
19 | };
20 | ok(!$@,"Aliased called: $@");
21 |
--------------------------------------------------------------------------------
/t/lib/ProductTest/Test2Handler.pm:
--------------------------------------------------------------------------------
1 | package ProductTest::Test2Handler;
2 |
3 | use base qw(JMX::Jmx4Perl::Product::BaseHandler);
4 |
5 | sub id { return "Test2" };
6 |
7 | sub autodetect {
8 | return 0;
9 | }
10 |
11 | sub order {
12 | return -1;
13 | }
14 |
15 | sub init_aliases {
16 | return
17 | {
18 | attributes => {
19 | MEMORY_HEAP => [ "resolved2_name", "resolved2_attr" ]
20 | },
21 | operations => {
22 | MEMORY_GC => [ "memory2_name", "gc2_op" ]
23 | }
24 | };
25 | }
26 |
27 | 1;
28 |
--------------------------------------------------------------------------------
/it/t/59_check_timeout.t:
--------------------------------------------------------------------------------
1 | use FindBin;
2 | use strict;
3 | use warnings;
4 | use Test::More qw(no_plan);
5 | use Data::Dumper;
6 | use JMX::Jmx4Perl::Alias;
7 | use It;
8 |
9 | require "check_jmx4perl/base.pl";
10 |
11 | my $jmx = It->new(verbose=>1)->jmx4perl;
12 | my ($ret,$content);
13 |
14 | my $time = time;
15 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=operation --operation sleep --timeout 1 -c 1 2");
16 | # print Dumper($ret,$content);
17 | # print "Time ",time - $time,"\n";
18 | ok($content =~ /timeout/i,"Timeout reached");
19 | is($ret,3,"UNKNOWN status for timeouts");
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/VOS.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::VOS;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Base;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Base);
11 |
12 |
13 | 1;
14 | __END__
15 |
16 |
17 | =head1 NAME
18 |
19 | Module::Build::Platform::VOS - Builder class for VOS platforms
20 |
21 | =head1 DESCRIPTION
22 |
23 | The sole purpose of this module is to inherit from
24 | C. Please see the L for the docs.
25 |
26 | =head1 AUTHOR
27 |
28 | Ken Williams
29 |
30 | =head1 SEE ALSO
31 |
32 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
33 |
34 | =cut
35 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/Amiga.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::Amiga;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Base;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Base);
11 |
12 |
13 | 1;
14 | __END__
15 |
16 |
17 | =head1 NAME
18 |
19 | Module::Build::Platform::Amiga - Builder class for Amiga platforms
20 |
21 | =head1 DESCRIPTION
22 |
23 | The sole purpose of this module is to inherit from
24 | C. Please see the L for the docs.
25 |
26 | =head1 AUTHOR
27 |
28 | Ken Williams
29 |
30 | =head1 SEE ALSO
31 |
32 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
33 |
34 | =cut
35 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/Default.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::Default;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Base;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Base);
11 |
12 | 1;
13 | __END__
14 |
15 |
16 | =head1 NAME
17 |
18 | Module::Build::Platform::Default - Stub class for unknown platforms
19 |
20 | =head1 DESCRIPTION
21 |
22 | The sole purpose of this module is to inherit from
23 | C. Please see the L for the docs.
24 |
25 | =head1 AUTHOR
26 |
27 | Ken Williams
28 |
29 | =head1 SEE ALSO
30 |
31 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
32 |
33 | =cut
34 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/MPEiX.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::MPEiX;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Base;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Base);
11 |
12 |
13 | 1;
14 | __END__
15 |
16 |
17 | =head1 NAME
18 |
19 | Module::Build::Platform::MPEiX - Builder class for MPEiX platforms
20 |
21 | =head1 DESCRIPTION
22 |
23 | The sole purpose of this module is to inherit from
24 | C. Please see the L for the docs.
25 |
26 | =head1 AUTHOR
27 |
28 | Ken Williams
29 |
30 | =head1 SEE ALSO
31 |
32 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
33 |
34 | =cut
35 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/EBCDIC.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::EBCDIC;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Base;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Base);
11 |
12 |
13 | 1;
14 | __END__
15 |
16 |
17 | =head1 NAME
18 |
19 | Module::Build::Platform::EBCDIC - Builder class for EBCDIC platforms
20 |
21 | =head1 DESCRIPTION
22 |
23 | The sole purpose of this module is to inherit from
24 | C. Please see the L for the docs.
25 |
26 | =head1 AUTHOR
27 |
28 | Ken Williams
29 |
30 | =head1 SEE ALSO
31 |
32 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
33 |
34 | =cut
35 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/RiscOS.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::RiscOS;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Base;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Base);
11 |
12 |
13 | 1;
14 | __END__
15 |
16 |
17 | =head1 NAME
18 |
19 | Module::Build::Platform::RiscOS - Builder class for RiscOS platforms
20 |
21 | =head1 DESCRIPTION
22 |
23 | The sole purpose of this module is to inherit from
24 | C. Please see the L for the docs.
25 |
26 | =head1 AUTHOR
27 |
28 | Ken Williams
29 |
30 | =head1 SEE ALSO
31 |
32 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
33 |
34 | =cut
35 |
--------------------------------------------------------------------------------
/t/lib/ProductTest/Test1Handler.pm:
--------------------------------------------------------------------------------
1 | package ProductTest::Test1Handler;
2 |
3 | use base qw(JMX::Jmx4Perl::Product::BaseHandler);
4 | use JMX::Jmx4Perl::Alias;
5 |
6 |
7 | sub id { return "Test1" };
8 |
9 | sub autodetect { return 1; }
10 |
11 | sub order {
12 | return 1;
13 | }
14 | sub init_aliases {
15 | return {
16 | attributes =>
17 | {
18 | MEMORY_HEAP => [ "resolved_name", "resolved_attr" ],
19 | SERVER_NAME => [
20 | sub {
21 | return ["server","name"]
22 | }
23 | ],
24 | SERVER_ADDRESS => sub {
25 | return "127.0.0.1";
26 | }
27 | }
28 | };
29 | }
30 |
31 | 1;
32 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/os2.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::os2;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Platform::Unix;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Platform::Unix);
11 |
12 | sub manpage_separator { '.' }
13 |
14 | sub have_forkpipe { 0 }
15 |
16 | 1;
17 | __END__
18 |
19 |
20 | =head1 NAME
21 |
22 | Module::Build::Platform::os2 - Builder class for OS/2 platform
23 |
24 | =head1 DESCRIPTION
25 |
26 | This module provides some routines very specific to the OS/2
27 | platform.
28 |
29 | Please see the L for the general docs.
30 |
31 | =head1 AUTHOR
32 |
33 | Ken Williams
34 |
35 | =head1 SEE ALSO
36 |
37 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
38 |
39 | =cut
40 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/cygwin.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::cygwin;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Platform::Unix;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Platform::Unix);
11 |
12 | sub manpage_separator {
13 | '.'
14 | }
15 |
16 | 1;
17 | __END__
18 |
19 |
20 | =head1 NAME
21 |
22 | Module::Build::Platform::cygwin - Builder class for Cygwin platform
23 |
24 | =head1 DESCRIPTION
25 |
26 | This module provides some routines very specific to the cygwin
27 | platform.
28 |
29 | Please see the L for the general docs.
30 |
31 | =head1 AUTHOR
32 |
33 | Initial stub by Yitzchak Scott-Thoennes
34 |
35 | =head1 SEE ALSO
36 |
37 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
38 |
39 | =cut
40 |
--------------------------------------------------------------------------------
/it/t/60_bulk_request.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More qw(no_plan);
5 | use JMX::Jmx4Perl;
6 | use JMX::Jmx4Perl::Request;
7 | use Data::Dumper;
8 | #use Test::More tests => $ENV{JMX4PERL_PRODUCT} ? 2 : 1;
9 |
10 |
11 | my $jmx = new It(verbose => 0)->jmx4perl;
12 | my @reqs = ( new JMX::Jmx4Perl::Request(READ,"java.lang:type=Memory", "HeapMemoryUsage", "used"),
13 | new JMX::Jmx4Perl::Request(READ,"java.lang:type=Memory", "HeapMemoryUsage", "max"),
14 | new JMX::Jmx4Perl::Request(READ,"java.lang:type=ClassLoading", "LoadedClassCount"),
15 | new JMX::Jmx4Perl::Request(SEARCH,"*:type=Memory,*"));
16 |
17 | my @resps = $jmx->request(@reqs);
18 | is(scalar(@resps),4,"4 Responses");
19 | for (my $i = 0 .. 3) {
20 | is($resps[$i]->{request},$reqs[$i],"Request " . ($i+1));
21 | }
22 | #print Dumper(\@resps);
23 |
--------------------------------------------------------------------------------
/it/t/83_write.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More qw(no_plan);
5 | use JMX::Jmx4Perl;
6 | use JMX::Jmx4Perl::Request;
7 | use Data::Dumper;
8 | use strict;
9 | #use Test::More tests => $ENV{JMX4PERL_PRODUCT} ? 2 : 1;
10 |
11 |
12 | # Write the object name ad re-read
13 | my $jmx = new It(verbose => 0)->jmx4perl;
14 | my $req = new JMX::Jmx4Perl::Request(WRITE,"jolokia.it:type=attribute","ObjectName","java.lang:type=Memory");
15 | my $resp = $jmx->request($req);
16 | #print Dumper(\$resp);
17 | my $value = $resp->{value};
18 | is($value->{objectName},"bla:type=blub","Set ObjectName: Old Name returned");
19 |
20 | $value = $jmx->get_attribute("jolokia.it:type=attribute","ObjectName");
21 | is($value->{objectName},"java.lang:type=Memory","Set ObjectName: New Name set");
22 |
23 |
24 |
25 | $jmx->execute("jolokia.it:type=attribute","reset");
26 |
27 |
--------------------------------------------------------------------------------
/it/t/10_base.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More qw(no_plan);
5 | #use Test::More tests => $ENV{JMX4PERL_PRODUCT} ? 2 : 1;
6 |
7 | BEGIN { use_ok("JMX::Jmx4Perl"); }
8 |
9 | my $jmx = new It()->jmx4perl;
10 |
11 | my $product = $ENV{JMX4PERL_PRODUCT};
12 | # Test autodetection
13 | if ($product) {
14 | my $jmx_auto = new JMX::Jmx4Perl(map { $_ => $jmx->cfg($_) } qw(url user password));
15 | $jmx_auto->info;
16 | is($jmx_auto->product->id,$product,"Autodetected proper server " . $product);
17 | }
18 |
19 | # Test info and detected handler
20 | my $info = $jmx->info();
21 | my $info_product = $1 if $info =~ /^Name:\s+(.*)/m;
22 | my $info_version = $1 if $info =~ /^Version:\s+(.*)/m;
23 | is($jmx->product->name,$info_product || "unknown","Product name match");
24 | is($jmx->product->version,$info_version,"Product version match") if $info_version;
25 |
26 |
--------------------------------------------------------------------------------
/t/50_config.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | use Test::More;
3 | use FindBin qw($Bin);
4 | use Data::Dumper;
5 | use JMX::Jmx4Perl::Config;
6 |
7 | my $HAS_CONFIG_GENERAL;
8 | BEGIN {
9 | eval "use Config::General";
10 | $HAS_CONFIG_GENERAL = $@ ? 0 : 1;
11 | }
12 | plan tests => $HAS_CONFIG_GENERAL ? 4 : 1;
13 | $SIG{__WARN__} = sub { };
14 | my $config = new JMX::Jmx4Perl::Config("$Bin/j4p_test.cfg");
15 | if ($HAS_CONFIG_GENERAL) {
16 | is(scalar(keys(%{$config->{server_config}})),2,"2 configuration entries read in");
17 | ok($config->server_config_exists("jboss"),"JBoss configuration exists");
18 | my $s = $config->get_server_config("weblogic");
19 | is($s->{product},"Weblogic","Proper product found");
20 | is(scalar(keys(%$s)),5,"Correct number of config elements");
21 | } else {
22 | ok(scalar(keys(%{$config->{config}})) == 0,"No config read in");
23 | }
24 |
--------------------------------------------------------------------------------
/it/t/84_exec.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More qw(no_plan);
5 | use JMX::Jmx4Perl;
6 | use JMX::Jmx4Perl::Request;
7 | use Data::Dumper;
8 | #use Test::More tests => $ENV{JMX4PERL_PRODUCT} ? 2 : 1;
9 |
10 |
11 | # Fetch all attributes
12 | my $jmx = new It(verbose => 0)->jmx4perl;
13 | my $req = new JMX::Jmx4Perl::Request(EXEC,{ mbean => "jolokia.it:type=operation", operation => "mapArgument",arguments => [{ name => "Kyotake"}],method => "POST"} );
14 | my $resp = $jmx->request($req);
15 | my $value = $resp->{value};
16 | is(ref($resp->{value}),"HASH","Response type");
17 | is($resp->{value}->{name},"Kyotake","Response value");
18 |
19 | $value = $jmx->execute("jolokia.it:type=operation","findTimeUnit","MINUTES");
20 | is($value,"MINUTES","Enum serialization up and done");
21 |
22 | $value = $jmx->execute("jolokia.it:type=operation","addBigDecimal",1,"1e3");
23 | is($value,1001,"Adding big decimal");
24 | #print Dumper($resp);
25 |
--------------------------------------------------------------------------------
/it/t/99_discovery.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More qw(no_plan);
5 | use JMX::Jmx4Perl;
6 | use Data::Dumper;
7 | use strict;
8 |
9 | my $jmx = new It(verbose => 0)->jmx4perl;
10 |
11 | # Might find nothing, dependening on where it is run.
12 | my $disc_class = urls(JMX::Jmx4Perl->discover_agents());
13 | ok(defined($disc_class));
14 | my $disc_obj = urls($jmx->discover_agents());
15 | ok(defined($disc_obj));
16 |
17 | my $agents_found = $jmx->execute("jolokia:type=Discovery","lookupAgents");
18 | print Dumper($agents_found);
19 | print Dumper($disc_class);
20 | my $agent_urls = urls($agents_found);
21 |
22 | for my $disc_p ($disc_class,$disc_obj) {
23 | for my $k (keys %$disc_p) {
24 | ok(defined($agent_urls->{$k}),"Agent URL " . $k . " detected");
25 | }
26 | }
27 |
28 | sub urls {
29 | my $agents = shift;
30 | my $ret = {};
31 | for my $agent (@$agents) {
32 | $ret->{$agent->{url}}++;
33 | }
34 | return $ret;
35 | }
36 |
--------------------------------------------------------------------------------
/config/common.cfg:
--------------------------------------------------------------------------------
1 |
2 | # Common check definitions which can be used
3 | # as a base for more specific configurations
4 |
5 | # This are mostly convenience, abstract checks
6 | # which are meant to be mixed into more concrete
7 | # checks
8 |
9 | # =================================================
10 |
11 | # A nice label to be used for relative values
12 |
13 | Label = %.2r% used (%.2v %u / %.2b %w)
14 | # Default values for critical (90%) and warning (80%) thresholds
15 | Critical = ${0:90}
16 | Warning = ${1:80}
17 |
18 |
19 | # A incremental check for values per minute
20 | # $0: used in label to specify what is counted
21 | # per minute
22 |
23 | Label = %2.2f $0/minute
24 | Delta = 60
25 |
26 |
27 | # A incremental check for values per hour
28 | # $0: used in label to specify what is counted
29 | # per hour
30 |
31 | Label = %2.2f $0/hour
32 | Delta = 3600
33 |
34 |
35 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/aix.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::aix;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Platform::Unix;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Platform::Unix);
11 |
12 | # This class isn't necessary anymore, but we can't delete it, because
13 | # some people might still have the old copy in their @INC, containing
14 | # code we don't want to execute, so we have to make sure an upgrade
15 | # will replace it with this empty subclass.
16 |
17 | 1;
18 | __END__
19 |
20 |
21 | =head1 NAME
22 |
23 | Module::Build::Platform::aix - Builder class for AIX platform
24 |
25 | =head1 DESCRIPTION
26 |
27 | This module provides some routines very specific to the AIX
28 | platform.
29 |
30 | Please see the L for the general docs.
31 |
32 | =head1 AUTHOR
33 |
34 | Ken Williams
35 |
36 | =head1 SEE ALSO
37 |
38 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
39 |
40 | =cut
41 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/darwin.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::darwin;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Platform::Unix;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Platform::Unix);
11 |
12 | # This class isn't necessary anymore, but we can't delete it, because
13 | # some people might still have the old copy in their @INC, containing
14 | # code we don't want to execute, so we have to make sure an upgrade
15 | # will replace it with this empty subclass.
16 |
17 | 1;
18 | __END__
19 |
20 |
21 | =head1 NAME
22 |
23 | Module::Build::Platform::darwin - Builder class for Mac OS X platform
24 |
25 | =head1 DESCRIPTION
26 |
27 | This module provides some routines very specific to the Mac OS X
28 | platform.
29 |
30 | Please see the L for the general docs.
31 |
32 | =head1 AUTHOR
33 |
34 | Ken Williams
35 |
36 | =head1 SEE ALSO
37 |
38 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
39 |
40 | =cut
41 |
--------------------------------------------------------------------------------
/it/t/51_check_relative.t:
--------------------------------------------------------------------------------
1 | use strict;
2 | use warnings;
3 | use Test::More qw(no_plan);
4 | use Data::Dumper;
5 | use It;
6 |
7 | require "check_jmx4perl/base.pl";
8 |
9 | my $jmx = It->new(verbose =>0)->jmx4perl;
10 | my ($ret,$content);
11 |
12 |
13 | # ====================================================
14 | # Relative value checks
15 | my %s = (
16 | ":90" => [ 0, "OK" ],
17 | "0.2:" => [ 0, "OK" ],
18 | ":0.2" => [ 1, "WARNING" ],
19 | "81:82" => [ 1, "WARNING" ]
20 | );
21 |
22 | my @args = ();
23 |
24 | for my $base (qw(MEMORY_HEAP_MAX java.lang:type=Memory/HeapMemoryUsage/max 1000000000)) {
25 | push @args,"--alias MEMORY_HEAP_USED --base $base"
26 | }
27 | push @args,"--alias MEMORY_HEAP_USED --base-mbean java.lang:type=Memory --base-attribute=HeapMemoryUsage --base-path=max";
28 |
29 | for my $arg (@args) {
30 | for my $k (keys %s) {
31 | ($ret,$content) = exec_check_perl4jmx("$arg -w $k");
32 | #print Dumper($ret,$content);
33 | is($ret,$s{$k}->[0],"$arg -w $k : $ret");
34 | ok($content =~ /^$s{$k}->[1]/,"$arg -w $k : " . $s{$k}->[1]);
35 | }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/config/threads.cfg:
--------------------------------------------------------------------------------
1 | # Predefined checks for fetching thread statistics
2 | # from MXBeans
3 | # ==================================================
4 |
5 | include common.cfg
6 |
7 | # Check for a thread increase per minute
8 | # $0 : Critical threshold (default: 60)
9 | # $1 : Warning threshold (default: 30)
10 |
11 | Use = count_per_minute("Threads")
12 | Value = java.lang:type=Threading/ThreadCount
13 | Name = Thread-Increase
14 | Critical = ${0:~:60}
15 | Warning = ${1:~:30}
16 |
17 |
18 | # Check for monitoring the total (absolute) count of threads
19 | # active within an application
20 | # $0 : Critical threshold (default: 1000)
21 | # $1 : Warning threshold (default: 800)
22 |
23 | Value = java.lang:type=Threading/ThreadCount
24 | Name = Thread-Count
25 | Critical = ${0:1000}
26 | Warning = ${1:800}
27 |
28 |
29 | # Find deadlocked Threads
30 |
31 | MBean = java.lang:type=Threading
32 | Operation = findDeadlockedThreads
33 | Null = no deadlock
34 | Name = Thread-Deadlock
35 | String = 1
36 | Critical = !no deadlock
37 |
38 |
--------------------------------------------------------------------------------
/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | # ==================================================
2 | # Dockerfile for jmx4perl Tools
3 | # ==================================================
4 | FROM alpine:3.11
5 |
6 | # The less command from alpine does not interpret color escapes (no -R switch)
7 | ENV JMX4PERL_VERSION=1.13 PAGER=cat
8 |
9 | RUN apk add --update \
10 | build-base \
11 | wget \
12 | perl \
13 | perl-dev \
14 | readline \
15 | readline-dev \
16 | ncurses \
17 | ncurses-dev \
18 | libxml2-dev \
19 | expat-dev \
20 | gnupg1 \
21 | openssl \
22 | openssl-dev \
23 | && cpan App::cpanminus < /dev/null \
24 | && cpanm install -n Term::ReadLine::Gnu \
25 | && cpanm install Term::ReadKey \
26 | JSON::XS \
27 | LWP::Protocol::https \
28 | XML::LibXML \
29 | Term::Clui \
30 | && cpanm install ROLAND/jmx4perl-${JMX4PERL_VERSION}.tar.gz \
31 | && rm -rf /var/cache/apk/* \
32 | && apk del \
33 | build-base \
34 | perl-dev \
35 | readline-dev \
36 | ncurses-dev \
37 | expat-dev \
38 | openssl-dev \
39 | && mkdir /jolokia
40 |
41 | WORKDIR /jolokia
42 | VOLUME /jolokia
43 |
44 | CMD [ "jmx4perl", "--version" ]
45 |
--------------------------------------------------------------------------------
/it/t/01_version.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More tests => 1;
5 | use strict;
6 | use JMX::Jmx4Perl::Request;
7 | use JMX::Jmx4Perl;
8 | use Data::Dumper;
9 |
10 | my $jmx = new It(verbose => 0)->jmx4perl;
11 |
12 | my $resp = $jmx->request(new JMX::Jmx4Perl::Request(AGENT_VERSION));
13 | my $value = $resp->{value};
14 | my $version_exp = $JMX::Jmx4Perl::VERSION;
15 | my ($base,$ext) = ($1,$3) if $version_exp =~ /^([\d.]+)(_(\d+))?$/;
16 | $base = $base . ".0" unless $base =~ /^\d+\.\d+\.\d+$/;
17 | $version_exp = $base . ($ext ? ".M" . $ext : "");
18 | my $agent_version = $value->{agent};
19 | if ($agent_version =~ /(\d+)\.(\d+)\.(\d+)(-SNAPSHOT)?/) {
20 | $agent_version = "$1.$2$3";
21 | }
22 | #ok($agent_version >= $version_exp,"Jolokia-version " . $value->{agent} . " >= Jmx4Perl Version " . $version_exp);
23 | print "Agent-Version:\n";
24 | print Dumper($value);
25 | ok($value->{protocol} > 0,"Protocol version " . $value->{protocol});
26 | #print Dumper(\@resps);
27 | my $resp = $jmx->request(new JMX::Jmx4Perl::Request(READ,"java.lang:type=Runtime","SystemProperties"));
28 | $value = $resp->{value};
29 | print "Java: ",$value->{'java.version'}," (",$value->{'java.vendor'},")\n";
30 |
--------------------------------------------------------------------------------
/t/60_parse_name.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use strict;
4 | use warnings;
5 | use JMX::Jmx4Perl;
6 | use Data::Dumper;
7 | use Test::More tests => 16;
8 |
9 | my $data =
10 | {
11 | "jmx4perl:lang=java,type=class" => [ "jmx4perl",{ lang => "java", type => "class"} ],
12 | "jmx4perl:lang=java,type=class" => [ "jmx4perl",{ lang => "java", type => "class"} ],
13 | "jmx4perl:lang=java:perl,type=x" => [ "jmx4perl",{ lang => "java:perl", type => "x"} ],
14 | "jmx4perl:lang=\"A\\*B\",type=\",\"" => [ "jmx4perl",{ lang => "A*B", type => ","} ],
15 | "jmx4perl:lang=\"A\\,B\",type=x" => [ "jmx4perl",{ lang => "A,B", type => "x"} ],
16 | 'jmx4perl:name="\\"\\"\\"",type=escape' => [ "jmx4perl", { name => '"""', type => "escape" }],
17 | "bla:blub" => [ undef, undef ],
18 | "bla:blub=" => [ undef, undef ],
19 | "sDSDSADSDA" => [ undef, undef]
20 | };
21 |
22 | my $jmx4perl = new JMX::Jmx4Perl(url => "localhost");
23 | for my $k (sort keys %$data) {
24 | my ($domain,$attr) = $jmx4perl->parse_name($k);
25 | my $expected = $data->{$k};
26 | # print Dumper($attr);
27 | is($domain,$expected->[0],"Domain: " . ($domain ? $domain : "(undef)"));
28 | is_deeply($attr,$expected->[1],"Attributes for $k");
29 | }
30 |
--------------------------------------------------------------------------------
/config/websphere.cfg:
--------------------------------------------------------------------------------
1 | # Websphere Checks
2 | # ----------------
3 |
4 | # These checks are for WebSphere and has been tested for WebSphere >= 8.0
5 | # (but should workd with older WebSphere servers as well).
6 |
7 | # For most of the test it is required that a customzied Jolokia agent is used
8 | # which provides simplified access to JSR-77 metrics.
9 | #
10 | # These agents can be obtained from the 'jolokia-extra' project: https://github.com/rhuss/jolokia-extra
11 | # or downloaded from Maven central: http://central.maven.org/maven2/org/jolokia/extra/
12 | # They all have an classifier "-jsr77" and the first three parts of the version specify
13 | # the Jolokia core version included.
14 | # E.g. "jolokia-extra-war-1.2.2.2-jsr77.war" contains Jolokia 1.2.2 (and is the second variant with
15 | # the JSR-77 specifier)
16 |
17 | # Most of these tests utilize the PMI subsystem of WebSphere.
18 |
19 | # ===============================================================
20 | # Including various checks. These config files are self contained,
21 | # and for performance optimizations could be included separately if only
22 | # some checks are needed.
23 |
24 | include websphere/threads.cfg
25 | include websphere/http.cfg
26 | include websphere/jdbc.cfg
27 | include websphere/jms.cfg
28 | include websphere/jca.cfg
29 | include websphere/appstate.cfg
30 |
31 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Config.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Config;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Config;
8 |
9 | sub new {
10 | my ($pack, %args) = @_;
11 | return bless {
12 | stack => {},
13 | values => $args{values} || {},
14 | }, $pack;
15 | }
16 |
17 | sub get {
18 | my ($self, $key) = @_;
19 | return $self->{values}{$key} if ref($self) && exists $self->{values}{$key};
20 | return $Config{$key};
21 | }
22 |
23 | sub set {
24 | my ($self, $key, $val) = @_;
25 | $self->{values}{$key} = $val;
26 | }
27 |
28 | sub push {
29 | my ($self, $key, $val) = @_;
30 | push @{$self->{stack}{$key}}, $self->{values}{$key}
31 | if exists $self->{values}{$key};
32 | $self->{values}{$key} = $val;
33 | }
34 |
35 | sub pop {
36 | my ($self, $key) = @_;
37 |
38 | my $val = delete $self->{values}{$key};
39 | if ( exists $self->{stack}{$key} ) {
40 | $self->{values}{$key} = pop @{$self->{stack}{$key}};
41 | delete $self->{stack}{$key} unless @{$self->{stack}{$key}};
42 | }
43 |
44 | return $val;
45 | }
46 |
47 | sub values_set {
48 | my $self = shift;
49 | return undef unless ref($self);
50 | return $self->{values};
51 | }
52 |
53 | sub all_config {
54 | my $self = shift;
55 | my $v = ref($self) ? $self->{values} : {};
56 | return {%Config, %$v};
57 | }
58 |
59 | 1;
60 |
--------------------------------------------------------------------------------
/it/t/56_check_value.t:
--------------------------------------------------------------------------------
1 | use strict;
2 | use warnings;
3 | use Test::More qw(no_plan);
4 | use Data::Dumper;
5 | use JMX::Jmx4Perl::Alias;
6 | use It;
7 |
8 | require "check_jmx4perl/base.pl";
9 |
10 | my $jmx = It->new(verbose =>0)->jmx4perl;
11 | my ($ret,$content);
12 |
13 | # ====================================================
14 | # Check for --value
15 |
16 | ($ret,$content) = exec_check_perl4jmx("--value java.lang:type=Memory/HeapMemoryUsage/used " .
17 | "--base java.lang:type=Memory/HeapMemoryUsage/max " .
18 | "--critical 90 ");
19 | is($ret,0,"Memory with value OK");
20 | ok($content =~ /^OK/,"Content contains OK");
21 |
22 | # TODO: Check escaping
23 | ($ret,$content) = exec_check_perl4jmx("--value jolokia.it:name=\\/\\/server\\/client,type=naming\\//Ok " .
24 | "--critical OK");
25 | #print Dumper($ret,$content);
26 | is($ret,2,"CRITICAL expected");
27 | ok($content =~ m|jolokia.it:name=\\/\\/server\\/client,type=naming\\//Ok|,"Content contains MBean name");
28 |
29 | ($ret,$content) = exec_check_perl4jmx("--value jolokia.it:type=naming\\/,name=\\\"jdbc/testDB\\\"/Ok " .
30 | "--critical OK");
31 | is($ret,2,"CRITICAL expected");
32 | ok($content =~ m|jolokia.it:type=naming\\/,name="jdbc/testDB"/Ok|,"Content contains weired MBean name");
33 |
--------------------------------------------------------------------------------
/MANIFEST.SKIP:
--------------------------------------------------------------------------------
1 | # Avoid version control files.
2 | \bRCS\b
3 | \bCVS\b
4 | ,v$
5 | \B\.svn\b
6 | \B\.cvsignore$
7 | \B\.gitignore$
8 |
9 | # Avoid Makemaker generated and utility files.
10 | \bMakefile$
11 | \bblib
12 | \bMakeMaker-\d
13 | \bpm_to_blib$
14 | \bblibdirs$
15 | ^MANIFEST\.SKIP$
16 |
17 | # Avoid VMS specific Makmaker generated files
18 | \bDescrip.MMS$
19 | \bDESCRIP.MMS$
20 | \bdescrip.mms$
21 |
22 | # Avoid Module::Build generated and utility files.
23 | \bBuild$
24 | \bBuild.bat$
25 | \b_build
26 | \bBuild.COM$
27 | \bBUILD.COM$
28 | \bbuild.com$
29 |
30 | # Avoid Devel::Cover generated files
31 | \bcover_db
32 |
33 | # Avoid temp and backup files.
34 | ~$
35 | \.tmp$
36 | \.old$
37 | \.bak$
38 | \#$
39 | \.#
40 | \.rej$
41 | \.ipr$
42 | \.iws$
43 | \.iml$
44 |
45 | # Avoid OS-specific files/dirs
46 | # Mac OSX metadata
47 | \B\.DS_Store
48 | # Mac OSX SMB mount metadata files
49 | \B\._
50 | # Avoid archives of this distribution
51 | \bjmx4perl-[\d\.\_]+
52 |
53 | # Java build directory
54 | \bagent/target\b
55 |
56 | ^test.pl$
57 | scripts/handlerTest.pl
58 | ^TODO$
59 | ^tmp
60 | ^.git/.*
61 | .*/target/.*
62 | temp/.*
63 | kurs.txt
64 | x.pl
65 | agent/j4p-it.war
66 | agent/j4p-access.xml$
67 | jboss_attr.txt
68 | site/.*
69 | x/.*
70 | it/test_log.txt
71 | jmx_remote.txt
72 | release.txt
73 | agent/modules/j4p-osgi/runner/*
74 | osgi.txt
75 | MYMETA.yml
76 | blog_ideas.txt
77 | agent/.sonar-ide.properties
78 | docs/
79 | agent/classes
80 | ^MYMETA\.json$
81 |
--------------------------------------------------------------------------------
/config/metrics.cfg:
--------------------------------------------------------------------------------
1 | # Checks for Metrics (http://metrics.codahale.com/)
2 | # =================================================
3 |
4 |
5 |
6 | MBean = $0:type=$1,name=$2
7 | Label = $0.$2 / $1
8 |
9 |
10 | #
11 | #
12 | #
13 |
14 | Use = metrics_base($1,$2,$3)
15 | Attribute = $0
16 | Label = $0 for $BASE : %v %u
17 | Name = $0
18 | Critical = $4
19 | Warning = $5
20 | Unit = ${6:ms}
21 |
22 |
23 |
24 | Check metrics_timer_base("Mean",$0,$1,$2,$3,$4,$5)
25 | Check metrics_timer_base("StdDev",$0,$1,$2,$3,$4,$5)
26 | Check metrics_timer_base("Min",$0,$1,$2,$3,$4,$5)
27 | Check metrics_timer_base("Max",$0,$1,$2,$3,$4,$5)
28 |
29 |
30 |
31 | Check metrics_timer_base("50thPercentile",$0,$1,$2,$3,$4,$5)
32 | Check metrics_timer_base("75thPercentile",$0,$1,$2,$3,$4,$5)
33 | Check metrics_timer_base("95thPercentile",$0,$1,$2,$3,$4,$5)
34 | Check metrics_timer_base("99thPercentile",$0,$1,$2,$3,$4,$5)
35 | Check metrics_timer_base("999thPercentile",$0,$1,$2,$3,$4,$5)
36 |
37 |
38 |
39 | Check metrics_timer_base("MeanRate",$0,$1,$2,$3,$4,$5)
40 | Check metrics_timer_base("OneMinuteRate",$0,$1,$2,$3,$4,$5)
41 | Check metrics_timer_base("FiveMinuteRate",$0,$1,$2,$3,$4,$5)
42 | Check metrics_timer_base("FifteenMinuteRate",$0,$1,$2,$3,$4,$5)
43 |
44 |
--------------------------------------------------------------------------------
/config/websphere/threads.cfg:
--------------------------------------------------------------------------------
1 | # ============================================
2 | # Thread Pool Checks
3 |
4 | # Generic Thread-Pool Check for the size of a Thread-Pool
5 | #
6 | # $0: Name of ThreadPool (z.B. "WebContainer")
7 | # $1: Critical (default: 90%)
8 | # $2: Warning (default: 80%)
9 |
10 | Use was_thread_pool($0,'PoolSize',$1,$2)
11 | Label $0: %2.2r% threads used (%v / %b)
12 |
13 |
14 | # Generic Thread-Pool Check for the number of active threads
15 | # within the thread pool
16 | #
17 | # $0: Name of ThreadPool (z.B. "WebContainer")
18 | # $1: Critical (default: 90%)
19 | # $2: Warning (default: 80%)
20 |
21 | Use was_thread_pool($0,'ActiveCount',$1,$2,)
22 | Label $0: %2.2r% active threads (%v / %b)
23 |
24 |
25 | # Base Check for thread-pools checks
26 | # $0: Name of ThreadPool (z.B. "WebContainer")
27 | # $1: Attribute (PoolSize or ActiveCount)
28 | # $2: Critical (default: 90%)
29 | # $3: Warning (default: 80%)
30 |
31 | MBean WebSphere:name=${0},type=ThreadPool,*
32 | Attribute stats
33 | Path */*/statistics/${1}/current
34 |
35 | BaseMBean WebSphere:name=${0},type=ThreadPool,*
36 | BaseAttribute stats
37 | BasePath */*/statistics/${1}/upperBound
38 |
39 | Critical ${2:90}
40 | Warning ${3:80}
41 |
42 | Label = ${0}: %.2r% Threads [${1}] (%v / %b)
43 | Name = ${0}-${1}-threadpool
44 |
45 |
46 |
--------------------------------------------------------------------------------
/it/t/30_naming.t:
--------------------------------------------------------------------------------
1 | # -*- mode: cperl -*-
2 |
3 | use It;
4 | use strict;
5 | use warnings;
6 | use Test::More qw(no_plan);
7 | use File::Temp qw/tmpnam/;
8 | use Data::Dumper;
9 |
10 | BEGIN { use_ok("JMX::Jmx4Perl"); }
11 |
12 | my $jmx = It->new(verbose => 0)->jmx4perl;
13 |
14 | my $name_p = "jolokia.it:type=naming/,name=%s";
15 | my @names =
16 | (
17 | "/slash-simple/",
18 | "simple",
19 | "/--/",
20 | "with%3acolon",
21 | "//server/client",
22 | "service%3ajmx%3armi%3a///jndi/rmi%3a//bhut%3a9999/jmxrmi",
23 | "name with space",
24 | "n!a!m!e with !/!"
25 | # "äöüßÄÖÜ"
26 | );
27 |
28 | my @searches =
29 | (
30 | [ "*:name=//server/client,*", qr#(jmx4perl|jolokia)\.it(\.hidden)?:.*name=//server/client# ]
31 | );
32 |
33 | # Basic check:
34 | for my $name (@names) {
35 | my $mbean = search($jmx,sprintf($name_p,$name));
36 | my $scalar = $jmx->get_attribute($mbean,"Ok");
37 | is($scalar,"OK",$name);
38 | }
39 |
40 |
41 | for my $s (@searches) {
42 | my $r = $jmx->search($s->[0]);
43 | #print Dumper($r);
44 | ok($r->[0] =~ $s->[1],"Search " . $s->[0]);
45 | }
46 |
47 | sub search {
48 | my $jmx = shift;
49 | my $prefix = shift;
50 | my $ret = $jmx->search($prefix . ",*");
51 | #print Dumper($ret);
52 | if (!defined($ret)) {
53 | fail("Search " . $prefix . ",* gives no result");
54 | exit;
55 | }
56 | is(scalar(@$ret),1,"One MBean found");
57 | return $ret->[0];
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/config/websphere/jca.cfg:
--------------------------------------------------------------------------------
1 | # ===============================================================
2 | # JCA
3 |
4 | # JCA connector pool usage
5 | #
6 | # ${0} : part of the JCA connector name
7 | # ${1} : Managed Connection Factory Name (JCA)
8 | # ${2} : Critical (default: 90 percent)
9 | # ${3} : Warning (default: 80 percent)
10 |
11 | MBean WebSphere:j2eeType=JCAResource,mbeanIdentifier=*${0}*,*
12 | Attribute stats
13 | Path */*/connectionPools/${1}/statistics/PercentUsed/current
14 |
15 | Critical ${2:90}
16 | Warning ${3:80}
17 |
18 | Label $1 : %2.0f% connections used
19 | Name jca-${1}-${0}-pool
20 |
21 |
22 | # Average waiting time until a JCA connector is available
23 | #
24 | # ${0} : part of the JCA resource name as it appears in the mbeanIdentifier
25 | # ${1} : Managed Connection Factory Name (JCA)
26 | # ${2} : Critical (default: 10s)
27 | # ${3} : Warning (default: 5s)
28 |
29 | MBean WebSphere:j2eeType=JCAResource,mbeanIdentifier=*${0}*,*
30 | Attribute stats
31 | Path */*/connectionPools/${1}/statistics/WaitTime/totalTime
32 |
33 | BaseMBean WebSphere:j2eeType=JCAResource,mbeanIdentifier=${0},*
34 | BaseAttribute stats
35 | BasePath */*/connectionPools/${1}/statistics/WaitTime/count
36 |
37 | Critical ${2:10000}
38 | Warning ${3:5000}
39 |
40 | Label $1: %2.2q ms ∅ wait time (%v ms total for %b requests)
41 | Name jca-${1}-${0}-wait-time
42 |
43 |
44 |
--------------------------------------------------------------------------------
/it/t/50_check_base.t:
--------------------------------------------------------------------------------
1 | use strict;
2 | use warnings;
3 | use Test::More qw(no_plan);
4 | use Data::Dumper;
5 | use It;
6 |
7 | require "check_jmx4perl/base.pl";
8 |
9 | my $jmx = It->new(verbose =>1)->jmx4perl;
10 | my ($ret,$content);
11 |
12 | # ====================================================
13 | # Basic checks
14 | my %s = (
15 | ":10000000000" => [ 0, "OK" ],
16 | "0.2:" => [ 0, "OK" ],
17 | ":0.2" => [ 2, "CRITICAL" ],
18 | "5:6" => [ 2, "CRITICAL" ]
19 | );
20 | for my $k (keys %s) {
21 | ($ret,$content) = exec_check_perl4jmx("--mbean java.lang:type=Memory --attribute HeapMemoryUsage",
22 | "--path used -c $k");
23 | #print Dumper($ret,$content);
24 | is($ret,$s{$k}->[0],"Memory -c $k : $ret");
25 | ok($content =~ /^$s{$k}->[1]/m,"Memory -c $k : " . $s{$k}->[1]);
26 | }
27 |
28 | # ====================================================
29 | # Alias attribute checks
30 |
31 | for my $k (keys %s) {
32 | ($ret,$content) = exec_check_perl4jmx("--alias MEMORY_HEAP_USED -c $k --method post");
33 | #print Dumper($ret,$content);
34 | is($ret,$s{$k}->[0],"MEMORY_HEAP_USED -c $k : $ret");
35 | ok($content =~ /^$s{$k}->[1]/m,"MEMORY_HEAP_USED $k : " . $s{$k}->[1]);
36 | }
37 |
38 | ($ret,$content) = exec_check_perl4jmx("--mbean java.lang:type=Memory --attribute HeapMemoryUsage --path used");
39 | is($ret,0,"No warning and no critical is always success");
40 | ok($content =~ /in range/,"Data has been povided");
41 |
--------------------------------------------------------------------------------
/t/10_handler.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use strict;
4 | use warnings;
5 | use FindBin qw($Bin);
6 | use lib qq($Bin/lib);
7 | use JMX::Jmx4Perl::Alias;
8 | use Data::Dumper;
9 | use Test::More tests => 10;
10 |
11 | BEGIN { use_ok("JMX::Jmx4Perl"); }
12 |
13 | # Use a new handler directory
14 | &JMX::Jmx4Perl::_register_handlers("ProductTest");
15 |
16 | my $jmx4perl = new JMX::Jmx4Perl(url => "localhost");
17 | my @res = $jmx4perl->resolve_alias("memory:heap");
18 | ok(@res && $res[0] eq "resolved_name" && $res[1] eq "resolved_attr","Resolved alias properly");
19 |
20 | $jmx4perl = new JMX::Jmx4Perl(url => "localhost", product => "Test2");
21 | my @alias = $jmx4perl->resolve_alias("memory:heap");
22 | ok(@alias && $alias[0] eq "resolved2_name" && $alias[1] eq "resolved2_attr","Resolved alias properly");
23 | @alias = $jmx4perl->resolve_alias("MEMORY_GC");
24 | ok(@alias && $alias[0] eq "memory2_name" && $alias[1] eq "gc2_op","Resolved operation alias properly");
25 |
26 | is($JMX::Jmx4Perl::PRODUCT_HANDLER_ORDERING[0],"test2","Test ordering");
27 | is($JMX::Jmx4Perl::PRODUCT_HANDLER_ORDERING[1],"test1","Test ordering");
28 |
29 | $jmx4perl = new JMX::Jmx4Perl(url => "localhost");
30 | @res = $jmx4perl->resolve_alias(SERVER_NAME);
31 | is($res[0],"server","Check for alias resolving by closure");
32 | is($res[1],"name","Check for alias resolving by closure");
33 | my $code = $jmx4perl->resolve_alias(SERVER_ADDRESS);
34 | is(ref($code),"CODE","Check for code based resolving");
35 | is($code->(),"127.0.0.1","Check for code based resolving");
36 |
--------------------------------------------------------------------------------
/it/t/85_path_escaping.t:
--------------------------------------------------------------------------------
1 | # -*- mode: cperl -*-
2 |
3 | use It;
4 | use strict;
5 | use warnings;
6 | use Test::More tests => 16;
7 | use File::Temp qw/tmpnam/;
8 | use Data::Dumper;
9 | use JMX::Jmx4Perl::Request;
10 |
11 | my $jmx = It->new(verbose => 0)->jmx4perl;
12 |
13 | my ($req,$resp,$list);
14 | for my $method ("post","get") {
15 | $req = new JMX::Jmx4Perl::Request(READ,"jolokia.it:type=attribute","ComplexNestedValue","Blub/1/numbers/1",{method => $method});
16 | $resp = $jmx->request($req);
17 | is($resp->{value},23);
18 | for my $path ("",undef,"/") {
19 | $req = new JMX::Jmx4Perl::Request(READ,"jolokia.it:type=attribute","Map",$path,{method => $method});
20 | $resp = $jmx->request($req);
21 | is($resp->{value}->{fcn},"meister");
22 | $req = new JMX::Jmx4Perl::Request(LIST,$path,{method => $method});
23 | $resp = $jmx->request($req);
24 | ok($resp->{value}->{'jolokia.it'});
25 | }
26 | $req = new JMX::Jmx4Perl::Request(LIST,"/java.lang/",{method => $method});
27 | $resp = $jmx->request($req);
28 | #print Dumper($resp);
29 | }
30 |
31 | $list = $jmx->list("jolokia.it/name=!/!/server!/client,type=naming!//attr");
32 | is($list->{Ok}->{type},"java.lang.String");
33 | #my $list = $jmx->list("jolokia.it");
34 | $req = new JMX::Jmx4Perl::Request(LIST,"jolokia.it/name=!/!/server!/client,type=naming!//attr",{method => "POST"});
35 | $resp = $jmx->request($req);
36 | #print Dumper($resp);
37 | is($resp->{value}->{Ok}->{type},"java.lang.String");
38 |
39 |
--------------------------------------------------------------------------------
/examples/remote.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use JMX::Jmx4Perl;
4 | use JMX::Jmx4Perl::Request;
5 | use JMX::Jmx4Perl::Alias;
6 | use Data::Dumper;
7 | use Time::HiRes qw(gettimeofday tv_interval);
8 | my $jmx = new JMX::Jmx4Perl(url => "http://localhost:8888/jolokia-proxy",
9 | target => {
10 | url => "service:jmx:rmi:///jndi/rmi://bhut:9999/jmxrmi",
11 | env => {
12 | user => "monitorRole",
13 | password => "consol",
14 | }
15 | }
16 | );
17 | my $req1 = new JMX::Jmx4Perl::Request(READ,{
18 | mbean => "java.lang:type=Memory",
19 | attribute => "HeapMemoryUsage",
20 | }
21 | );
22 | my $req2 = new JMX::Jmx4Perl::Request(LIST);
23 | my $req3 = new JMX::Jmx4Perl::Request(READ,{
24 | mbean => "jboss.system:type=ServerInfo",
25 | attribute => "HostAddress"
26 | }
27 | );
28 | my $t0 = [gettimeofday];
29 | my @resp = $jmx->request($req3);
30 | print "Duration: ",tv_interval($t0,[gettimeofday]),"\n";
31 | print Dumper(@resp);
32 |
--------------------------------------------------------------------------------
/it/t/70_overloaded_method.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More qw(no_plan);
5 | use JMX::Jmx4Perl;
6 | use JMX::Jmx4Perl::Request;
7 | use Data::Dumper;
8 | #use Test::More tests => $ENV{JMX4PERL_PRODUCT} ? 2 : 1;
9 |
10 |
11 | my $jmx = new It(verbose => 0)->jmx4perl;
12 | my $req = new JMX::Jmx4Perl::Request(EXEC,"jolokia.it:type=operation", "overloadedMethod","bla");
13 | my $resp = $jmx->request($req);
14 | ok($resp->{error},"Error must be set");
15 | $req = new JMX::Jmx4Perl::Request(EXEC,"jolokia.it:type=operation", "overloadedMethod()");
16 | $resp = $jmx->request($req);
17 | is($resp->{value},0,"No-Arg operation called");
18 | $req = new JMX::Jmx4Perl::Request(EXEC,"jolokia.it:type=operation", "overloadedMethod(java.lang.String)","bla");
19 | $resp = $jmx->request($req);
20 | is($resp->{value},1,"First operation called");
21 | $req = new JMX::Jmx4Perl::Request(EXEC,"jolokia.it:type=operation", "overloadedMethod(java.lang.String,int)","bla",1);
22 | $resp = $jmx->request($req);
23 | #print Dumper($resp);
24 | is($resp->{value},2,"Second operation called");
25 | $req = new JMX::Jmx4Perl::Request(EXEC,"jolokia.it:type=operation", "overloadedMethod([Ljava.lang.String;)","bla,blub");
26 | $resp = $jmx->request($req);
27 | #print Dumper($resp);
28 | is($resp->{value},3,"Third operation called");
29 | $req = new JMX::Jmx4Perl::Request(EXEC,"jolokia.it:type=operation", "overloadedMethod(java.lang.String,int,long)","bla",3,3);
30 | $resp = $jmx->request($req);
31 | ok($resp->{error},"No such method");
32 | #print Dumper($resp);
33 | #print Dumper(\@resps);
34 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Agent/Jolokia/Verifier/PGPKey.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | package JMX::Jmx4Perl::Agent::Jolokia::Verifier::PGPKey;
4 |
5 | use strict;
6 | use vars qw($KEY);
7 |
8 | # Public key for verifying downloaded artifacts
9 |
10 | $KEY = <{url} = $args{gateway} || $ENV{JMX4PERL_GATEWAY} || die "No gateway URL given";
21 | $self->{product} = $args{product} || $ENV{JMX4PERL_PRODUCT};
22 | $self->{user} = $args{user} || $ENV{JMX4PERL_USER};
23 | $self->{password} = $args{password} || $ENV{JMX4PERL_PASSWORD};
24 | $self->{verbose} = $args{verbose} || $ENV{JMX4PERL_VERBOSE};
25 | my $t_url = $args{target_url} || $ENV{JMX4PERL_TARGET_URL};
26 | my $t_user = $args{target_user} || $ENV{JMX4PERL_TARGET_USER};
27 | my $t_password = $args{target_password} || $ENV{JMX4PERL_TARGET_PASSWORD};
28 | my @params = map { $_ => $self->{$_ } } qw(url product user password verbose);
29 | if ($t_url) {
30 | push @params, target => {
31 | url => $t_url,
32 | $t_user ? (user => $t_user) : (),
33 | $t_password ? (password => $t_password) : ()
34 | };
35 | }
36 | $self->{jmx4perl} = new JMX::Jmx4Perl(@params);
37 |
38 | bless $self,(ref($class) || $class);
39 |
40 | }
41 |
42 | sub jmx4perl {
43 | my $self = shift;
44 | return $self->{jmx4perl};
45 | }
46 |
47 | sub userAgent {
48 | my $self = shift;
49 | my $j4p = $self->jmx4perl;
50 | return $j4p->{ua};
51 | }
52 |
53 | 1;
54 |
--------------------------------------------------------------------------------
/it/t/55_check_incremental.t:
--------------------------------------------------------------------------------
1 | use strict;
2 | use warnings;
3 | use Test::More qw(no_plan);
4 | use Data::Dumper;
5 | use JMX::Jmx4Perl::Alias;
6 | use It;
7 |
8 | require "check_jmx4perl/base.pl";
9 |
10 | my $jmx = It->new(verbose => 1)->jmx4perl;
11 | my ($ret,$content);
12 |
13 | # ====================================================
14 | # Incremental value checks
15 |
16 | reset_history($jmx);
17 |
18 | my $membean = "--mbean java.lang:type=Memory --attribute HeapMemoryUsage";
19 | my $cparams = $membean . " --path used --unit B --delta --name mem";
20 |
21 |
22 | ($ret,$content) = exec_check_perl4jmx($cparams);
23 | is($ret,0,"Initial history fetch returns OK");
24 | #print $content;
25 | ok($content =~ /mem=(\d+)/ && $1 eq "0","Initial history fetch returns 0 mem delta");
26 |
27 | my $max_mem = $jmx->get_attribute("java.lang:type=Memory", "HeapMemoryUsage","max");
28 | my $c = abs(0.50 * $max_mem);
29 | #print "Mem Max: $mem\n";
30 | my $mem = $jmx->get_attribute("java.lang:type=Memory", "HeapMemoryUsage","used");
31 | #print "Used Memory: $mem\n";
32 |
33 | # Trigger Garbage collection
34 | $jmx->execute("java.lang:type=Memory","gc");
35 |
36 | for my $i (0 .. 2) {
37 | $jmx->execute("java.lang:type=Memory","gc");
38 | ($ret,$content) = exec_check_perl4jmx($cparams . " -c -$c:$c");
39 | is($ret,0,($i+1) . ". history fetch returns OK for -c $c");
40 | ok($content =~ /mem=([\-\d]+)/ && $1 ne "0",($i+1) . ". history fetch return non null Mem-Delta ($1)");
41 | #print Dumper($ret,$content);
42 | print "Heap: ",$jmx->get_attribute("java.lang:type=Memory","HeapMemoryUsage","used"),"\n";
43 | }
44 | #print "$c: $content\n";
45 |
46 | reset_history($jmx);
47 |
48 |
--------------------------------------------------------------------------------
/it/check_jmx4perl/multi_check.cfg:
--------------------------------------------------------------------------------
1 |
2 | include checks.cfg
3 |
4 | # =======================================================================
5 | # Multi checks to check
6 |
7 |
8 | Check memory_non_heap
9 | Check memory_heap
10 |
11 |
12 |
13 | Check thread_count(400,,"'Thread-Count'")
14 | # Multi-Check referenced via 'Check'
15 | Check memory
16 |
17 |
18 |
19 | Check thread_count(400)
20 | Check memory_heap_with_label("HelloLabel","WithInnerArgs")
21 |
22 |
23 |
24 | Check thread_count(400)
25 | Check memory_heap_with_label("HelloLabel",$0)
26 |
27 |
28 |
29 | HtmlOutput
30 | Check memory_non_heap(1,2)
31 | Check memory_non_heap(30,20)
32 | Check memory_heap(1,2)
33 |
34 |
35 |
36 | Check memory_heap
37 | Check kaputt
38 | Check memory_heap(1,2)
39 |
40 |
41 |
42 | MBean bla:type=blub
43 | Attribute foobar
44 |
45 |
46 |
47 | MultiCheck with_outer_args("NestedWithArgs")
48 |
49 |
50 |
51 | # MulitCheck referenced via Check
52 | Check with_outer_args($0)
53 |
54 |
55 |
56 | Check overloaded_operation("blub")
57 |
58 |
59 | # Multicheck where the checks have different arguments
60 | # but are otherwise the same checks.
61 |
62 | Check with_name("bla",1)
63 | Check with_name("blub",2)
64 |
65 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Agent/Jolokia/Verifier/MD5Verifier.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Agent::Jolokia::Verifier::MD5Verifier;
3 |
4 | use Digest::MD5;
5 | use JMX::Jmx4Perl::Agent::Jolokia::Verifier::ChecksumVerifier;
6 | use base qw(JMX::Jmx4Perl::Agent::Jolokia::Verifier::ChecksumVerifier);
7 | use strict;
8 |
9 | =head1 NAME
10 |
11 | JMX::Jmx4Perl::Agent::Jolokia::Verifier::MD5Verifier - Verifies a
12 | MD5 checksum
13 |
14 | =head1 DESCRIPTION
15 |
16 | Verifies against a MD5 checksum for an artifact. The MD5 sum needs to be
17 | available parallel to the download artifact with a ".md5" extension.
18 |
19 | =cut
20 |
21 |
22 | sub extension {
23 | return ".md5";
24 | }
25 |
26 | sub name {
27 | return "MD5";
28 | }
29 |
30 | sub create_digester {
31 | return new Digest::MD5();
32 | }
33 |
34 | =head1 LICENSE
35 |
36 | This file is part of jmx4perl.
37 | Jmx4perl is free software: you can redistribute it and/or modify
38 | it under the terms of the GNU General Public License as published by
39 | The Free Software Foundation, either version 2 of the License, or
40 | (at your option) any later version.
41 |
42 | jmx4perl is distributed in the hope that it will be useful,
43 | but WITHOUT ANY WARRANTY; without even the implied warranty of
44 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 | GNU General Public License for more details.
46 |
47 | You should have received a copy of the GNU General Public License
48 | along with jmx4perl. If not, see .
49 |
50 | A commercial license is available as well. Please contact roland@cpan.org for
51 | further details.
52 |
53 | =head1 AUTHOR
54 |
55 | roland@cpan.org
56 |
57 | =cut
58 |
59 | 1;
60 |
61 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Agent/Jolokia/Verifier/SHA1Verifier.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Agent::Jolokia::Verifier::SHA1Verifier;
3 |
4 | use Digest::SHA1;
5 | use JMX::Jmx4Perl::Agent::Jolokia::Verifier::ChecksumVerifier;
6 | use base qw(JMX::Jmx4Perl::Agent::Jolokia::Verifier::ChecksumVerifier);
7 | use strict;
8 |
9 | =head1 NAME
10 |
11 | JMX::Jmx4Perl::Agent::Jolokia::Verifier::SHA1Verifier - Verifies a
12 | SHA1 checksum
13 |
14 | =head1 DESCRIPTION
15 |
16 | Verifies against a SHA1 checksum for an artifact. The SHA1 sum needs to be
17 | available parallel to the download artifact with a ".sha1" extension.
18 |
19 | =cut
20 |
21 | sub extension {
22 | return ".sha1";
23 | }
24 |
25 | sub name {
26 | return "SHA1";
27 | }
28 |
29 | sub create_digester {
30 | return new Digest::SHA1();
31 | }
32 |
33 | =head1 LICENSE
34 |
35 | This file is part of jmx4perl.
36 | Jmx4perl is free software: you can redistribute it and/or modify
37 | it under the terms of the GNU General Public License as published by
38 | The Free Software Foundation, either version 2 of the License, or
39 | (at your option) any later version.
40 |
41 | jmx4perl is distributed in the hope that it will be useful,
42 | but WITHOUT ANY WARRANTY; without even the implied warranty of
43 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 | GNU General Public License for more details.
45 |
46 | You should have received a copy of the GNU General Public License
47 | along with jmx4perl. If not, see .
48 |
49 | A commercial license is available as well. Please contact roland@cpan.org for
50 | further details.
51 |
52 | =head1 AUTHOR
53 |
54 | roland@cpan.org
55 |
56 | =cut
57 |
58 | 1;
59 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Nagios/MessageHandler.pm:
--------------------------------------------------------------------------------
1 | package JMX::Jmx4Perl::Nagios::MessageHandler;
2 |
3 | use Monitoring::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT);
4 | use strict;
5 |
6 | =head1 NAME
7 |
8 | JMX::Jmx4Perl::Nagios::MessageHandler - Handling Nagios exit message (one or
9 | many)
10 |
11 | =cut
12 |
13 | sub new {
14 | my $class = shift;
15 | my $self = {
16 | messages => {}
17 | };
18 | bless $self,(ref($class) || $class);
19 | return $self;
20 | }
21 |
22 | sub add_message {
23 | my $self = shift;
24 | my ($code,@messages) = @_;
25 |
26 | die "Invalid error code '$code'\n"
27 | unless defined($ERRORS{uc $code}) || defined($STATUS_TEXT{$code});
28 |
29 | # Store messages using strings rather than numeric codes
30 | $code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code};
31 | $code = lc $code;
32 |
33 | $self->{messages}->{$code} = [] unless $self->{messages}->{$code};
34 | push @{$self->{messages}->{$code}}, @messages;
35 | }
36 |
37 | sub check_messages {
38 | my $self = shift;
39 | my %arg = @_;
40 |
41 | for my $code (qw(critical warning ok unknown)) {
42 | $arg{$code} = $self->{messages}->{$code} || [];
43 | }
44 |
45 | my $code = OK;
46 | $code ||= UNKNOWN if @{$arg{unknown}};
47 | $code ||= CRITICAL if @{$arg{critical}};
48 | $code ||= WARNING if @{$arg{warning}};
49 |
50 | my $message = join( "\n",
51 | map { @$_ ? join( "\n", @$_) : () }
52 | $arg{unknown},
53 | $arg{critical},
54 | $arg{warning},
55 | $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : []
56 | );
57 | return ($code, $message);
58 | }
59 |
60 | 1;
61 |
--------------------------------------------------------------------------------
/config/websphere/jms.cfg:
--------------------------------------------------------------------------------
1 | # =======================================================
2 | # WebSphere JMS checks
3 |
4 | # Check the number of message in a queue
5 | #
6 | # $0: Queue Name
7 | # $1: Critical Threshold (default: 10)
8 | # $2: Warning Threshold (default: 5)
9 |
10 | MBean WebSphere:type=SIBQueuePoint,name=${0},*
11 | Attribute depth
12 |
13 | # Messages Thresshold
14 | Critical ${1:10}
15 | Warning ${2:5}
16 |
17 | Label %v messages in queue ${0}
18 | Name jms-{0}-queue
19 |
20 |
21 | # PMI metrics available over UI but not still via JMX ? -->
22 |
23 | # Queues.QueueStats.LocalProducerAttachesCount
24 | # Queues.QueueStats.LocalProducerCount
25 | # Queues.QueueStats.LocalConsumerAttachesCount
26 | # Queues.QueueStats.LocalConsumerCount
27 | # Queues.QueueStats.TotalMessagesProducedCount
28 | # Queues.QueueStats.BestEffortNonPersistentMessagesProducedCount
29 | # Queues.QueueStats.ExpressNonPersistentMessagesProducedCount
30 | # Queues.QueueStats.ReliableNonPersistentMessagesProducedCount
31 | # Queues.QueueStats.ReliablePersistentMessagesProducedCount
32 | # Queues.QueueStats.AssuredPersistentMessagesProducedCount
33 | # Queues.QueueStats.TotalMessagesConsumedCount
34 | # Queues.QueueStats.BestEffortNonPersistentMessagesConsumedCount
35 | # Queues.QueueStats.ExpressNonPersistentMessagesConsumedCount
36 | # Queues.QueueStats.ReliableNonPersistentMessagesConsumedCount
37 | # Queues.QueueStats.ReliablePersistentMessagesConsumedCount
38 | # Queues.QueueStats.AssuredPersistentMessagesConsumedCount
39 | # Queues.QueueStats.ReportEnabledMessagesExpiredCount
40 | # Queues.QueueStats.AggregateMessageWaitTime
41 | # Queues.QueueStats.LocalMessageWaitTime
42 | # Queues.QueueStats.LocalOldestMessageAge
43 | # Queues.QueueStats.AvailableMessageCount
44 | # Queues.QueueStats.UnavailableMessageCount
--------------------------------------------------------------------------------
/it/check_jmx4perl/base.pl:
--------------------------------------------------------------------------------
1 | # Base functions for various check_jmx4perl checks
2 |
3 | use strict;
4 | use FindBin;
5 | use JMX::Jmx4Perl::Alias;
6 | use JMX::Jmx4Perl::Request;
7 | use JMX::Jmx4Perl::Response;
8 |
9 | sub exec_check_perl4jmx {
10 | my @args;
11 | for (@_) {
12 | push @args,split;
13 | }
14 | my ($url,$user,$password,$product,$target,$target_user,$target_password) =
15 | @ENV{"JMX4PERL_GATEWAY","JMX4PERL_USER",
16 | "JMX4PERL_PASSWORD","JMX4PERL_PRODUCT","JMX4PERL_TARGET_URL","JMX4PERL_TARGET_USER","JMX4PERL_TARGET_PASSWORD"};
17 | push @args,("--user",$user,"--password",$password) if $user;
18 | push @args,("--product",$product) if $product;
19 | push @args,("--url",$url);
20 | push @args,("--target",$target) if $target;
21 | push @args,("--target-user",$target_user,"--target-password",$target_password) if $target_user;
22 | #push @args,"--legacy-escape";
23 | #push @args,("--verbose");
24 |
25 | my $cmd = "perl $FindBin::Bin/../../scripts/check_jmx4perl "
26 | .join(" ",map { '"' . $_ . '"' } @args);
27 | #print $cmd,"\n";
28 | open (F,"$cmd 2>&1 |")
29 | || die "Cannot open check_jmx4perl: $!";
30 | my $content = join "",;
31 | close F;
32 |
33 | if ($? == -1) {
34 | die "check_jmx4perl: failed to execute: $!\n";
35 | }
36 | elsif ($? & 127) {
37 | die "check_jmx4perl child died with signal %d, %s coredump\n",
38 | ($? & 127), ($? & 128) ? 'with' : 'without';
39 | }
40 | return ($? >> 8,$content);
41 | }
42 |
43 | sub reset_history {
44 | my $jmx = shift;
45 | my ($mbean,$operation) = $jmx->resolve_alias(JMX4PERL_HISTORY_RESET);
46 | my $req = new JMX::Jmx4Perl::Request(EXEC,$mbean,$operation,{target => undef});
47 | my $resp = $jmx->request($req);
48 | }
49 |
50 | 1;
51 |
--------------------------------------------------------------------------------
/it/it.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use FindBin;
4 | use lib "$FindBin::Bin/../lib";
5 | use Getopt::Long;
6 | use strict;
7 | use TAP::Harness;
8 | use Data::Dumper;
9 |
10 |
11 | my $dir = $FindBin::Bin . "/t";
12 | my ($gateway_url,$user,$password,$product,$target_url,$target_user,$target_password);
13 | GetOptions("dir=s" => \$dir,
14 | "url=s" => \$gateway_url,
15 | "target=s" => \$target_url,
16 | "target-user=s" => \$target_user,
17 | "target-password=s" => \$target_password,
18 | "user=s" => \$user,
19 | "password=s" => \$password,
20 | "product=s" => \$product);
21 | die "No gateway url given. Please use option '--url' for pointing to the server with the agent installed\n" unless $gateway_url;
22 |
23 | my @testfiles;
24 | if (@ARGV) {
25 | @testfiles = prepare_filenames(@ARGV);
26 | } else {
27 | opendir(D,$dir) || die "Cannot open test dir $dir : $!";
28 | @testfiles = prepare_filenames(grep { /\.t$/ } map { $dir . "/" . $_ } readdir(D));
29 | closedir D;
30 | }
31 |
32 | my $harness = new TAP::Harness
33 | ({
34 | verbosity => 1,
35 | timer => 1,
36 | show_count => 0,
37 | color => 1,
38 | merge => 1,
39 | jobs => 1,
40 | lib => [ "$FindBin::Bin/../lib", "$FindBin::Bin/../t/lib", "$FindBin::Bin" ]
41 | });
42 |
43 | $ENV{JMX4PERL_GATEWAY} = $gateway_url;
44 | $ENV{JMX4PERL_TARGET_URL} = $target_url;
45 | $ENV{JMX4PERL_TARGET_USER} = $target_user;
46 | $ENV{JMX4PERL_TARGET_PASSWORD} = $target_password;
47 | $ENV{JMX4PERL_USER} = $user;
48 | $ENV{JMX4PERL_PASSWORD} = $password;
49 | $ENV{JMX4PERL_PRODUCT} = $product;
50 |
51 | $harness->runtests(@testfiles);
52 |
53 | sub prepare_filenames {
54 | my @files = @_;
55 | my @ret = ();
56 | for (@files) {
57 | my $name = $_;
58 | $name =~ s|.*/([^/]+)$|$1|;
59 | push @ret,[ $_, $name ];
60 | }
61 | return @ret;
62 | }
63 |
--------------------------------------------------------------------------------
/it/t/52_check_operation.t:
--------------------------------------------------------------------------------
1 | use strict;
2 | use warnings;
3 | use Test::More qw(no_plan);
4 | use Data::Dumper;
5 | use It;
6 | use FindBin;
7 |
8 | require "check_jmx4perl/base.pl";
9 |
10 | my $jmx = It->new(verbose =>0)->jmx4perl;
11 | my ($ret,$content);
12 |
13 | # ====================================================
14 | # Operation return value check
15 |
16 | # A single slash argument
17 |
18 | $jmx->execute("jolokia.it:type=operation","reset");
19 |
20 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=operation --operation fetchNumber",
21 | "-c 1 --name counter inc");
22 | is($ret,0,"Initial operation");
23 | ok($content =~ /counter=(\d+)/ && $1 eq "0","Initial operation returns 0");
24 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=operation --operation fetchNumber",
25 | "-c 1 --name counter inc");
26 | is($ret,0,"Second operation");
27 | ok($content =~ /counter=(\d+)/ && $1 eq "1","Second operation returns 1");
28 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=operation --operation fetchNumber",
29 | "-c 1 --name counter inc");
30 | is($ret,2,"Third operation");
31 | ok($content =~ /counter=(\d+)/ && $1 eq "2","Third operation returns 2");
32 |
33 | my $config_file = $FindBin::Bin . "/../check_jmx4perl/checks.cfg";
34 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check counter_operation");
35 | ok($content =~ /value (\d+)/ && $1 eq "3","Fourth operation return 3");
36 | is($ret,1,"Fourth operation");
37 |
38 |
39 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=operation --operation emptyStringArgumentCheck",
40 | "-c 1 /");
41 | #print Dumper($ret,$content);
42 | is($ret,0,"Single slash argument (return code)");
43 | ok($content =~ /false/,"Single slash argument (return message)");
44 | $jmx->execute("jolokia.it:type=operation","reset");
45 |
46 |
--------------------------------------------------------------------------------
/it/t/54_check_unit.t:
--------------------------------------------------------------------------------
1 | use strict;
2 | use warnings;
3 | use Test::More qw(no_plan);
4 | use Data::Dumper;
5 | use It;
6 |
7 | require "check_jmx4perl/base.pl";
8 |
9 | my $jmx = It->new(verbose =>0)->jmx4perl;
10 | my ($ret,$content);
11 |
12 | # ================================================================================
13 | # Unit conversion checking
14 |
15 | ($ret,$content) = exec_check_perl4jmx
16 | ("--mbean jolokia.it:type=attribute --attribute Bytes --critical 10000:");
17 | is($ret,0,"Bytes: OK");
18 | ok($content =~ /3670016/,"Bytes: Perfdata");
19 | ok($content !~ /3\.50 MB/,"Bytes: Output");
20 |
21 | ($ret,$content) = exec_check_perl4jmx
22 | ("--mbean jolokia.it:type=attribute --attribute Bytes --critical 10000: --unit B");
23 | is($ret,0,"Bytes: OK");
24 | ok($content =~ /3670016B/,"Bytes Unit: Perfdata");
25 | ok($content =~ /3\.50 MB/,"Bytes Unit: Output");
26 |
27 | ($ret,$content) = exec_check_perl4jmx
28 | ("--mbean jolokia.it:type=attribute --attribute LongSeconds --critical :10000 ");
29 | is($ret,2,"SecondsLong: CRITICAL");
30 | ok($content =~ /172800/,"SecondsLong: Perfdata");
31 | ok($content !~ /2 d/,"SecondsLong: Output");
32 |
33 | ($ret,$content) = exec_check_perl4jmx
34 | ("--mbean jolokia.it:type=attribute --attribute LongSeconds --critical :10000 --unit s");
35 | is($ret,2,"SecondsLong: CRITICAL");
36 | ok($content =~ /172800/,"SecondsLong: Perfdata");
37 | ok($content =~ /2 d/,"SecondsLong: Output");
38 |
39 | ($ret,$content) = exec_check_perl4jmx
40 | ("--mbean jolokia.it:type=attribute --attribute SmallMinutes --critical :10000 --unit m");
41 | #print Dumper($ret,$content);
42 | is($ret,0,"SmallMinutes: OK");
43 | ok($content =~ /10.00 ms/,"SmallMinutes: Output");
44 |
45 | ($ret,$content) = exec_check_perl4jmx
46 | ("--value jolokia.it:type=attribute/MemoryUsed --base jolokia.it:type=attribute/MemoryMax --critical 80 --unit B");
47 | #print Dumper($ret,$content);
48 | is($ret,0,"Relative Memory: OK");
49 | ok($content =~ /1\.99 GB/,"Relative Memory: Output");
50 |
51 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Hadoop.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Hadoop;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 | use Data::Dumper;
8 |
9 | use Carp qw(croak);
10 |
11 | =head1 NAME
12 |
13 | JMX::Jmx4Perl::Product::Hadoop - Handler for Hadoop
14 |
15 | =head1 DESCRIPTION
16 |
17 | This is the product handler support Hadoop (L)
18 | which works with the JVM Agent provided for Sun JDK 6 based applications.
19 |
20 | =cut
21 |
22 | sub id {
23 | return "hadoop";
24 | }
25 |
26 | sub name {
27 | return "Hadoop";
28 | }
29 |
30 | sub vendor {
31 | return "Apache";
32 | }
33 |
34 | sub version {
35 | # No way to detect version until yet.
36 | return "";
37 | }
38 | sub order {
39 | return 220;
40 | }
41 |
42 | sub autodetect_pattern {
43 | return sub {
44 | my $self = shift;
45 | my $j4p = $self->{jmx4perl};
46 | my $ret = $j4p->search("hadoop:*");
47 | #print Dumper($ret);
48 | return $ret;
49 | };
50 | }
51 |
52 | =head1 LICENSE
53 |
54 | This file is part of jmx4perl.
55 |
56 | Jmx4perl is free software: you can redistribute it and/or modify
57 | it under the terms of the GNU General Public License as published by
58 | the Free Software Foundation, either version 2 of the License, or
59 | (at your option) any later version.
60 |
61 | jmx4perl is distributed in the hope that it will be useful,
62 | but WITHOUT ANY WARRANTY; without even the implied warranty of
63 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64 | GNU General Public License for more details.
65 |
66 | You should have received a copy of the GNU General Public License
67 | along with jmx4perl. If not, see .
68 |
69 | A commercial license is available as well. Please contact roland@cpan.org for
70 | further details.
71 |
72 | =head1 AUTHOR
73 |
74 | roland@cpan.org
75 |
76 | =cut
77 |
78 | 1;
79 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/ActiveMQ.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::ActiveMQ;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 | use Data::Dumper;
8 |
9 | use Carp qw(croak);
10 |
11 | =head1 NAME
12 |
13 | JMX::Jmx4Perl::Product::ActiveMQ - Handler for Jonas
14 |
15 | =head1 DESCRIPTION
16 |
17 | This is the product handler support for ActiveMQ
18 | (L) which works with the JVM Agent provided for
19 | Sun JDK 6 based applications
20 |
21 | =cut
22 |
23 | sub id {
24 | return "activemq";
25 | }
26 |
27 | sub name {
28 | return "ActiveMQ";
29 | }
30 |
31 | sub vendor {
32 | return "Apache";
33 | }
34 |
35 | sub version {
36 | # No way to detect version until yet.
37 | return "";
38 | }
39 | sub order {
40 | return 200;
41 | }
42 |
43 | sub autodetect_pattern {
44 | return sub {
45 | my $self = shift;
46 | my $j4p = $self->{jmx4perl};
47 | my $ret = $j4p->search("org.apache.activemq:*");
48 | #print Dumper($ret);
49 | return $ret;
50 | };
51 | }
52 |
53 | =head1 LICENSE
54 |
55 | This file is part of jmx4perl.
56 |
57 | Jmx4perl is free software: you can redistribute it and/or modify
58 | it under the terms of the GNU General Public License as published by
59 | the Free Software Foundation, either version 2 of the License, or
60 | (at your option) any later version.
61 |
62 | jmx4perl is distributed in the hope that it will be useful,
63 | but WITHOUT ANY WARRANTY; without even the implied warranty of
64 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65 | GNU General Public License for more details.
66 |
67 | You should have received a copy of the GNU General Public License
68 | along with jmx4perl. If not, see .
69 |
70 | A commercial license is available as well. Please contact roland@cpan.org for
71 | further details.
72 |
73 | =head1 AUTHOR
74 |
75 | roland@cpan.org
76 |
77 | =cut
78 |
79 | 1;
80 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/Unix.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::Unix;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Base;
8 |
9 | use vars qw(@ISA);
10 | @ISA = qw(Module::Build::Base);
11 |
12 | sub is_executable {
13 | # We consider the owner bit to be authoritative on a file, because
14 | # -x will always return true if the user is root and *any*
15 | # executable bit is set. The -x test seems to try to answer the
16 | # question "can I execute this file", but I think we want "is this
17 | # file executable".
18 |
19 | my ($self, $file) = @_;
20 | return +(stat $file)[2] & 0100;
21 | }
22 |
23 | sub _startperl { "#! " . shift()->perl }
24 |
25 | sub _construct {
26 | my $self = shift()->SUPER::_construct(@_);
27 |
28 | # perl 5.8.1-RC[1-3] had some broken %Config entries, and
29 | # unfortunately Red Hat 9 shipped it like that. Fix 'em up here.
30 | my $c = $self->{config};
31 | for (qw(siteman1 siteman3 vendorman1 vendorman3)) {
32 | $c->{"install${_}dir"} ||= $c->{"install${_}"};
33 | }
34 |
35 | return $self;
36 | }
37 |
38 | # Open group says username should be portable filename characters,
39 | # but some Unix OS working with ActiveDirectory wind up with user-names
40 | # with back-slashes in the name. The new code below is very liberal
41 | # in what it accepts.
42 | sub _detildefy {
43 | my ($self, $value) = @_;
44 | $value =~ s[^~([^/]+)?(?=/|$)] # tilde with optional username
45 | [$1 ?
46 | ((getpwnam $1)[7] || "~$1") :
47 | ($ENV{HOME} || (getpwuid $>)[7])
48 | ]ex;
49 | return $value;
50 | }
51 |
52 | 1;
53 | __END__
54 |
55 |
56 | =head1 NAME
57 |
58 | Module::Build::Platform::Unix - Builder class for Unix platforms
59 |
60 | =head1 DESCRIPTION
61 |
62 | The sole purpose of this module is to inherit from
63 | C. Please see the L for the docs.
64 |
65 | =head1 AUTHOR
66 |
67 | Ken Williams
68 |
69 | =head1 SEE ALSO
70 |
71 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
72 |
73 | =cut
74 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/JBoss.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::JBoss;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 |
8 | use Carp qw(croak);
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::Product::JBoss - Handler for JBoss
13 |
14 | =head1 DESCRIPTION
15 |
16 | This is the product handler support JBoss 4.x and JBoss 5.x (L)
17 |
18 | =cut
19 |
20 | sub id {
21 | return "jboss";
22 | }
23 |
24 | sub name {
25 | return "JBoss AS";
26 | }
27 |
28 | sub order {
29 | return -2;
30 | }
31 |
32 | sub jsr77 {
33 | return 1;
34 | }
35 |
36 | sub version {
37 | return shift->_version_or_vendor("version",qr/^(.*?)\s+/);
38 | }
39 |
40 | sub autodetect_pattern {
41 | return ("vendor",qr/JBoss/i);
42 | }
43 |
44 | sub init_aliases {
45 | return
46 | {
47 | attributes =>
48 | {
49 | SERVER_ADDRESS => [ "jboss.system:type=ServerInfo", "HostAddress"],
50 | SERVER_HOSTNAME => [ "jboss.system:type=ServerInfo", "HostName"],
51 | },
52 | operations =>
53 | {
54 | THREAD_DUMP => [ "jboss.system:type=ServerInfo", "listThreadDump"]
55 | }
56 | # Alias => [ "mbean", "attribute", "path" ]
57 | };
58 | }
59 |
60 |
61 | =head1 LICENSE
62 |
63 | This file is part of jmx4perl.
64 |
65 | Jmx4perl is free software: you can redistribute it and/or modify
66 | it under the terms of the GNU General Public License as published by
67 | the Free Software Foundation, either version 2 of the License, or
68 | (at your option) any later version.
69 |
70 | jmx4perl is distributed in the hope that it will be useful,
71 | but WITHOUT ANY WARRANTY; without even the implied warranty of
72 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73 | GNU General Public License for more details.
74 |
75 | You should have received a copy of the GNU General Public License
76 | along with jmx4perl. If not, see .
77 |
78 | A commercial license is available as well. Please contact roland@cpan.org for
79 | further details.
80 |
81 | =head1 AUTHOR
82 |
83 | roland@cpan.org
84 |
85 | =cut
86 |
87 | 1;
88 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Terracotta.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Terracotta;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 | use Data::Dumper;
8 |
9 | use Carp qw(croak);
10 |
11 | =head1 NAME
12 |
13 | JMX::Jmx4Perl::Product::Terracotta - Handler for Terracotta server
14 |
15 | =head1 DESCRIPTION
16 |
17 | This is the product handler support Terracotta (L)
18 | which works with the JVM Agent provided for Sun JDK 6 based applications.
19 |
20 | =cut
21 |
22 | sub id {
23 | return "terracotta";
24 | }
25 |
26 | sub name {
27 | return "Terracotta";
28 | }
29 |
30 |
31 | sub order {
32 | return 210;
33 | }
34 |
35 | sub vendor {
36 | return "Terracotta";
37 | }
38 |
39 | sub version {
40 | return shift->{version};
41 | }
42 |
43 | sub autodetect_pattern {
44 | return sub {
45 | my $self = shift;
46 | my $j4p = $self->{jmx4perl};
47 | my $found = $self->try_attribute("version","org.terracotta.internal:name=Terracotta Server,type=Terracotta Server","Version");
48 | if ($found) {
49 | $self->{version} =~ s/.*?([\d\.]+).*/$1/;
50 | return 1;
51 | } else {
52 | return undef;
53 | }
54 | };
55 | }
56 |
57 | =head1 LICENSE
58 |
59 | This file is part of jmx4perl.
60 |
61 | Jmx4perl is free software: you can redistribute it and/or modify
62 | it under the terms of the GNU General Public License as published by
63 | the Free Software Foundation, either version 2 of the License, or
64 | (at your option) any later version.
65 |
66 | jmx4perl is distributed in the hope that it will be useful,
67 | but WITHOUT ANY WARRANTY; without even the implied warranty of
68 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69 | GNU General Public License for more details.
70 |
71 | You should have received a copy of the GNU General Public License
72 | along with jmx4perl. If not, see .
73 |
74 | A commercial license is available as well. Please contact roland@cpan.org for
75 | further details.
76 |
77 | =head1 AUTHOR
78 |
79 | roland@cpan.org
80 |
81 | =cut
82 |
83 | 1;
84 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Geronimo.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Geronimo;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 |
8 | use Carp qw(croak);
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::Product::Geronimo - Handler for Geronimo
13 |
14 | =head1 DESCRIPTION
15 |
16 | This is the product handler supporting Geronimo 2 (L)
17 |
18 | =cut
19 |
20 | sub id {
21 | return "geronimo";
22 | }
23 |
24 | sub name {
25 | return "Apache Geronimo";
26 | }
27 |
28 | # Not that popular
29 | sub order {
30 | return 10;
31 | }
32 |
33 | sub autodetect {
34 | my $self = shift;
35 | my $info = shift;
36 | my $jmx = $self->{jmx4perl};
37 |
38 | my $servers = $jmx->search("geronimo:j2eeType=J2EEServer,*");
39 | return $servers && @$servers;
40 | }
41 |
42 | sub jsr77 {
43 | return 1;
44 | }
45 |
46 | sub init_aliases {
47 | return
48 | {
49 | attributes =>
50 | {
51 | #SERVER_ADDRESS => [ "jboss.system:type=ServerInfo", "HostAddress"],
52 | #SERVER_HOSTNAME => [ "Catalina:type=Engine", "defaultHost"],
53 | },
54 | operations =>
55 | {
56 | #THREAD_DUMP => [ "jboss.system:type=ServerInfo", "listThreadDump"]
57 | }
58 | # Alias => [ "mbean", "attribute", "path" ]
59 | };
60 | }
61 |
62 |
63 |
64 | =head1 LICENSE
65 |
66 | This file is part of jmx4perl.
67 |
68 | Jmx4perl is free software: you can redistribute it and/or modify
69 | it under the terms of the GNU General Public License as published by
70 | the Free Software Foundation, either version 2 of the License, or
71 | (at your option) any later version.
72 |
73 | jmx4perl is distributed in the hope that it will be useful,
74 | but WITHOUT ANY WARRANTY; without even the implied warranty of
75 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76 | GNU General Public License for more details.
77 |
78 | You should have received a copy of the GNU General Public License
79 | along with jmx4perl. If not, see .
80 |
81 | A commercial license is available as well. Please contact roland@cpan.org for
82 | further details.
83 |
84 | =head1 AUTHOR
85 |
86 | roland@cpan.org
87 |
88 | =cut
89 |
90 | 1;
91 |
--------------------------------------------------------------------------------
/config/glassfish.cfg:
--------------------------------------------------------------------------------
1 | # Glassfish specific checks
2 | # ===========================
3 |
4 |
5 | # =================
6 | # JMS with Open MQ
7 | # For even more metrics, please refer to http://docs.oracle.com/cd/E19316-01/820-6766/gcakw/index.html
8 |
9 | # Number of messages within a queue
10 | # $0: Name of queue
11 | # $1: Critical (default: 1000)
12 | # $2: Warning (default: 800)
13 |
14 | MBean = com.sun.messaging.jms.server:name="$0",subtype=Monitor,type=Destination,desttype=q
15 | Attribute = NumMsgs
16 | Name = JMS Queue $0 Count
17 | Critical = ${1:1000}
18 | Warning = ${2:800}
19 |
20 |
21 | # Number of messages held for a topic
22 | # $0: Name of queue
23 | # $1: Critical (default: 1000)
24 | # $2: Warning (default: 800)
25 |
26 | MBean = com.sun.messaging.jms.server:name="$0",subtype=Monitor,type=Destination,desttype=t
27 | Attribute = NumMsgs
28 | Name = JMS Topic $0 Count
29 | Critical = ${1:1000}
30 | Warning = ${2:800}
31 |
32 |
33 | # Average number of consumers of a topic or queue
34 | # $0: Name of queue or topic
35 | # $1: Critical (default: 300)
36 | # $2: Warning (default: 200)
37 |
38 | MBean = com.sun.messaging.jms.server:name="$0",subtype=Monitor,type=Destination,*
39 | Attribute = AvgNumConsumers
40 | Name = Average Number of consumers for $0
41 | Critical = ${1:300}
42 | Warning = ${2:200}
43 |
44 |
45 | # Active number of consumers of a topic or queue
46 | # $0: Name of queue or topic
47 | # $1: Critical (default: 300)
48 | # $2: Warning (default: 200)
49 |
50 | MBean = com.sun.messaging.jms.server:name="$0",subtype=Monitor,type=Destination,*
51 | Attribute = NumActiveConsumers
52 | Name = Number of consumers of $0
53 | Critical = ${1:300}
54 | Warning = ${2:200}
55 |
56 |
57 | # Size of all messages within a queue or topic
58 | # $0: Name of queue or topic
59 | # $1: Critical (default: 30 MB)
60 | # $2: Warning (default: 20 MB)
61 |
62 | MBean = com.sun.messaging.jms.server:name="$0",subtype=Monitor,type=Destination,*
63 | Attribute = TotalMsgBytes
64 | Name = Size of messages in $0
65 | Critical = ${1:30000000}
66 | Warning = ${2:20000000}
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Jonas.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Jonas;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 |
8 | use Carp qw(croak);
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::Product::Jonas - Handler for Jonas
13 |
14 | =head1 DESCRIPTION
15 |
16 | This is the product handler support Jonas 4 and 5 (L)
17 |
18 | =cut
19 |
20 | sub id {
21 | return "jonas";
22 | }
23 |
24 | sub name {
25 | return "Jonas";
26 | }
27 |
28 | sub order {
29 | return 10;
30 | }
31 |
32 | sub autodetect_pattern {
33 | return ("vendor",qr/OW2/i);
34 | }
35 |
36 | sub server_info {
37 | my $self = shift;
38 | my $ret = $self->SUPER::server_info();
39 | $ret .= sprintf("%-10.10s %s\n","Web:",$self->{jmx4perl}->get_attribute("jonas:name=webContainers,type=service","ServerName"));
40 | }
41 |
42 | sub jsr77 {
43 | return 1;
44 | }
45 |
46 | sub init_aliases {
47 | return
48 | {
49 | attributes =>
50 | {
51 | #SERVER_ADDRESS => [ "jboss.system:type=ServerInfo", "HostAddress"],
52 | #SERVER_HOSTNAME => [ "jonas:name=jonas,type=ServerProxy", "HostName"],
53 | },
54 | operations =>
55 | {
56 | #THREAD_DUMP => [ "jboss.system:type=ServerInfo", "listThreadDump"]
57 | }
58 | # Alias => [ "mbean", "attribute", "path" ]
59 | };
60 | }
61 |
62 |
63 | =head1 LICENSE
64 |
65 | This file is part of jmx4perl.
66 |
67 | Jmx4perl is free software: you can redistribute it and/or modify
68 | it under the terms of the GNU General Public License as published by
69 | the Free Software Foundation, either version 2 of the License, or
70 | (at your option) any later version.
71 |
72 | jmx4perl is distributed in the hope that it will be useful,
73 | but WITHOUT ANY WARRANTY; without even the implied warranty of
74 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 | GNU General Public License for more details.
76 |
77 | You should have received a copy of the GNU General Public License
78 | along with jmx4perl. If not, see .
79 |
80 | A commercial license is available as well. Please contact roland@cpan.org for
81 | further details.
82 |
83 | =head1 AUTHOR
84 |
85 | roland@cpan.org
86 |
87 | =cut
88 |
89 | 1;
90 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Resin.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Resin;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 |
8 | use Carp qw(croak);
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::Product::Resin - Handler for Resin
13 |
14 | =head1 DESCRIPTION
15 |
16 | This is the product handler support Resind 3 and 4 (L)
17 |
18 | =cut
19 |
20 | sub id {
21 | return "resin";
22 | }
23 |
24 | sub name {
25 | return "Resin";
26 | }
27 |
28 | sub order {
29 | return 110;
30 | }
31 |
32 | sub _try_version {
33 | my $self = shift;
34 | my $ret = $self->try_attribute("version","resin:type=Resin","Version");
35 | if ($ret) {
36 | $self->{version} =~ s|^.*?([\d.]+).*$|$1|;
37 | }
38 | return $ret;
39 | }
40 |
41 | sub autodetect_pattern {
42 | return ("version");
43 | }
44 |
45 | sub jsr77 {
46 | return 1;
47 | }
48 |
49 | sub init_aliases {
50 | return
51 | {
52 | attributes =>
53 | {
54 | #SERVER_ADDRESS => [ "jboss.system:type=ServerInfo", "HostAddress"],
55 | #SERVER_HOSTNAME => [ "jonas:name=jonas,type=ServerProxy", "HostName"],
56 | },
57 | operations =>
58 | {
59 | #THREAD_DUMP => [ "jboss.system:type=ServerInfo", "listThreadDump"]
60 | }
61 | # Alias => [ "mbean", "attribute", "path" ]
62 | };
63 | }
64 |
65 |
66 | =head1 LICENSE
67 |
68 | This file is part of jmx4perl.
69 |
70 | Jmx4perl is free software: you can redistribute it and/or modify
71 | it under the terms of the GNU General Public License as published by
72 | the Free Software Foundation, either version 2 of the License, or
73 | (at your option) any later version.
74 |
75 | jmx4perl is distributed in the hope that it will be useful,
76 | but WITHOUT ANY WARRANTY; without even the implied warranty of
77 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78 | GNU General Public License for more details.
79 |
80 | You should have received a copy of the GNU General Public License
81 | along with jmx4perl. If not, see .
82 |
83 | A commercial license is available as well. Please contact roland@cpan.org for
84 | further details.
85 |
86 | =head1 AUTHOR
87 |
88 | roland@cpan.org
89 |
90 | =cut
91 |
92 | 1;
93 |
--------------------------------------------------------------------------------
/t/40_check_jmx4perl.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use strict;
4 | use warnings;
5 | use FindBin qw($Bin);
6 | use lib qq($Bin/lib);
7 | use vars qw(@ARGS);
8 | use Test::More;
9 | use Data::Dumper;
10 |
11 | eval { require Monitoring::Plugin };
12 | if ($@) {
13 | plan skip_all => 'Monitoring::Plugin not installed';
14 | }
15 | else {
16 | plan tests => 29;
17 | }
18 |
19 | Monitoring::Plugin->import();
20 |
21 | eval { require JMX::Jmx4Perl::Nagios::SingleCheck };
22 | ok(!$@,"JMX::Jmx4Perl::Nagios::SingleCheck loads properly");
23 |
24 | eval { require JMX::Jmx4Perl::Nagios::CheckJmx4Perl };
25 | ok(!$@,"JMX::Jmx4Perl::Nagios::CheckJmx4Perl loads properly");
26 |
27 | @ARGV=qw(--url http://localhost:8080/j4p -a MEMORY_HEAP_USED -c 1 -m 2 --name Memory --unit m);
28 | my $cj4p = new JMX::Jmx4Perl::Nagios::CheckJmx4Perl();
29 | my $scheck = $cj4p->{checks}->[0];
30 | my ($value,$unit) = $scheck->_normalize_value("0.50","MB");
31 | is($value,512);
32 | is($unit,"KB");
33 | ($value,$unit) = $scheck->_normalize_value("2048","MB");
34 | is($value,2);
35 | is($unit,"GB");
36 | ($value,$unit) = $scheck->_normalize_value("0.5","m");
37 | is($value,30);
38 | is($unit,"s");
39 | ($value,$unit) = $scheck->_normalize_value("360","m");
40 | is($value,6);
41 | is($unit,"h");
42 | ($value,$unit) = $scheck->_normalize_value("0.5","us");
43 | is($value,"500");
44 | is($unit,"ns");
45 | ($value,$unit) = $scheck->_normalize_value("300","us");
46 | is($value,"300");
47 | is($unit,"us");
48 | ($value,$unit) = $scheck->_normalize_value("20","d");
49 | is($value,"20");
50 | is($unit,"d");
51 | ($value,$unit) = $scheck->_normalize_value("200","TB");
52 | is($value,"200");
53 | is($unit,"TB");
54 | ($value,$unit) = $scheck->_normalize_value(1024*1024,"B");
55 | is($value,1);
56 | is($unit,"MB");
57 | ($value,$unit) = $scheck->_normalize_value("1000","ms");
58 | is($value,1);
59 | is($unit,"s");
60 | ($value,$unit) = $scheck->_normalize_value(1/60,"m");
61 | is($value,1);
62 | is($unit,"s");
63 | ($value,$unit) = $scheck->_normalize_value(0.001,"us");
64 | is($value,1);
65 | is($unit,"ns");
66 | ($value,$unit) = $scheck->_normalize_value(1010,"ns");
67 | is($value,1.01);
68 | is($unit,"us");
69 |
70 | my $label = $scheck->_exit_message(code => &Monitoring::Plugin::OK,mode => "numeric",value => "2.1", unit => "MB");
71 | is($label,"Memory : Value 2.10 MB in range");
72 |
73 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/SpringDM.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::SpringDM;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 | use Data::Dumper;
8 |
9 | use Carp qw(croak);
10 |
11 | =head1 NAME
12 |
13 | JMX::Jmx4Perl::Product::SpringDM - Handler for Spring dm-Server.
14 |
15 | =head1 DESCRIPTION
16 |
17 | This is the product handler support for Spring dm Server
18 | (L).
19 |
20 | =cut
21 |
22 | sub id {
23 | return "springdm";
24 | }
25 |
26 | sub name {
27 | return "Spring dm-Server";
28 | }
29 |
30 | sub vendor {
31 | return "SpringSource";
32 | }
33 |
34 | sub order {
35 | return 300;
36 | }
37 |
38 | sub version {
39 | return shift->{version};
40 | }
41 |
42 | sub autodetect_pattern {
43 | return sub {
44 | my $self = shift;
45 | my $j4p = $self->{jmx4perl};
46 | my $ret = $j4p->search("com.springsource.kernel:name=com.springsource.kernel.agent.dm,*");
47 | #print Dumper($ret);
48 | if ($ret) {
49 | for my $n (@$ret) {
50 | my ($domain,$attrs) = $j4p->parse_name($n);
51 | if ($attrs->{version}) {
52 | $self->{version} = $attrs->{version};
53 | return 1;
54 | }
55 | }
56 | }
57 | return undef;
58 | };
59 | }
60 |
61 | =head1 LICENSE
62 |
63 | This file is part of jmx4perl.
64 |
65 | Jmx4perl is free software: you can redistribute it and/or modify
66 | it under the terms of the GNU General Public License as published by
67 | the Free Software Foundation, either version 2 of the License, or
68 | (at your option) any later version.
69 |
70 | jmx4perl is distributed in the hope that it will be useful,
71 | but WITHOUT ANY WARRANTY; without even the implied warranty of
72 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73 | GNU General Public License for more details.
74 |
75 | You should have received a copy of the GNU General Public License
76 | along with jmx4perl. If not, see .
77 |
78 | A commercial license is available as well. Please contact roland@cpan.org for
79 | further details.
80 |
81 | =head1 AUTHOR
82 |
83 | roland@cpan.org
84 |
85 | =cut
86 |
87 | 1;
88 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Tomcat.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Tomcat;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 |
8 | use Carp qw(croak);
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::Product::Tomcat - Handler for Apache Tomcat
13 |
14 | =head1 DESCRIPTION
15 |
16 | This is the product handler supporting Tomcat, Version 4, 5 and 6. (http://tomcat.apache.org/)
17 |
18 | =cut
19 |
20 | sub id {
21 | return "tomcat";
22 | }
23 |
24 | sub name {
25 | return "Apache Tomcat";
26 | }
27 |
28 | # Pure Tomcat must be *after* all App-Servers using tomcat as web container
29 | sub order {
30 | return 20;
31 | }
32 |
33 | sub _try_version {
34 | my $self = shift;
35 | my $ret = $self->try_attribute("version","Catalina:type=Server","serverInfo");
36 | if ($ret) {
37 | $self->{version} =~ s/^.*?\/?(\d.+)$/$1/;
38 | }
39 | return $ret;
40 | }
41 |
42 | sub autodetect_pattern {
43 | return "version";
44 | }
45 |
46 | sub vendor {
47 | return "Apache";
48 | }
49 |
50 | sub jsr77 {
51 | return 1;
52 | }
53 |
54 | sub init_aliases {
55 | return
56 | {
57 | attributes =>
58 | {
59 | #SERVER_ADDRESS => [ "jboss.system:type=ServerInfo", "HostAddress"],
60 | SERVER_HOSTNAME => [ "Catalina:type=Engine", "defaultHost"],
61 | },
62 | operations =>
63 | {
64 | #THREAD_DUMP => [ "jboss.system:type=ServerInfo", "listThreadDump"]
65 | }
66 | # Alias => [ "mbean", "attribute", "path" ]
67 | };
68 | }
69 |
70 | =head1 LICENSE
71 |
72 | This file is part of jmx4perl.
73 |
74 | Jmx4perl is free software: you can redistribute it and/or modify
75 | it under the terms of the GNU General Public License as published by
76 | the Free Software Foundation, either version 2 of the License, or
77 | (at your option) any later version.
78 |
79 | jmx4perl is distributed in the hope that it will be useful,
80 | but WITHOUT ANY WARRANTY; without even the implied warranty of
81 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82 | GNU General Public License for more details.
83 |
84 | You should have received a copy of the GNU General Public License
85 | along with jmx4perl. If not, see .
86 |
87 | A commercial license is available as well. Please contact roland@cpan.org for
88 | further details.
89 |
90 | =head1 AUTHOR
91 |
92 | roland@cpan.org
93 |
94 | =cut
95 |
96 | 1;
97 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Unknown.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Unknown;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use JMX::Jmx4Perl;
6 | use strict;
7 | use base "JMX::Jmx4Perl::Product::BaseHandler";
8 |
9 | use Carp qw(croak);
10 |
11 | =head1 NAME
12 |
13 | JMX::Jmx4Perl::Product::Unknown - Fallback handler
14 |
15 | =head1 DESCRIPTION
16 |
17 | This fallback handler runs always as I in the autodetection chain and
18 | provides at least informations about the platform MXMBeans which are available
19 | on any Java 5 platform.
20 |
21 | =cut
22 |
23 | sub id {
24 | return "unknown";
25 | }
26 |
27 | sub name {
28 | return "unknown";
29 | }
30 |
31 | # Highest ordering number
32 | sub order {
33 | return 1000;
34 | }
35 |
36 | sub info {
37 | my $self = shift;
38 | my $verbose = shift;
39 |
40 | my $ret = $self->jvm_info($verbose);
41 | $ret .= "-" x 80 . "\n";
42 | $ret .= "The application server's brand could not be auto-detected.\n";
43 | $ret .= "Known brands are: " . (join ", ",grep { $_ ne "unknown"} @JMX::Jmx4Perl::PRODUCT_HANDLER_ORDERING) . "\n\n";
44 | $ret .=
45 | "Please submit the output of 'jmx4perl list' and 'jmx4perl attributes' to\n" .
46 | "roland\@cpan.de in order to provide a new product handler in the next release\n";
47 | }
48 |
49 | sub autodetect {
50 | # Since we are the last one in the chain, we will be the one 'found'
51 | return 1;
52 | }
53 |
54 | sub version {
55 | return "";
56 | }
57 |
58 | sub jsr77 {
59 | return 0;
60 | }
61 |
62 |
63 | =head1 LICENSE
64 |
65 | This file is part of jmx4perl.
66 |
67 | Jmx4perl is free software: you can redistribute it and/or modify
68 | it under the terms of the GNU General Public License as published by
69 | the Free Software Foundation, either version 2 of the License, or
70 | (at your option) any later version.
71 |
72 | jmx4perl is distributed in the hope that it will be useful,
73 | but WITHOUT ANY WARRANTY; without even the implied warranty of
74 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 | GNU General Public License for more details.
76 |
77 | You should have received a copy of the GNU General Public License
78 | along with jmx4perl. If not, see .
79 |
80 | A commercial license is available as well. Please contact roland@cpan.org for
81 | further details.
82 |
83 | =head1 AUTHOR
84 |
85 | roland@cpan.org
86 |
87 | =cut
88 |
89 | 1;
90 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | 1.06
2 | ====
3 |
4 | - ${0} aufloesen (??? in den tests funktioniert .... hmmm)
5 | - jolokia: Auch ein sun-web.xml anlegen (ggfs.)
6 | - Agents nach OMD
7 | - 'refresh' in j4psh
8 |
9 | - Relative and delta checks combined (see mail from Reinhard)
10 | - Optional hide performance data (RT#75062)
11 | - RT#69167 - Alias resolution
12 | - RT#70892 - ePN
13 |
14 | - --unknown-is-critical in documentation of check_jmx4perl
15 | - wbelogic checks
16 | - Checks, if MBean is missing or existing
17 | - Matching auf value part or existance of keys in MBean names
18 | - Parameter durchreichen bei Pool-Checks
19 | - check_jmx4perl with pattern and path won't work on jolokia's side: java.lang:type=*/HeapMemoryUsage/used
20 |
21 | 04 Deployment instructions for various application servers
22 | 06 WS-Management integration ?
23 | 07 Path handling for operation return values
24 | 14 JSON Schema for protocol
25 | 16 SSL Support for jvm-agent-6
26 | 17 JVM agent with Jetty for Non Sun-JDK 6 environments
27 | 18 More unit tests
28 | 20 Pattern switching of history
29 | 22 Bug: Overloaded method with string array arguments
30 | gets parsed badly:
31 | No operation installBundles([Ljava.lang.String found on MBean osgi.core:type=framework,version=1.5
32 | 51 Versionscheck in Requests. Offer upgrade path and recommendations.
33 | 52 Local storage for history values (?)
34 | 53 Fail fast for --delta when Config-MBean is not available
35 |
36 | j4psh:
37 |
38 | 80 last_error handling in ServerHandler
39 | 81 Completion on MBeans with spaces
40 | 82 Formatting for overlength MBean lines
41 | (complete MBean->_lign_aligned)
42 | 83 Wildcard for 'cd' in MBean/Domain listing
43 | 84 'cat': Proper Error-Handling
44 | 85 Implement 'find/search' (attribute/operation names, content of attributes)
45 | 86 Implement 'version'
46 | 87 History Handling
47 | 88 Plugin architecture
48 | 89 Alias support
49 | 90 MBean Description for 'list' command
50 | 91 Bug: Glassfish, cat in servlet:
51 | [localhost:8080 com.sun.appserv:J2EEApplication=null, ...] : cat *
52 | Error: java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to java.lang.String at /opt/local/lib/perl5/site_perl/5.8.9/JMX/Jmx4Perl/J4psh/Command/MBean.pm line 155.
53 | 92 overloaded exec()
54 | 93 cd ../type=Memory (cd mit relativen Pfaden ..)
55 | 94 refresh()
56 | 93 Overloaded with void params
57 |
58 | java-client:
59 |
60 | 200 Respect redirect answers (jetty without trailing slash)
61 |
62 |
63 |
64 | Math::Pari --> dynamic download during build
--------------------------------------------------------------------------------
/docker/README.md:
--------------------------------------------------------------------------------
1 | ## Jmx4Perl Tools 1.12
2 |
3 | This Docker image is intended to provided an easy access to the [Jmx4Perl](https://metacpan.org/pod/distribution/jmx4perl) tools, i.e.
4 |
5 | * [**jmx4perl**](https://metacpan.org/pod/distribution/jmx4perl/scripts/jmx4perl) is a command line tool for one-shot querying a Jolokia agent. It is perfectly suited for shell scripts.
6 | * [**j4psh**](https://metacpan.org/pod/distribution/jmx4perl/scripts/j4psh) is a readline based, JMX shell with coloring and command line completion. You can navigate the JMX namespace like directories with `cd` and `ls`, read JMX attributes with `cat` and execute operations with `exec`.
7 | * [**jolokia**](https://metacpan.org/pod/distribution/jmx4perl/scripts/jolokia) is an agent management tool which helps you in downloading Jolokia agents of various types (war, jvm, osgi, mule) and versions. It also knows how to repackage agents e.g. for enabling security with the war agent by inplace modification of the web.xml descriptor.
8 | * [**check_jmx4perl**](https://metacpan.org/pod/distribution/jmx4perl/scripts/check_jmx4perl) is a full featured Nagios plugin.
9 |
10 | Please refer to the upstream tool documentation for details.
11 |
12 | Examples:
13 |
14 | ```shell
15 | # Get some basic information of the server
16 | docker run --rm -it jolokia/jmx4perl \
17 | jmx4perl http://localhost:8080/jolokia
18 |
19 | # Download the current jolokia.war agent
20 | docker run --rm -it -v `pwd`:/jolokia jolokia/jmx4perl \
21 | jolokia
22 |
23 | # Start a JMX shell. "tomcat" is defined in ~/.j4p/jmx4perl.config
24 | docker run --rm -it -v ~/.j4p:/root/.j4p jolokia/jmx4perl \
25 | j4psh tomcat
26 | ```
27 |
28 | In these examples we mounted some volumes:
29 |
30 | * If you put your server definitions into `~/.j4p/jmx4perl.config` you can use them by mounting this directory as volume with `-v ~/.j4p:/root/.j4p`.
31 | * For the management tool `jolokia` it is recommended to mount the local directory with `-v $(pwd):/jolokia` so that downloaded artefacts are stored in the current host directory. (Note for boot2docker users: This works only when you are in a directory below you home directory)
32 |
33 | To simplify the usage, the following aliases are recommended:
34 |
35 | ```
36 | alias jmx4perl="docker run --rm -it -v ~/.j4p:/root/.j4p jolokia/jmx4perl jmx4perl"
37 | alias jolokia="docker run --rm -it -v `pwd`:/jolokia jolokia/jmx4perl jolokia"
38 | alias j4psh="docker run --rm -it -v ~/.j4p:/root/.j4p jolokia/jmx4perl j4psh"
39 | ```
40 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Websphere.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Websphere;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 |
8 | use Carp qw(croak);
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::Product::Websphere - Handler for IBM Websphere
13 |
14 | =head1 DESCRIPTION
15 |
16 | This is the product handler support for IBM Websphere Application Server 6 and
17 | 7 (L)
18 |
19 | =cut
20 |
21 | sub id {
22 | return "websphere";
23 | }
24 |
25 | sub name {
26 | return "IBM Websphere Application Server";
27 | }
28 |
29 |
30 | sub version {
31 | return shift->_version_or_vendor("version",qr/^Version\s+(\d.*)\s*$/m);
32 | }
33 |
34 | sub autodetect_pattern {
35 | return (shift->original_version_sub,qr/IBM\s+WebSphere\s+Application\s+Server/i);
36 | }
37 |
38 | sub order {
39 | return 100;
40 | }
41 |
42 | sub jsr77 {
43 | return 1;
44 | }
45 |
46 | sub init_aliases {
47 | my $self = shift;
48 | return {
49 | attributes => {
50 | OS_CPU_TIME => 0, # Don't support these ones
51 | OS_FILE_DESC_MAX => 0,
52 | OS_FILE_DESC_OPEN => 0,
53 | OS_MEMORY_PHYSICAL_FREE => 0,
54 | OS_MEMORY_PHYSICAL_TOTAL => 0,
55 | OS_MEMORY_SWAP_FREE => 0,
56 | OS_MEMORY_SWAP_TOTAL => 0,
57 | OS_MEMORY_VIRTUAL => 0
58 | }
59 | };
60 | }
61 |
62 | =head1 LICENSE
63 |
64 | This file is part of jmx4perl.
65 |
66 | Jmx4perl is free software: you can redistribute it and/or modify
67 | it under the terms of the GNU General Public License as published by
68 | the Free Software Foundation, either version 2 of the License, or
69 | (at your option) any later version.
70 |
71 | jmx4perl is distributed in the hope that it will be useful,
72 | but WITHOUT ANY WARRANTY; without even the implied warranty of
73 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74 | GNU General Public License for more details.
75 |
76 | You should have received a copy of the GNU General Public License
77 | along with jmx4perl. If not, see .
78 |
79 | A commercial license is available as well. Please contact roland@cpan.org for
80 | further details.
81 |
82 | =head1 AUTHOR
83 |
84 | roland@cpan.org
85 |
86 | =cut
87 |
88 | 1;
89 |
--------------------------------------------------------------------------------
/it/t/64_check_perfdata.t:
--------------------------------------------------------------------------------
1 | use strict;
2 | use warnings;
3 | use Test::More qw(no_plan);
4 | use Data::Dumper;
5 | use JMX::Jmx4Perl::Alias;
6 | use It;
7 | use FindBin;
8 |
9 | require "check_jmx4perl/base.pl";
10 |
11 | my $jmx = It->new(verbose =>0)->jmx4perl;
12 | my ($ret,$content);
13 |
14 | # ====================================================
15 | # Given as command line
16 |
17 | ($ret,$content) = exec_check_perl4jmx("--value java.lang:type=Memory/HeapMemoryUsage/used " .
18 | "--base java.lang:type=Memory/HeapMemoryUsage/max " .
19 | "--critical 90 " .
20 | "--perfdata no");
21 |
22 | ok($content !~ /\s*\|\s*/,"1: Content contains no perfdata");
23 | ($ret,$content) = exec_check_perl4jmx("--value java.lang:type=Memory/HeapMemoryUsage/used " .
24 | "--base java.lang:type=Memory/HeapMemoryUsage/max " .
25 | "--warn 80 " .
26 | "--critical 90 " .
27 | "--perfdata %");
28 | ok($content =~ /\s*\|\s*/,"2: Content contains perfdata");
29 | ok($content =~ /80;90/,"2a: Perfdata is relative");
30 | print Dumper($ret,$content);
31 |
32 | ($ret,$content) = exec_check_perl4jmx("--mbean java.lang:type=Threading " .
33 | "--operation findDeadlockedThreads " .
34 | "--null 'nodeadlock' " .
35 | "--string " .
36 | "--critical '!nodeadlock'");
37 | ok($content !~ /\s*\|\s*/,"3: Content contains no perfdata");
38 |
39 | # ====================================================
40 | # Given in config
41 |
42 | my $config_file = $FindBin::Bin . "/../check_jmx4perl/checks.cfg";
43 | ($ret,$content) = exec_check_perl4jmx("--config $config_file " .
44 | "--check thread_deadlock");
45 | ok($content !~ /\s*\|\s*/,"4: Content contains no perfdata");
46 |
47 | ($ret,$content) = exec_check_perl4jmx("--config $config_file " .
48 | "--check memory_without_perfdata");
49 | #print Dumper($ret,$content);
50 |
51 | ok($content !~ /\s*\|\s*/,"5: Content contains no perfdata");
52 |
53 | ($ret,$content) = exec_check_perl4jmx("--config $config_file " .
54 | "--check memory_with_perfdata");
55 | #print Dumper($ret,$content);
56 | ok($content =~ /\s*\|\s*/,"6: Content contains perfdata");
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Agent/Jolokia/Verifier/ChecksumVerifier.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Agent::Jolokia::Verifier::ChecksumVerifier;
3 |
4 | =head1 NAME
5 |
6 | JMX::Jmx4Perl::Agent::Jolokia::Verifier::ChecksumVerifier - Verifies a
7 | checksum for a downloaded artifact.
8 |
9 | =head1 DESCRIPTION
10 |
11 | This verifier provides the base for simple checksum checking. It needs to be
12 | subclassed to provide the proper extension (e.g. ".sha1") and creating of a
13 | digester.
14 |
15 | =cut
16 |
17 |
18 | use strict;
19 |
20 | sub new {
21 | my $class = shift;
22 | my $self = {};
23 | bless $self,(ref($class) || $class);
24 | }
25 |
26 | sub extension {
27 | die "abstract";
28 | }
29 |
30 | sub name {
31 | die "abstract";
32 | }
33 |
34 | sub create_digester {
35 | die "abstract";
36 | }
37 |
38 | sub verify {
39 | my $self = shift;
40 | my %args = @_;
41 | my $logger = $args{logger};
42 | my $sig = $args{signature};
43 | chomp $sig;
44 | $sig =~ s/^([^\s]+).*$/$1/;
45 | my $digester = $self->create_digester;
46 | my $file = $args{path};
47 | if ($file) {
48 | open (my $fh, "<", $file) || ($logger->error("Cannot open $file for ",$self->name," check: $!") && die "\n");
49 | $digester->addfile($fh);
50 | close $fh;
51 | } else {
52 | my $data = $args{data};
53 | $digester->add($data);
54 | }
55 | my $sig_calc = $digester->hexdigest;
56 | if (lc($sig) eq lc($sig_calc)) {
57 | $logger->info("Passed ",$self->name," check (" . $sig_calc . ")",($file ? " for file $file" : ""));
58 | } else {
59 | $logger->error("Failed ",$self->name," check. Got: " . $sig_calc . ", Expected: " . $sig);
60 | die "\n";
61 | }
62 | }
63 |
64 | =head1 LICENSE
65 |
66 | This file is part of jmx4perl.
67 | Jmx4perl is free software: you can redistribute it and/or modify
68 | it under the terms of the GNU General Public License as published by
69 | The Free Software Foundation, either version 2 of the License, or
70 | (at your option) any later version.
71 |
72 | jmx4perl is distributed in the hope that it will be useful,
73 | but WITHOUT ANY WARRANTY; without even the implied warranty of
74 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 | GNU General Public License for more details.
76 |
77 | You should have received a copy of the GNU General Public License
78 | along with jmx4perl. If not, see .
79 |
80 | A commercial license is available as well. Please contact roland@cpan.org for
81 | further details.
82 |
83 | =head1 AUTHOR
84 |
85 | roland@cpan.org
86 |
87 | =cut
88 |
89 | 1;
90 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Glassfish.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Glassfish;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 |
8 | use Carp qw(croak);
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::Product::Glassfish - Handler for Glassfish
13 |
14 | =head1 DESCRIPTION
15 |
16 | This handler supports glassfish up to version 3.1
17 | (L)
18 |
19 | =cut
20 |
21 | sub id {
22 | return "glassfish";
23 | }
24 |
25 | sub name {
26 | return "Glassfish";
27 | }
28 |
29 | sub version {
30 | my $self = shift;
31 | my $version = $self->_version_or_vendor("version",qr/([\d\.]+)/m);
32 | return $version if $version;
33 |
34 | # Try for Glassfish V3
35 | my $jmx = $self->{jmx4perl};
36 |
37 | my $servers = $jmx->search("com.sun.appserv:type=Host,*");
38 | if ($servers) {
39 | $self->{"original_version"} = "GlassFish V3";
40 | $self->{"version"} = "3";
41 | return "3";
42 | }
43 | return undef;
44 | }
45 |
46 | sub vendor {
47 | return "Oracle";
48 | }
49 |
50 | sub autodetect_pattern {
51 | return (shift->original_version_sub,qr/GlassFish/i);
52 | }
53 |
54 | sub jsr77 {
55 | return 1;
56 | }
57 |
58 | sub init_aliases {
59 | return
60 | {
61 | attributes =>
62 | {
63 | },
64 | operations =>
65 | {
66 | THREAD_DUMP => [ "com.sun.appserv:category=monitor,server=server,type=JVMInformation", "getThreadDump"]
67 | }
68 | # Alias => [ "mbean", "attribute", "path" ]
69 | };
70 | }
71 |
72 |
73 | =head1 LICENSE
74 |
75 | This file is part of jmx4perl.
76 |
77 | Jmx4perl is free software: you can redistribute it and/or modify
78 | it under the terms of the GNU General Public License as published by
79 | the Free Software Foundation, either version 2 of the License, or
80 | (at your option) any later version.
81 |
82 | jmx4perl is distributed in the hope that it will be useful,
83 | but WITHOUT ANY WARRANTY; without even the implied warranty of
84 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85 | GNU General Public License for more details.
86 |
87 | You should have received a copy of the GNU General Public License
88 | along with jmx4perl. If not, see .
89 |
90 | A commercial license is available as well. Please contact roland@cpan.org for
91 | further details.
92 |
93 | =head1 AUTHOR
94 |
95 | roland@cpan.org
96 |
97 | =cut
98 |
99 | 1;
100 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/PodParser.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::PodParser;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use vars qw(@ISA);
8 |
9 | sub new {
10 | # Perl is so fun.
11 | my $package = shift;
12 |
13 | my $self;
14 |
15 | # Try using Pod::Parser first
16 | if (eval{ require Pod::Parser; 1; }) {
17 | @ISA = qw(Pod::Parser);
18 | $self = $package->SUPER::new(@_);
19 | $self->{have_pod_parser} = 1;
20 | } else {
21 | @ISA = ();
22 | *parse_from_filehandle = \&_myparse_from_filehandle;
23 | $self = bless {have_pod_parser => 0, @_}, $package;
24 | }
25 |
26 | unless ($self->{fh}) {
27 | die "No 'file' or 'fh' parameter given" unless $self->{file};
28 | $self->{fh} = IO::File->new($self->{file}) or die "Couldn't open $self->{file}: $!";
29 | }
30 |
31 | return $self;
32 | }
33 |
34 | sub _myparse_from_filehandle {
35 | my ($self, $fh) = @_;
36 |
37 | local $_;
38 | while (<$fh>) {
39 | next unless /^=(?!cut)/ .. /^=cut/; # in POD
40 | last if ($self->{abstract}) = /^ (?: [a-z:]+ \s+ - \s+ ) (.*\S) /ix;
41 | }
42 |
43 | my @author;
44 | while (<$fh>) {
45 | next unless /^=head1\s+AUTHORS?/ ... /^=/;
46 | next if /^=/;
47 | push @author, $_ if /\@/;
48 | }
49 | return unless @author;
50 | s/^\s+|\s+$//g foreach @author;
51 |
52 | $self->{author} = \@author;
53 |
54 | return;
55 | }
56 |
57 | sub get_abstract {
58 | my $self = shift;
59 | return $self->{abstract} if defined $self->{abstract};
60 |
61 | $self->parse_from_filehandle($self->{fh});
62 |
63 | return $self->{abstract};
64 | }
65 |
66 | sub get_author {
67 | my $self = shift;
68 | return $self->{author} if defined $self->{author};
69 |
70 | $self->parse_from_filehandle($self->{fh});
71 |
72 | return $self->{author} || [];
73 | }
74 |
75 | ################## Pod::Parser overrides ###########
76 | sub initialize {
77 | my $self = shift;
78 | $self->{_head} = '';
79 | $self->SUPER::initialize();
80 | }
81 |
82 | sub command {
83 | my ($self, $cmd, $text) = @_;
84 | if ( $cmd eq 'head1' ) {
85 | $text =~ s/^\s+//;
86 | $text =~ s/\s+$//;
87 | $self->{_head} = $text;
88 | }
89 | }
90 |
91 | sub textblock {
92 | my ($self, $text) = @_;
93 | $text =~ s/^\s+//;
94 | $text =~ s/\s+$//;
95 | if ($self->{_head} eq 'NAME') {
96 | my ($name, $abstract) = split( /\s+-\s+/, $text, 2 );
97 | $self->{abstract} = $abstract;
98 | } elsif ($self->{_head} =~ /^AUTHORS?$/) {
99 | push @{$self->{author}}, $text if $text =~ /\@/;
100 | }
101 | }
102 |
103 | sub verbatim {}
104 | sub interior_sequence {}
105 |
106 | 1;
107 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Jetty.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Jetty;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use strict;
6 | use base "JMX::Jmx4Perl::Product::BaseHandler";
7 |
8 | use Carp qw(croak);
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::Product::Jetty - Handler for Jetty
13 |
14 | =head1 DESCRIPTION
15 |
16 | This is the product handler support Jetty. It supports Jetty version 5, 6 and 7.
17 | (L)
18 |
19 | Please note, that you must have JMX support enabled in Jetty for autodetection
20 | and aliasing to work. See the Jetty documentation for details.
21 |
22 | =cut
23 |
24 | sub id {
25 | return "jetty";
26 | }
27 |
28 | sub name {
29 | return "Jetty";
30 | }
31 |
32 | sub _try_version {
33 | my $self = shift;
34 | my $jmx = $self->{jmx4perl};
35 |
36 | # Jetty V6 & 7
37 | my $servers = $jmx->search("*:id=0,type=server,*");
38 | my $ret;
39 | if ($servers) {
40 | $ret = $self->try_attribute("version",$servers->[0],"version");
41 | }
42 |
43 | # Jetty V5
44 | if (!length($self->{version})) {
45 | delete $self->{version};
46 | $ret = $self->try_attribute("version","org.mortbay:jetty=default","version");
47 | }
48 |
49 | $self->{version} =~ s/Jetty\/([^\s]+).*/$1/;
50 | return $ret;
51 | }
52 |
53 | sub autodetect_pattern {
54 | return "version";
55 | }
56 |
57 | sub vendor {
58 | return "Mortbay";
59 | }
60 |
61 | sub jsr77 {
62 | return 0;
63 | }
64 |
65 | sub init_aliases {
66 | return
67 | {
68 | attributes =>
69 | {
70 | },
71 | operations =>
72 | {
73 | THREAD_DUMP => [ "jboss.system:type=ServerInfo", "listThreadDump"]
74 | }
75 | # Alias => [ "mbean", "attribute", "path" ]
76 | };
77 | }
78 |
79 |
80 | =head1 LICENSE
81 |
82 | This file is part of jmx4perl.
83 |
84 | Jmx4perl is free software: you can redistribute it and/or modify
85 | it under the terms of the GNU General Public License as published by
86 | the Free Software Foundation, either version 2 of the License, or
87 | (at your option) any later version.
88 |
89 | jmx4perl is distributed in the hope that it will be useful,
90 | but WITHOUT ANY WARRANTY; without even the implied warranty of
91 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92 | GNU General Public License for more details.
93 |
94 | You should have received a copy of the GNU General Public License
95 | along with jmx4perl. If not, see .
96 |
97 | A commercial license is available as well. Please contact roland@cpan.org for
98 | further details.
99 |
100 | =head1 AUTHOR
101 |
102 | roland@cpan.org
103 |
104 | =cut
105 |
106 | 1;
107 |
--------------------------------------------------------------------------------
/it/t/53_check_non_numeric.t:
--------------------------------------------------------------------------------
1 | use strict;
2 | use warnings;
3 | use Test::More qw(no_plan);
4 | use Data::Dumper;
5 | use It;
6 |
7 | require "check_jmx4perl/base.pl";
8 |
9 | my $jmx = It->new(verbose =>0)->jmx4perl;
10 | my ($ret,$content);
11 |
12 | # ====================================================
13 | # Non-numerice Attributes return value check
14 |
15 | # Boolean values
16 | $jmx->execute("jolokia.it:type=attribute","reset");
17 |
18 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute State --critical false");
19 | #print ($ret,$content);
20 | is($ret,0,"Boolean: OK");
21 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute State --critical false");
22 | is($ret,2,"Boolean: CRITICAL");
23 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute State --critical false --warning true");
24 | is($ret,1,"Boolean: WARNING");
25 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute State --critical false --warning true");
26 | is($ret,2,"Boolean (as String): CRITICAL");
27 |
28 | # String values
29 | $jmx->execute("jolokia.it:type=attribute","reset");
30 |
31 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute String --critical Started");
32 | is($ret,2,"String: CRITICAL");
33 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute String --critical Started");
34 | is($ret,0,"String: OK");
35 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute String --critical !Started");
36 | is($ret,0,"String: OK");
37 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute String --critical !Started");
38 | is($ret,2,"String: CRITICAL");
39 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute String --critical Stopped --warning qr/art/");
40 | is($ret,1,"String: WARNING");
41 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute String --critical qr/^St..p\\wd\$/ --warning qr/art/");
42 | is($ret,2,"String: CRITICAL");
43 |
44 | # Check for a null value
45 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute Null --critical null");
46 | is($ret,2,"null: CRITICAL");
47 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute Null --critical null --null bla");
48 | is($ret,0,"null: OK");
49 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute Null --critical bla --null bla");
50 | is($ret,2,"null: CRITICAL");
51 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute Null --critical !null --string");
52 | is($ret,0,"null: OK");
53 |
54 | # Check for a string array value
55 | ($ret,$content) = exec_check_perl4jmx("--mbean jolokia.it:type=attribute --attribute StringArray --string --critical qr/Stopped/");
56 | is($ret,2,"String Array: CRITICAL");
57 | ok($content =~ /Stopped/,"Matches Threshhold");
58 |
59 |
60 |
--------------------------------------------------------------------------------
/config/websphere/jdbc.cfg:
--------------------------------------------------------------------------------
1 | # ==============================================================================
2 | # JDBC Datasources
3 |
4 | # JDBC Poolsize Check. This check requires two parameters at least:
5 | # The name of th JDBC Provider and the data source name. It must be ensured that
6 | # the pattern used in this check must result in a single data source only.
7 | #
8 | # In order to specify this even further, a fourth parameter can be used to
9 | # match on part of the mbeanIdentifier.
10 | #
11 | # ${0} : Name of the JDBC Provider
12 | # ${1} : DataSource Name
13 | # ${2} : Critical (default: 90%)
14 | # ${3} : Warning (default: 80%)
15 | # ${4} : Part of mbeanIdentifier (default: *)
16 |
17 |
18 | MBean WebSphere:j2eeType=JDBCResource,name=${0},mbeanIdentifier=${4:*},*
19 | Attribute stats
20 | Path */*/connectionPools/${1}/statistics/PercentUsed/current
21 |
22 | Critical ${2:90}
23 | Warning ${3:80}
24 |
25 | Label $1 : %2.0f % DB Connections used
26 | Name jdbc-$0-connections
27 |
28 |
29 | # Average wait time until a connection is obtained
30 |
31 | # ${0} : Name of the JDBC Provider
32 | # ${1} : Datasource name
33 | # ${2} : Critical (default: 10s)
34 | # ${3} : Warning (default: 5s)
35 | # ${4} : Part of mbeanIdentifier (default: *)
36 |
37 | MBean WebSphere:j2eeType=JDBCResource,name=${0},mbeanIdentifier=${4:*},*
38 | Attribute stats
39 | Path */*/connectionPools/${1}/statistics/WaitTime/totalTime
40 |
41 | BaseMBean WebSphere:j2eeType=JDBCResource,name=${0},mbeanIdentifier=${4:*},*
42 | BaseAttribute stats
43 | BasePath */*/connectionPools/${1}/statistics/WaitTime/count
44 |
45 | Critical ${2:10000}
46 | Warning ${3:5000}
47 |
48 | Label $1: %2.2q ms ∅ waiting time (%v ms total for %b requests)
49 | Name jdbc-$0-average-wait-time
50 |
51 |
52 | # Check for the number of rolled back transactions
53 | #
54 | # $0: Part of the MBean identifier
55 | # $1: Critical as rollback count / minute
56 | # $2: Warning as rollback count / minute
57 |
58 | Use was_transaction_count($0,"RolledbackCount",$1,$2)
59 |
60 |
61 | # Check for the number of active transactions
62 | #
63 | # $0: Part of the MBean identifier
64 | # $1: Critical as rollback count / minute
65 | # $2: Warning as rollback count / minute
66 |
67 | Use was_transaction_count($0,"ActiveCount",$1,$2)
68 |
69 |
70 | # Base-Check for the number of transactions
71 | #
72 | # $0: Part of the MBean identifier
73 | # $1: Attribute name
74 | # $2: Critical as rollback count / minute
75 | # $3: Warning as rollback count / minute
76 |
77 | MBean WebSphere:type=TransactionService,mbeanIdentifier=*${0}*,*
78 | Attribute stats
79 | Path */*/statistics/${1}/count
80 | Delta 60
81 |
82 | Critical ${2:10}
83 | Warning ${3:5}
84 |
85 | Label $0 : %2.2q ${1} / minute
86 | Name $1-$0-transaction
87 |
88 |
89 |
--------------------------------------------------------------------------------
/it/t/95_cors.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 |
5 | use Test::More (tests => 14);
6 | use LWP::UserAgent;
7 | use Data::Dumper;
8 | use IO::Socket::SSL;
9 | use strict;
10 |
11 | my $url = $ENV{JMX4PERL_GATEWAY} || $ARGV[0];
12 | $url .= "/" unless $url =~ /\/$/;
13 | my $origin = "http://localhost:8080";
14 | my $ua = new LWP::UserAgent(ssl_opts => {
15 | verify_hostname => 0,
16 | SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE
17 | });
18 |
19 | if ($ENV{JMX4PERL_USER}) {
20 | my $netloc = $url;
21 | $netloc =~ s|^.*/([^:]+:\d+).*$|$1|;
22 | $ua->credentials($netloc,"jolokia",$ENV{JMX4PERL_USER},$ENV{JMX4PERL_PASSWORD});
23 | }
24 |
25 | $ua->default_headers()->header("Origin" => $origin);
26 |
27 | # Test for CORS functionality. This is done without Jmx4Perl client library but
28 | # with direct requests
29 |
30 | # 1) Preflight Checks
31 | my $req = new HTTP::Request("OPTIONS",$url);
32 |
33 | my $resp = $ua->request($req);
34 | print Dumper($resp);
35 | is($resp->header('Access-Control-Allow-Origin'),$origin,"Access-Control-Allow Origin properly set");
36 | ok($resp->header('Access-Control-Max-Age') > 0,"Max Age set");
37 | ok(!$resp->header('Access-Control-Allow-Request-Header'),"No Request headers set");
38 | $req->header("Access-Control-Request-Headers","X-Extra, X-Extra2");
39 | $req->header('X-Extra',"bla");
40 | $resp = $ua->request($req);
41 | is($resp->header('Access-Control-Allow-Headers'),'X-Extra, X-Extra2',"Allowed headers");
42 |
43 | # 2) GET Requests with "Origin:"
44 | $req = new HTTP::Request("GET",$url . "/read/java.lang:type=Memory/HeapMemoryUsage");
45 | $resp = $ua->request($req);
46 |
47 | verify_resp("GET",$resp);
48 |
49 | # 3) POST Requests with "Origin:"
50 | $req = new HTTP::Request("POST",$url);
51 | $req->content(<request($req);
60 |
61 | verify_resp("POST",$resp);
62 |
63 | # 4) POST Request with "Origin:" and error
64 |
65 | $req = new HTTP::Request("POST",$url);
66 | $req->content(<request($req);
72 |
73 | verify_resp("POST-Error",$resp);
74 |
75 | # 5) Try request splitting attack
76 |
77 | my $ua2 = new LWP::UserAgent();
78 | $req = new HTTP::Request("GET",$url . "/read/java.lang:type=Memory/HeapMemoryUsage");
79 | $req->header("Origin","http://bla.com\r\n\r\nInjected content");
80 | $resp = $ua2->request($req);
81 | ok($resp->header('Access-Control-Allow-Origin') !~ /[\r\n]/,"No new lines included");
82 | #print Dumper($resp);
83 |
84 | # ---------------------------------------------
85 |
86 | sub verify_resp {
87 | my $pref = shift;
88 | my $resp = shift;
89 |
90 | is($resp->header('Access-Control-Allow-Origin'),$origin,"$pref: Access-Control-Allow Origin properly set");
91 | ok(!$resp->header('Access-Control-Allow-Max-Age'),"$pref: No Max Age set");
92 | ok(!$resp->header('Access-Control-Allow-Request-Header'),"$pref: No Request headers set");
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/t/30_request.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use strict;
4 | use warnings;
5 | use FindBin qw($Bin);
6 | use lib qq($Bin/lib);
7 |
8 | use Test::More tests => 35;
9 |
10 | BEGIN {
11 | use_ok("JMX::Jmx4Perl::Request");
12 | use_ok("JMX::Jmx4Perl::Agent");
13 | }
14 |
15 | ok(READ eq "read","Import of constants");
16 |
17 | my $names =
18 | {
19 | "jmx4perl.it:name=\"name\\*with\\?strange=\\\"chars\",type=escape" => 0,
20 | "*:*" => 1,
21 | "*:type=bla" => 1,
22 | "domain:*" => 1,
23 | "domain:name=blub,*" => 1,
24 | "domain:name=*,type=blub" => 1,
25 | "domain:name=*,*" => 1,
26 | "domain:name=\"\\*\",type=blub" => 0,
27 | "domain:name" => 0,
28 | "domain:name=Bla*blub" => 1,
29 | "domain:name=\"Bla\\*blub\"" => 0,
30 | "domain:name=\"Bla\\*?blub\"" => 1,
31 | "domain:name=\"Bla\\*\\?blub\"" => 0,
32 | "domain:name=\"Bla\\*\\?blub\",type=?" => 1,
33 | "do*1:name=bla" => 1,
34 | "do?1:name=bla" => 1
35 | };
36 |
37 | for my $name (keys %$names) {
38 | my $req = new JMX::Jmx4Perl::Request(READ,$name,"attribute");
39 | my $is_pattern = $req->is_mbean_pattern;
40 | is($is_pattern,$names->{$name},"Pattern: $name");
41 | }
42 |
43 | # Check for autodetection of requests
44 | my $name="domain:attr=val";
45 | my $req = new JMX::Jmx4Perl::Request(READ,$name,"attribute");
46 | is($req->method(),undef,"Method not defined");
47 | $req = new JMX::Jmx4Perl::Request(READ,$name,"attribute",{method => "PoSt"});
48 | is($req->method(),"POST","Post method");
49 | $req = new JMX::Jmx4Perl::Request(READ,$name,["a1","a2"]);
50 | is($req->method(),"POST","Read with attribute refs need POST");
51 | eval {
52 | $req = new JMX::Jmx4Perl::Request(READ,$name,["a1","a2"],{method => "GET"});
53 | };
54 | ok($@,"No attributes with GET");
55 |
56 | # Regexp for squeezing trailing slashes (RT#89108)
57 | my $regexps = {
58 | new => 's|((?:!/)?/)/*|$1|g',
59 | old => 's|(!/)?/+|$1/|g'
60 | };
61 | my $data = {
62 | '!////' => '!//',
63 | '////' => '/',
64 | '/' => '/',
65 | '!/' => '!/'
66 | };
67 | for my $d (keys %$data) {
68 | no warnings;
69 | for my $re (keys %$regexps) {
70 | my $test = $d;
71 | my $expected = $data->{$d};
72 | eval '$^W = 0; $test =~ ' . $regexps->{$re};
73 | is($test,$expected,"Squeezing regexp '" . $re ."' : ".$d." --> ".$test);
74 | }
75 | }
76 |
77 | # Check slash escaping in LIST requests (issue#64)
78 | my @list = (
79 | [['domain:name=value'], 'dummy/list/domain/name%3Dvalue'],
80 | [['domain:name=a/b/c'], 'dummy/list/domain/name%3Da!/b!/c'],
81 | [['domain:name=value', 'x/y'], 'dummy/list/domain/name%3Dvalue/x/y'],
82 | [['domain:name=a/b/c', 'x/y'], 'dummy/list/domain/name%3Da!/b!/c/x/y'],
83 | );
84 | my $agent = JMX::Jmx4Perl::Agent->new(url => 'dummy');
85 | for my $test (@list) {
86 | my $req = JMX::Jmx4Perl::Request->new(LIST,@{$test->[0]});
87 | my $url = $agent->request_url($req);
88 | is($url,$test->[1],"request_url(@{$test->[0]})");
89 | }
90 |
--------------------------------------------------------------------------------
/config/weblogic.cfg:
--------------------------------------------------------------------------------
1 | # Weblogic specific checks
2 | # ========================================================
3 |
4 | include common.cfg
5 |
6 |
7 | Use = count_per_minute("bytes received")
8 | Label = Channel $0 : $BASE
9 | Name = bytes_received
10 | Value = *:Name=$0,Type=ServerChannelRuntime,*/BytesReceivedCount
11 | Critical = ${1:104857600}
12 | Warning = ${2:83886080}
13 |
14 |
15 |
16 | Use = count_per_minute("bytes sent")
17 | Label = Channel $0 : $BASE
18 | Name = bytes_sent
19 | Value = *:Name=$0,Type=ServerChannelRuntime,*/BytesSentCount
20 | Critical = ${1:104857600}
21 | Warning = ${2:83886080}
22 |
23 |
24 |
25 | Label = Channel $0 : %4.4v active connections
26 | Name = connections
27 | Value = *:Name=$0,Type=ServerChannelRuntime,*/ConnectionsCount
28 | Critical = ${1:1000}
29 | Warning = ${2:800}
30 |
31 |
32 |
33 | Value = *:Type=WebAppComponentRuntime,ApplicationRuntime=$0,*/DeploymentState
34 | String = 1
35 | Label = $0 is running
36 | Name = running
37 | Critical = !1
38 |
39 |
40 |
41 | Value = *:Type=ServletRuntime,ApplicationRuntime=$0,Name=$1,*/ExecutionTimeAverage
42 | Label = $0 [$1] : Average execution time %d ms
43 | Name = servlet_avg_execution_time
44 | Critical = ${2:20000}
45 | Warning = ${3:10000}
46 |
47 |
48 |
49 | Value = *:Type=WseeOperationRuntime,ApplicationRuntime=$0,Name=$1,*/ExecutionTimeAverage
50 | Label = WS $0 [$1] : Average execution time %d ms
51 | Name = ws_avg_execution_time
52 | Critical = ${2:150000}
53 | Warning = ${3:100000}
54 |
55 |
56 |
57 | Value = *:Type=WseeOperationRuntime,ApplicationRuntime=$0,Name=$1,*/ResponseTimeAverage
58 | Label = WS $0 [$1] : Average response time %d ms
59 | Name = ws_avg_execution_time
60 | Critical = ${2:150000}
61 | Warning = ${3:100000}
62 |
63 |
64 |
65 | Value = *:Type=WseeOperationRuntime,ApplicationRuntime=$0,Name=$1,*/ResponseErrorCount
66 | Label = WS $0 [$1] : Response error count %d
67 | Name = ws_response_errors
68 | Critical = ${2:10}
69 | Warning = ${3:5}
70 |
71 |
72 |
73 | Value = *:Type=WorkManagerRuntime,ApplicationRuntime=$0,Name=$1,*/PendingRequests
74 | Label = WorkManager $0 [$1] : Pending requests %d
75 | Name = ws_wm_pending_requests
76 | Critical = ${2:10}
77 | Warning = ${3:5}
78 |
79 |
80 |
81 | Value = *:Type=WorkManagerRuntime,ApplicationRuntime=$0,Name=$1,*/StuckThreadCount
82 | Label = WorkManager $0 [$1] : Stuck threads %d
83 | Name = ws_wm_stuck_threads
84 | Critical = ${2:10}
85 | Warning = ${3:5}
86 |
87 |
88 |
89 | Value = *:Type=WebAppComponentRuntime,ApplicationRuntime=$0,*/OpenSessionsCurrentCount
90 | Label = Webapp $0 : Open sessions %d
91 | Name = ws_webapp_sessions
92 | Critical = ${1:2000}
93 | Warning = ${2:1500}
94 |
95 |
96 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Alias/Object.pm:
--------------------------------------------------------------------------------
1 | package JMX::Jmx4Perl::Alias::Object;
2 |
3 | =head1 NAME
4 |
5 | JMX::Jmx4Perl::Alias::Object - Internal object representing a concrete alias
6 |
7 | =head1 DESCRIPTION
8 |
9 | Simple object which describes an alias. It knows about the following read-only
10 | methods
11 |
12 | =over
13 |
14 | =item $alias->alias()
15 |
16 | alias name in uppercase form (e.g. C)
17 |
18 | =item $alias->name()
19 |
20 | alias name in lowercase format (e.g. C)
21 |
22 | =item $alias->description()
23 |
24 | short description of the alias
25 |
26 | =item $alias->default()
27 |
28 | default values for an alias, which can be overwritten by a specific
29 | L. This is an arrayref with two values:
30 | The MBean's name and the attribute or operation name.
31 |
32 | =item $alias->type()
33 |
34 | Either C or C, depending on what kind of MBean part the
35 | alias stands for.
36 |
37 | =back
38 |
39 | Additional, the C<"">, C<==> and C operators are overloaded to naturally
40 | compare and stringify alias values.
41 |
42 | =cut
43 |
44 | use Scalar::Util qw(refaddr);
45 |
46 | use overload
47 | q{""} => sub { (shift)->as_string(@_) },
48 | q{==} => sub { (shift)->equals(@_) },
49 | q{!=} => sub { !(shift)->equals(@_) };
50 |
51 | sub equals {
52 | return (ref $_[0] eq ref $_[1] && refaddr $_[0] == refaddr $_[1]) ? 1 : 0;
53 | }
54 |
55 | sub new {
56 | my $class = shift;
57 | return bless { @_ },ref($class) || $class;
58 | }
59 |
60 | sub as_string { return $_[0]->{alias}; }
61 | sub alias { return shift->{alias}; }
62 | sub name { return shift->{name}; }
63 | sub description { return shift->{description}; }
64 | sub default { return shift->{default}; }
65 | sub type { return shift->{type}; }
66 |
67 | =head1 LICENSE
68 |
69 | This file is part of jmx4perl.
70 |
71 | Jmx4perl is free software: you can redistribute it and/or modify
72 | it under the terms of the GNU General Public License as published by
73 | the Free Software Foundation, either version 2 of the License, or
74 | (at your option) any later version.
75 |
76 | jmx4perl is distributed in the hope that it will be useful,
77 | but WITHOUT ANY WARRANTY; without even the implied warranty of
78 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79 | GNU General Public License for more details.
80 |
81 | You should have received a copy of the GNU General Public License
82 | along with jmx4perl. If not, see .
83 |
84 | A commercial license is available as well. Please contact roland@cpan.org for
85 | further details.
86 |
87 | =head1 PROFESSIONAL SERVICES
88 |
89 | Just in case you need professional support for this module (or Nagios or JMX in
90 | general), you might want to have a look at
91 | http://www.consol.com/opensource/nagios/. Contact roland.huss@consol.de for
92 | further information (or use the contact form at http://www.consol.com/contact/)
93 |
94 | =head1 AUTHOR
95 |
96 | roland@cpan.org
97 |
98 | =cut
99 |
100 | 1;
101 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Nagios/CactiJmx4Perl.pm:
--------------------------------------------------------------------------------
1 | package JMX::Jmx4Perl::Nagios::CactiJmx4Perl;
2 |
3 | use strict;
4 | use base qw(JMX::Jmx4Perl::Nagios::CheckJmx4Perl);
5 | use Data::Dumper;
6 |
7 | =head1 NAME
8 |
9 | JMX::Jmx4Perl::Nagios::CactiJmx4Perl - Module for encapsulating the functionality of
10 | L
11 |
12 | =head1 SYNOPSIS
13 |
14 | # One line in check_jmx4perl to rule them all
15 | JMX::Jmx4Perl::Nagios::CactiJmx4Perl->new(@ARGV)->execute();
16 |
17 | =head1 DESCRIPTION
18 |
19 | =cut
20 |
21 | sub create_nagios_plugin {
22 | my $self = shift;
23 |
24 | my $np = Monitoring::Plugin->
25 | new(
26 | usage =>
27 | "Usage: %s -u [-m ] [-a ]\n" .
28 | " [--alias ] [--value ] [--base ] [--delta ]\n" .
29 | " [--name ] [--product ]\n".
30 | " [--user ] [--password ] [--proxy ]\n" .
31 | " [--target ] [--target-user ] [--target-password ]\n" .
32 | " [--legacy-escape]\n" .
33 | " [--config ] [--check ] [--server ] [-v] [--help]\n" .
34 | " arg1 arg2 ....",
35 | version => $JMX::Jmx4Perl::VERSION,
36 | url => "http://www.jolokia.org",
37 | plugin => "cacti_jmx4perl",
38 | license => undef,
39 | blurb => "This script can be used as an script for a Cacti Data Input Method",
40 | extra => "\n\nYou need to deploy jolokia.war on the target application server or an intermediate proxy.\n" .
41 | "Please refer to the documentation for JMX::Jmx4Perl for further details.\n\n" .
42 | "For a complete documentation please consult the man page of cacti_jmx4perl or use the option --doc"
43 | );
44 | $np->shortname(undef);
45 | $self->add_common_np_args($np);
46 | # Add dummy thresholds to keep Nagios plugin happy
47 | $np->set_thresholds(warning => undef, critical => undef);
48 | $np->getopts();
49 | return $np;
50 | }
51 |
52 | sub verify_check {
53 | # Not needed
54 | }
55 |
56 | sub do_exit {
57 | my $self = shift;
58 | my $error_stat = shift;
59 | my $np = $self->{np};
60 |
61 | my $perf = $np->perfdata;
62 | my @res;
63 | for my $p (@$perf) {
64 | my $label = $p->label;
65 | $label =~ s/\s/_/g;
66 | push @res,@$perf > 1 ? $label . ":" . $p->value : $p->value;
67 | }
68 | print join(" ",@res),"\n";
69 | exit 0;
70 | }
71 |
72 |
73 | =head1 LICENSE
74 |
75 | This file is part of jmx4perl.
76 |
77 | Jmx4perl is free software: you can redistribute it and/or modify
78 | it under the terms of the GNU General Public License as published by
79 | the Free Software Foundation, either version 2 of the License, or
80 | (at your option) any later version.
81 |
82 | jmx4perl is distributed in the hope that it will be useful,
83 | but WITHOUT ANY WARRANTY; without even the implied warranty of
84 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85 | GNU General Public License for more details.
86 |
87 | You should have received a copy of the GNU General Public License
88 | along with jmx4perl. If not, see .
89 |
90 | =head1 AUTHOR
91 |
92 | roland@cpan.org
93 |
94 | =cut
95 |
96 | 1;
97 |
--------------------------------------------------------------------------------
/config/jboss.cfg:
--------------------------------------------------------------------------------
1 | # JBoss specific checks
2 | # ========================================================
3 |
4 | # JBoss uses tomcat internally
5 | include tomcat.cfg
6 |
7 | # =======================================================
8 | # Connection-Pools:
9 |
10 | # Available connections in a connection pool for a data source
11 | # Should be not 0
12 | # $0: Datasource name
13 |
14 | MBean = *:service=ManagedConnectionPool,name=$0
15 | Attribute = AvailableConnectionCount
16 | Name = $0 : Available connections
17 | Critical = $1
18 | Warning = $2
19 |
20 |
21 | # The reverse: Max. number of connections ever in use
22 | # $0: Datasource name
23 |
24 | MBean = *:service=ManagedConnectionPool,name=$0
25 | Attribute = MaxConnectionsInUseCount
26 | Name = $0 : Max. connections in use
27 | Critical = $1
28 | Warning = $2
29 |
30 |
31 | # Connections currently in use
32 | # $0: Datasource name
33 |
34 | MBean = *:service=ManagedConnectionPool,name=$0
35 | Attribute = InUseConnectionCount
36 | Name = $0 : Connections in use
37 | Critical = $1
38 | Warning = $2
39 |
40 |
41 | # Rate how often connections are created per minute
42 | # $0: Datasource name
43 |
44 | Use = count_per_minute("connections")
45 | MBean = *:service=ManagedConnectionPool,name=$0
46 | Attribute = ConnectionCreatedCount
47 | Name = $0 : Connection creation rate
48 | Critical = $1
49 | Warning = $2
50 |
51 |
52 | # =============================================================
53 | # Workmanager
54 |
55 | # Ratio of threads used in the JBoss WorkManager
56 |
57 | Use = relative_base
58 | Value = jboss.jca:service=WorkManagerThreadPool/Instance/poolSize
59 | Base = jboss.jca:service=WorkManagerThreadPool/Instance/maximumPoolSize
60 | Label = WorkManager Threads: $BASE
61 | Name = WorkManager Threads
62 |
63 |
64 |
65 | Use = relative_base
66 | Value = jboss.threads:name=WorkManagerThreadPool/CurrentThreadCount
67 | Base = jboss.threads:name=WorkManagerThreadPool/MaxThreads
68 |
69 | Label = WorkManager Threads: $BASE
70 | Name = WorkManager Threads
71 |
72 |
73 | # =============================================================
74 | # JMS
75 |
76 | # Rate how fast the number of messages in a JMS queue increases
77 | # $0: Queue name
78 | # $1: Critical (default: 1000)
79 | # $2: Warning (default: 800)
80 |
81 | Use = count_per_minute("messages")
82 | MBean = *:name=$0,service=Queue
83 | Attribute = MessageCount
84 | Name = JMS Queue $0 : Message count rate
85 |
86 |
87 | # Number of messages in a JMS queue
88 | # $0: Queue name
89 | # $1: Critical (default: 1000)
90 | # $2: Warning (default: 800)
91 |
92 | MBean = *:name=$0,service=Queue
93 | Attribute = MessageCount
94 | Name = JMS Queue $0 Count
95 | Critical = ${1:1000}
96 | Warning = ${2:800}
97 |
98 |
99 | # Number of messages in a JMS Topic
100 | # $0: Topic name
101 | # $1: Critical (default: 1000)
102 | # $2: Warning (default: 800)
103 |
104 | MBean = *:name=$0,service=Topic
105 | Attribute = AllMessageCount
106 | Name = JMS Topic $0 Count
107 | Critical = ${1:1000}
108 | Warning = ${2:800}
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/examples/threadDump.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use Getopt::Long;
4 | use JMX::Jmx4Perl;
5 | use Data::Dumper;
6 | use strict;
7 | use warnings;
8 |
9 | =head1 NAME
10 |
11 | threadDump.pl - Print a thread dump of an JEE Server
12 |
13 | =head1 SYNOPSIS
14 |
15 | threadDumpl.pl -f org.jmx4perl http://localhost:8080/j4p
16 |
17 | http-0.0.0.0-8080-1 (RUNNABLE):
18 | ....
19 | sun.management.ThreadImpl.dumpThreads0(ThreadImpl.java:unknown)
20 | org.jmx4perl.handler.ExecHandler.doHandleRequest(ExecHandler.java:77)
21 | org.jmx4perl.handler.RequestHandler.handleRequest(RequestHandler.java:89)
22 | org.jmx4perl.MBeanServerHandler.dispatchRequest(MBeanServerHandler.java:73)
23 | org.jmx4perl.AgentServlet.callRequestHandler(AgentServlet.java:205)
24 | org.jmx4perl.AgentServlet.handle(AgentServlet.java:152)
25 | org.jmx4perl.AgentServlet.doGet(AgentServlet.java:129)
26 | ....
27 |
28 | =head1 DESCRIPTION
29 |
30 | For JEE Server running with Java 6, this simple script prints out a thread
31 | dump, possibly filtered by package name. This is done by executing the MBean
32 | C's operation C.
33 |
34 | =cut
35 |
36 | my %opts = ();
37 | my $result = GetOptions(\%opts,
38 | "user|u=s","password|p=s",
39 | "proxy=s",
40 | "proxy-user=s","proxy-password=s",
41 | "filter|f=s",
42 | "verbose|v!",
43 | "help|h!" => sub { Getopt::Long::HelpMessage() }
44 | );
45 |
46 | my $url = $ARGV[0] || die "No URL to j4p agent given\n";
47 | my $jmx = new JMX::Jmx4Perl(url => $url,user => $opts{user},password => $opts{password},
48 | proxy => $opts{proxy}, proxy_user => $opts{"proxy-user"});
49 |
50 | my $dump;
51 | eval {
52 | $dump = $jmx->execute("java.lang:type=Threading","dumpAllThreads","false","false");
53 | };
54 | die "Cannot execute thread dump. Remember, $0 works only with Java >= 1.6\n$@\n" if $@;
55 |
56 | my @filters = split ",",$opts{filter} if $opts{filter};
57 | for my $thread (@$dump) {
58 | print "-" x 75,"\n" if print_thread($thread);;
59 | }
60 |
61 | sub print_thread {
62 | my $thread = shift;
63 | my $st = get_stacktrace($thread->{stackTrace});
64 | if ($st) {
65 | print $thread->{threadName}," (",$thread->{threadState},"):\n";
66 | print $st;
67 | return 1;
68 | } else {
69 | return undef;
70 | }
71 | }
72 |
73 | sub get_stacktrace {
74 | my $trace = shift;
75 | my $ret = "";
76 | my $found = 0;
77 | my $flag = 1;
78 | my $last_line;
79 | for my $l (@$trace) {
80 | my $class = $l->{className};
81 | if (!@filters || grep { $class =~ /^\Q$_\E/ } @filters) {
82 | $ret .= $last_line if ($last_line && !$found);
83 | $ret .= format_stack_line($l);
84 | $found = 1;
85 | $flag = 1;
86 | } elsif ($flag) {
87 | $flag = 0;
88 | $ret .= " ....\n";
89 | $last_line = format_stack_line($l);
90 | }
91 | }
92 | return $found ? $ret : undef;
93 | }
94 |
95 | sub format_stack_line {
96 | my $l = shift;
97 | my $ret = " ".$l->{className}.".".$l->{methodName}."(".$l->{fileName}.":";
98 | $ret .= $l->{lineNumber} > 0 ? $l->{lineNumber} : "unknown";
99 | $ret .= ")\n";
100 | return $ret;
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/scripts/cacti_jmx4perl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | # nagios: +epn
3 |
4 | use FindBin qw ($Bin);
5 |
6 | use JMX::Jmx4Perl::Nagios::CactiJmx4Perl;
7 |
8 | # Create modue and immediately execute it
9 | JMX::Jmx4Perl::Nagios::CactiJmx4Perl->new(@ARGV)->execute();
10 |
11 | =head1 NAME
12 |
13 | cacti_jmx4perl - Script for a Cacti Data Input Method
14 |
15 | =head1 SYNOPSIS
16 |
17 | # Print out used heap memory (absolute values)
18 | cacti_jmx4perl --url http://localhost:8888/jolokia \
19 | --name memory_used \
20 | --mbean java.lang:type=Memory \
21 | --attribute HeapMemoryUsage \
22 | --path used
23 |
24 | # Print out relative value
25 | cacti_jmx4perl --url http://localhost:8888/jolokia \
26 | --alias MEMORY_HEAP_USED \
27 | --base MEMORY_HEAP_MAX
28 |
29 | # Use predefined checks in a configuration file with a server alias Server
30 | # alias is 'webshop', output is the number of requests per minute for the servlet
31 | # 'socks_shop'
32 | cacti_jmx4perl --config /etc/nagios/check_jmx4perl/tomcat.cfg
33 | --server webshop \
34 | --check tc_servlet_requests \
35 | socks_shop
36 |
37 | # Number of threads started within a minute
38 | cacti_jmx4perl --url http://localhost:8888/jolokia \
39 | --alias THREAD_COUNT_STARTED \
40 | --delta 60
41 |
42 | # Proxy-mode usage
43 | cacti_jmx4perl --url http://localhost:8888/jolokia \
44 | --alias MEMORY_HEAP_USED \
45 | --critical 10000000 \
46 | --target service:jmx:rmi:///jndi/rmi://bhut:9999/jmxrmi
47 |
48 | =head1 DESCRIPTION
49 |
50 | This script is a simplified version of C which does not check
51 | for thresshold and prints out the measured data in a simplified format, which
52 | can be used by Cacti (L). For single checks, it simply returns
53 | the number measured, for multi checks, the numbers are returned with labels and
54 | space separated. See L for more about
55 | multichecks.
56 |
57 | Example:
58 |
59 | $ cacti_jmx4perl --url http://localhost:8080/jolokia --alias MEMORY_HEAP_USED
60 | 15308376
61 |
62 | $ cacti_jmx4perl -u http://localhost:8080/jolokia --config config/memory.cfg --check memory
63 | Heap:15341168 Non-Heap:19450312
64 |
65 | For the possible options and the configuration syntax, please refer to the
66 | documentation of L. Certain options are I available for this
67 | Cacti Script, since they make no sense here:
68 |
69 | =over
70 |
71 | =item --warning
72 |
73 | =item --critical
74 |
75 | =item --unit
76 |
77 | =item --null
78 |
79 | =item --string
80 |
81 | =item --numeric
82 |
83 | =item --label
84 |
85 | =back
86 |
87 | =head1 LICENSE
88 |
89 | This file is part of jmx4perl.
90 |
91 | Jmx4perl is free software: you can redistribute it and/or modify
92 | it under the terms of the GNU General Public License as published by
93 | the Free Software Foundation, either version 2 of the License, or
94 | (at your option) any later version.
95 |
96 | jmx4perl is distributed in the hope that it will be useful,
97 | but WITHOUT ANY WARRANTY; without even the implied warranty of
98 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
99 | GNU General Public License for more details.
100 |
101 | You should have received a copy of the GNU General Public License
102 | along with jmx4perl. If not, see .
103 |
104 | =head1 AUTHOR
105 |
106 | roland@cpan.org
107 |
108 | =cut
109 |
110 | 1;
111 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Agent/Jolokia/Verifier/OpenPGPVerifier.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | package JMX::Jmx4Perl::Agent::Jolokia::Verifier::OpenPGPVerifier;
4 |
5 | use JMX::Jmx4Perl::Agent::Jolokia::Verifier::PGPKey;
6 | use Crypt::OpenPGP::KeyRing;
7 | use Crypt::OpenPGP;
8 | use Module::Find;
9 | use Data::Dumper;
10 | use Cwd 'abs_path';
11 |
12 | use strict;
13 |
14 | =head1 NAME
15 |
16 | JMX::Jmx4Perl::Agent::Jolokia::Verifier::OpenPGPVerifier - Verifies PGP
17 | signature with L
18 |
19 | =head1 DESCRIPTION
20 |
21 | This verifier uses L for validating a PGP signature obtained
22 | from the download site. Ie. each URL used for download should have (and does
23 | have) and associated signature ending with F<.asc>. This verifier typically
24 | quite robust, however installing L is a bit clumsy, so you
25 | might omit this one.
26 |
27 | =head1 IMPORTANT
28 |
29 | It is not used currently since the new agents has been signed with 'digest
30 | algortihm 10' which is not supported by OpenPGP. Use a native GnuPG instead
31 | (i.e. a 'gpg' which is in the path)
32 |
33 | =cut
34 |
35 | sub new {
36 | my $class = shift;
37 | my $self = {};
38 | $self->{keyring} = $JMX::Jmx4Perl::Agent::Jolokia::Verifier::PGPKey::KEY;
39 | bless $self,(ref($class) || $class);
40 | }
41 |
42 | sub extension {
43 | return ".asc";
44 | }
45 |
46 | sub name {
47 | return "OpenPGP";
48 | }
49 |
50 | sub verify {
51 | my $self = shift;
52 | my %args = @_;
53 |
54 | my $kr = new Crypt::OpenPGP::KeyRing(Data => $self->{keyring});
55 | my $pgp = new Crypt::OpenPGP(PubRing => $kr);
56 | my $path = $args{path};
57 | my $log = $args{logger};
58 | my $validate;
59 | if ($path) {
60 | $validate = $pgp->verify(Files => [abs_path($args{path})],Signature => $args{signature});
61 | } else {
62 | $validate = $pgp->verify(Data => $args{data},Signature => $args{signature});
63 | }
64 | if ($validate) {
65 | my $key;
66 | if ($validate != 1) {
67 | my $kb = $kr->find_keyblock_by_uid($validate);
68 | if ($kb) {
69 | eval {
70 | # Non-document method
71 | $key = $kb->key->key_id_hex;
72 | $key = substr $key,8,8 if length($key) > 8;
73 | };
74 | }
75 | }
76 | $log->info("Good PGP signature",
77 | ($validate != 1 ? (", signed by ",$validate) : ""),
78 | ($key ? " ($key)" :""));
79 | return 1;
80 | } elsif ($validate == 0) {
81 | $log->error("Invalid signature",$path ? " for $path" : "",": " . $pgp->errstr);
82 | die "\n";
83 | } else {
84 | $log->error("Error occured while verifying signature: ",$pgp->errstr);
85 | die "\n";
86 | }
87 | }
88 |
89 | 1;
90 |
91 | =head1 LICENSE
92 |
93 | This file is part of jmx4perl.
94 | Jmx4perl is free software: you can redistribute it and/or modify
95 | it under the terms of the GNU General Public License as published by
96 | The Free Software Foundation, either version 2 of the License, or
97 | (at your option) any later version.
98 |
99 | jmx4perl is distributed in the hope that it will be useful,
100 | but WITHOUT ANY WARRANTY; without even the implied warranty of
101 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102 | GNU General Public License for more details.
103 |
104 | You should have received a copy of the GNU General Public License
105 | along with jmx4perl. If not, see .
106 |
107 | A commercial license is available as well. Please contact roland@cpan.org for
108 | further details.
109 |
110 | =head1 AUTHOR
111 |
112 | roland@cpan.org
113 |
114 | =cut
115 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/J4psh/Command/Global.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | package JMX::Jmx4Perl::J4psh::Command::Global;
4 | use strict;
5 | use Term::ANSIColor qw(:constants);
6 | use Term::Clui;
7 | use base qw(JMX::Jmx4Perl::J4psh::Command);
8 |
9 | =head1 NAME
10 |
11 | JMX::Jmx4Perl::J4psh::Command::Global - Globally available commands
12 |
13 | =head1 DESCRIPTION
14 |
15 | =head1 COMMANDS
16 |
17 | =over
18 |
19 | =cut
20 |
21 |
22 | sub name { "global" }
23 |
24 | sub global_commands {
25 | my $self = shift;
26 |
27 | return
28 | {
29 | "error" => {
30 | desc => "Show last error (if any)",
31 | proc => $self->cmd_last_error,
32 | doc => < {
38 | desc => "Print online help",
39 | args => sub { shift->help_args(undef, @_); },
40 | method => sub { shift->help_call(undef, @_); },
41 | doc => <]
43 | h []
44 |
45 | Print online help. Without option, show a summary. With
46 | option, show specific help for command .
47 | EOT
48 | },
49 | "h" => { alias => "help", exclude_from_completion=>1},
50 | "history" => {
51 | desc => "Command History",
52 | doc => <]
55 |
56 | Specify a number to list the last N lines of history
57 |
58 | Options:
59 | -c : Clear the command history
60 | -d : Delete a single item
61 | EOT
62 | args => "[-c] [-d] [number]",
63 | method => sub { shift->history_call(@_) },
64 | },
65 | "quit" => {
66 | desc => "Quit",
67 | maxargs => 0,
68 | method => sub { shift->exit_requested(1); },
69 | doc => < { alias => 'quit', exclude_from_completion => 1 },
74 | "exit" => { alias => 'quit', exclude_from_completion => 1 }
75 | };
76 | }
77 |
78 | sub cmd_last_error {
79 | my $self = shift;
80 | return sub {
81 | my $agent = $self->agent;
82 | my $txt = $self->context->last_error;
83 | if ($txt) {
84 | chomp $txt;
85 | print "$txt\n";
86 | } else {
87 | print "No errors\n";
88 | }
89 | }
90 | }
91 |
92 | =back
93 |
94 | =head1 LICENSE
95 |
96 | This file is part of jmx4perl.
97 |
98 | Jmx4perl is free software: you can redistribute it and/or modify
99 | it under the terms of the GNU General Public License as published by
100 | the Free Software Foundation, either version 2 of the License, or
101 | (at your option) any later version.
102 |
103 | jmx4perl is distributed in the hope that it will be useful,
104 | but WITHOUT ANY WARRANTY; without even the implied warranty of
105 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
106 | GNU General Public License for more details.
107 |
108 | You should have received a copy of the GNU General Public License
109 | along with jmx4perl. If not, see .
110 |
111 | A commercial license is available as well. Please contact roland@cpan.org for
112 | further details.
113 |
114 | =head1 PROFESSIONAL SERVICES
115 |
116 | Just in case you need professional support for this module (or Nagios or JMX in
117 | general), you might want to have a look at
118 | http://www.consol.com/opensource/nagios/. Contact roland.huss@consol.de for
119 | further information (or use the contact form at http://www.consol.com/contact/)
120 |
121 | =head1 AUTHOR
122 |
123 | roland@cpan.org
124 |
125 | =cut
126 |
127 | 1;
128 |
129 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/J4psh/Command/Server.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | package JMX::Jmx4Perl::J4psh::Command::Server;
4 | use strict;
5 | use Term::ANSIColor qw(:constants);
6 |
7 | use base qw(JMX::Jmx4Perl::J4psh::Command);
8 |
9 |
10 | =head1 NAME
11 |
12 | JMX::Jmx4Perl::J4psh::Command::Server - Server related commands
13 |
14 | =head1 DESCRIPTION
15 |
16 | =head1 COMMANDS
17 |
18 | =over
19 |
20 | =cut
21 |
22 |
23 | sub name { "server" }
24 |
25 | sub top_commands {
26 | my $self = shift;
27 | return {
28 | "servers" => {
29 | desc => "Show all configured servers",
30 | proc => $self->cmd_server_list,
31 | doc => < {
44 | desc => "Connect to a server by its URL or symbolic name",
45 | minargs => 1, maxargs => 2,
46 | args => $self->complete->servers,
47 | proc => $self->cmd_connect,
48 | doc => < []
51 |
52 | Connect to an agent. is the URL under which the agent
53 | is reachable. Alternatively a as stored in the configuration
54 | can be given. Is using the form an additional
55 | can be given which will be used as name in the server list.
56 | EOT
57 | }
58 | };
59 | }
60 |
61 | # Connect to a server
62 | sub cmd_connect {
63 | my $self = shift;
64 | return sub {
65 | my $arg = shift;
66 | my $name = shift;
67 | my $context = $self->context;
68 | $context->servers->connect_to_server($arg,$name);
69 | $context->commands->reset_stack;
70 | my ($yellow,$reset) = $context->color("host",RESET);
71 | print "Connected to " . $yellow . $context->server . $reset . " (" . $context->agent->url . ").\n" if $context->agent;
72 | }
73 | }
74 |
75 | # Show all servers
76 | sub cmd_server_list {
77 | my $self = shift;
78 | return sub {
79 | my $context = $self->context;
80 | my $server_list = $context->servers->list;
81 | for my $s (@$server_list) {
82 | my ($ms,$me) = $context->color("host",RESET);
83 | my $sep = $s->{from_config} ? "-" : "*";
84 | printf " " . $ms . '%30.30s' . $me . ' %s %s' . "\n",$s->{name},$sep,$s->{url};
85 | }
86 | }
87 | }
88 |
89 | =back
90 |
91 | =head1 LICENSE
92 |
93 | This file is part of jmx4perl.
94 |
95 | Jmx4perl is free software: you can redistribute it and/or modify
96 | it under the terms of the GNU General Public License as published by
97 | the Free Software Foundation, either version 2 of the License, or
98 | (at your option) any later version.
99 |
100 | jmx4perl is distributed in the hope that it will be useful,
101 | but WITHOUT ANY WARRANTY; without even the implied warranty of
102 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103 | GNU General Public License for more details.
104 |
105 | You should have received a copy of the GNU General Public License
106 | along with jmx4perl. If not, see .
107 |
108 | A commercial license is available as well. Please contact roland@cpan.org for
109 | further details.
110 |
111 | =head1 PROFESSIONAL SERVICES
112 |
113 | Just in case you need professional support for this module (or Nagios or JMX in
114 | general), you might want to have a look at
115 | http://www.consol.com/opensource/nagios/. Contact roland.huss@consol.de for
116 | further information (or use the contact form at http://www.consol.com/contact/)
117 |
118 | =head1 AUTHOR
119 |
120 | roland@cpan.org
121 |
122 | =cut
123 |
124 | 1;
125 |
126 |
--------------------------------------------------------------------------------
/it/t/80_read.t:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use It;
4 | use Test::More qw(no_plan);
5 | use JMX::Jmx4Perl;
6 | use JMX::Jmx4Perl::Request;
7 | use Data::Dumper;
8 | #use Test::More tests => $ENV{JMX4PERL_PRODUCT} ? 2 : 1;
9 |
10 |
11 | # Fetch all attributes
12 | my $jmx = new It(verbose => 0)->jmx4perl;
13 |
14 | my $req = new JMX::Jmx4Perl::Request(READ,"jolokia.it:type=attribute");
15 | my $resp = $jmx->request($req);
16 | my $value = $resp->{value};
17 | #print Dumper($resp);
18 | ok($value->{LongSeconds} == 60*60*24*2,"LongSeconds");
19 | ok($value->{Bytes} == 3 * 1024 * 1024 + 1024 * 512,"Bytes");
20 | ok(exists($value->{Null}) && !$value->{Null},"Null");
21 |
22 | # Fetch an array ref of attributes
23 | $jmx->execute("jolokia.it:type=attribute","reset");
24 | my $req = new JMX::Jmx4Perl::Request(READ,"jolokia.it:type=attribute",["LongSeconds","State"],{method => "post"});
25 | my $resp = $jmx->request($req);
26 | my $value = $resp->{value};
27 | #print Dumper($resp);
28 | is(scalar(keys(%$value)),2,"2 Return values");
29 | ok($value->{LongSeconds} == 60*60*24*2,"LongSeconds");
30 | ok($value->{State},"State");
31 | $jmx->execute("jolokia.it:type=attribute","reset");
32 |
33 | my $value = $jmx->get_attribute("jolokia.it:type=attribute",["LongSeconds","State"]);
34 | ok($value->{LongSeconds} == 60*60*24*2,"LongSeconds");
35 | ok($value->{State},"State");
36 | $jmx->execute("jolokia.it:type=attribute","reset");
37 |
38 | # Fetch a pattern with a single attribute
39 | my $value = $jmx->get_attribute("jolokia.it:*","LongSeconds");
40 | ok($value->{"jolokia.it:type=attribute"}->{LongSeconds} == 60*60*24*2,"LongSeconds");
41 | $jmx->execute("jolokia.it:type=attribute","reset");
42 |
43 | # Fetch a pattern with all attributes
44 | my $value = $jmx->get_attribute("jolokia.it:*",undef);
45 | ok($value->{"jolokia.it:type=attribute"}->{LongSeconds} == 60*60*24*2,"LongSeconds");
46 | $jmx->execute("jolokia.it:type=attribute","reset");
47 | is($value->{"jolokia.it:type=operation"},undef,"Operation missing");
48 | is($value->{"jolokia.it:type=attribute"}->{Bytes},3670016,"Bytes with pattern");
49 |
50 | # Fetch a pattern with multiple attributes
51 | my $value = $jmx->get_attribute("jolokia.it:*",["LongSeconds","State"]);
52 | ok($value->{"jolokia.it:type=attribute"}->{LongSeconds} == 60*60*24*2,"LongSeconds");
53 | ok($value->{"jolokia.it:type=attribute"}->{State},"State");
54 | $jmx->execute("jolokia.it:type=attribute","reset");
55 |
56 | my $value = $jmx->get_attribute("jolokia.it:type=attribute","ObjectName");
57 | ok($value->{objectName} eq "bla:type=blub","object name simplified");
58 | ok(!defined($value->{canonicalName}),"no superfluos parameters");
59 |
60 | my $value = $jmx->get_attribute("jolokia.it:type=attribute","Set");
61 | is(ref($value),"ARRAY","Set as array returned");
62 | ok(scalar(grep("jolokia",@$value)),"contains 'jolokia'");
63 | ok(scalar(grep("habanero",@$value)),"contains 'habanero'");
64 |
65 | my $value = $jmx->get_attribute("jolokia.it:type=attribute","Utf8Content");
66 | is($value,"☯","UTF-8 ☯ check passed");
67 |
68 | my $value = $jmx->get_attribute("jolokia.it:type=attribute","Chili");
69 | is($value,"AJI","Enum serialization passed");
70 |
71 | # Fetch all attributes
72 | $req = new JMX::Jmx4Perl::Request(READ,"jolokia.it.jsonmbean:type=plain");
73 | $resp = $jmx->request($req);
74 | $value = $resp->{value};
75 | #print Dumper($resp);
76 | is($resp->status,200);
77 |
78 | # Check Tabular data
79 | $value = $jmx->get_attribute("jolokia.it:type=tabularData","Table2","Value0.0/Value0.1");
80 | is($value->{Column1},"Value0.0","First column");
81 | is($value->{Column2},"Value0.1","Second column");
82 |
83 |
84 | $req = new JMX::Jmx4Perl::Request(READ,"jolokia.it:type=tabularData","Table2","Value0.1/Value0.0");
85 | $resp = $jmx->request($req);
86 | #print Dumper($resp);
87 | $value = $resp->{value};
88 | is($value,undef,"Path with no value");
89 |
90 | $value = $jmx->get_attribute("jolokia.it:type=mxbean","MapWithComplexKey");
91 | is(scalar(keys %$value),2,"2 elements");
92 | ok($value->{indexNames}->[0],"key");
93 | is(@{$value->{values}},2,"2 values");
94 | ok($value->{values}->[0]->{key}->{number} =~ /^(1|2)$/,"key match");
95 | #print Dumper($value);
96 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Product/Weblogic.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Product::Weblogic;
3 |
4 | use JMX::Jmx4Perl::Product::BaseHandler;
5 | use JMX::Jmx4Perl::Request;
6 | use Data::Dumper;
7 | use strict;
8 | use base "JMX::Jmx4Perl::Product::BaseHandler";
9 |
10 | use Carp qw(croak);
11 |
12 | =head1 NAME
13 |
14 | JMX::Jmx4Perl::Product::Weblogic - Handler for Oracle WebLogic
15 |
16 | =head1 DESCRIPTION
17 |
18 | This is the product handler support for Oracle Weblogic Server 9 and 10
19 | (L)
20 |
21 | =cut
22 |
23 | sub id {
24 | return "weblogic";
25 | }
26 |
27 | sub name {
28 | return "Oracle WebLogic Server";
29 | }
30 |
31 | sub order {
32 | return undef;
33 | }
34 |
35 | sub _try_version {
36 | my $self = shift;
37 | my $is_weblogic = $self->_try_server_domain;
38 | return undef unless $is_weblogic;
39 | return $self->try_attribute("version",$self->{server_domain},"ConfigurationVersion");
40 | }
41 |
42 | sub vendor {
43 | return "Oracle";
44 | }
45 |
46 | sub server_info {
47 | my $self = shift;
48 | my $ret = $self->SUPER::server_info();
49 | $ret .= sprintf("%-10.10s %s\n","IP:",$self->{jmx4perl}->get_attribute("SERVER_ADDRESS"));
50 | }
51 |
52 | sub _try_server_domain {
53 | my $self = shift;
54 | return $self->try_attribute
55 | ("server_domain",
56 | "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean",
57 | "DomainConfiguration",
58 | "objectName");
59 | }
60 |
61 | sub jsr77 {
62 | return 0;
63 | }
64 |
65 | sub autodetect_pattern {
66 | return ("version",1);
67 | }
68 |
69 | sub init_aliases {
70 | return
71 | {
72 | attributes => {
73 | SERVER_ADDRESS => [ sub {
74 | my $self = shift;
75 | $self->_try_server_domain;
76 | $self->try_attribute("admin_server",
77 | $self->{server_domain},
78 | "AdminServerName");
79 | return [ "com.bea:Name=" . $self->{admin_server} . ",Type=ServerRuntime",
80 | "AdminServerHost" ];
81 | }],
82 | },
83 | operations => {
84 | # Needs to be done in a more complex. Depends on admin server name *and*
85 | # JVM used
86 | THREAD_DUMP => \&exec_thread_dump
87 | }
88 | # Alias => [ "mbean", "attribute", "path" ]
89 | };
90 | }
91 |
92 | sub exec_thread_dump {
93 | my $self = shift;
94 | my $jmx = $self->{jmx4perl};
95 |
96 | my $beans = $jmx->search("com.bea:Type=JRockitRuntime,*");
97 | if ($beans && @{$beans}) {
98 | my $bean = $beans->[0];
99 | my $request = new JMX::Jmx4Perl::Request(READ,$bean,"ThreadStackDump");
100 | return $jmx->request($request);
101 | }
102 | die $self->name,": Cannot execute THREAD_DUMP because I can't find a suitable JRockitRuntime";
103 | }
104 |
105 | =head1 LICENSE
106 |
107 | This file is part of jmx4perl.
108 |
109 | Jmx4perl is free software: you can redistribute it and/or modify
110 | it under the terms of the GNU General Public License as published by
111 | the Free Software Foundation, either version 2 of the License, or
112 | (at your option) any later version.
113 |
114 | jmx4perl is distributed in the hope that it will be useful,
115 | but WITHOUT ANY WARRANTY; without even the implied warranty of
116 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
117 | GNU General Public License for more details.
118 |
119 | You should have received a copy of the GNU General Public License
120 | along with jmx4perl. If not, see .
121 |
122 | A commercial license is available as well. Please contact roland@cpan.org for
123 | further details.
124 |
125 | =head1 AUTHOR
126 |
127 | roland@cpan.org
128 |
129 | =cut
130 |
131 | 1;
132 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Util.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | =head1 NAME
4 |
5 | JMX::Jmx4Perl::Util - Utility methods for Jmx4Perl
6 |
7 | =head1 DESCRIPTION
8 |
9 | This class contains utility methods mostly for tools like C or
10 | C for things like formatting data output. All methods are 'static'
11 | methods which needs to be called like in
12 |
13 | JMX::Jmx4Perl::Util->dump_value(...);
14 |
15 | There is no constructor.
16 |
17 | =over
18 |
19 | =cut
20 |
21 | package JMX::Jmx4Perl::Util;
22 |
23 | use Data::Dumper;
24 | use JSON;
25 |
26 | =item $is_object = JMX::Jmx4Perl::Util->is_object_to_dump($val)
27 |
28 | For dumping out, checks whether C<$val> is an object (i.e. it is a ref but not a
29 | JSON::XS::Boolean) or not.
30 |
31 | =cut
32 |
33 | sub is_object_to_dump {
34 | my $self = shift;
35 | my $val = shift;
36 | return ref($val) && !JSON::is_bool($val);
37 | }
38 |
39 | =item $text = JMX::Jmx4Perl::Util->dump_value($value,{ format => "json", boolean_string =>1})
40 |
41 | Return a formatted text representation useful for tools printing out complex
42 | response values. Two modes are available: C which is the default and uses
43 | L for creating a textual description and C which return the
44 | result as JSON value. When C is used as format, booleans are returned as 0
45 | for false and 1 for true exception when the option C is given in
46 | which case it returns C or C.
47 |
48 | =cut
49 |
50 | sub dump_value {
51 | my $self = shift;
52 | my $value = shift;
53 | my $opts = shift || {};
54 | if ($opts && ref($opts) ne "HASH") {
55 | $opts = { $opts,@_ };
56 | }
57 | my $format = $opts->{format} || "data";
58 | my $ret;
59 | if ($format eq "json") {
60 | # Return a JSON representation of the data structure
61 | my $json = JSON->new->allow_nonref;
62 | $ret = $json->pretty->encode($value);
63 | } else {
64 | # Use data dumper, but resolve all JSON::XS::Booleans to either 0/1 or
65 | # true/false
66 | local $Data::Dumper::Terse = 1;
67 | local $Data::Dumper::Indent = 1;
68 | # local $Data::Dumper::Useqq = 1;
69 | local $Data::Dumper::Deparse = 0;
70 | local $Data::Dumper::Quotekeys = 0;
71 | local $Data::Dumper::Sortkeys = 1;
72 | $ret = Dumper($self->_canonicalize_value($value,$opts->{booleans}));
73 | }
74 | my $indent = $opts->{indent} ? " " x $opts->{indent} : " ";
75 | $ret =~ s/^/$indent/gm;
76 | return $ret;
77 | }
78 |
79 | =item $dump = JMX::Jmx4Perl::Util->dump_scalar($val,$format)
80 |
81 | Dumps a scalar value with special handling for booleans. If C<$val> is a
82 | L it is returned as string formatted according to
83 | C<$format>. C<$format> must contain two values separated bu C>. The first
84 | part is taken for a C value, the second for a C value. If no
85 | C<$format> is given, C<[true]/[false]> is used.
86 |
87 | =cut
88 |
89 | sub dump_scalar {
90 | my $self = shift;
91 | my $value = shift;
92 | my $format = shift || "[true]/[false]";
93 |
94 | if (JSON::is_bool($value)) {
95 | my ($true,$false) = split /\//,$format;
96 | if ($value eq JSON::true) {
97 | return $true;
98 | } else {
99 | return $false;
100 | }
101 | } else {
102 | return $value;
103 | }
104 | }
105 |
106 | # Replace all boolean values in
107 | sub _canonicalize_value {
108 | my $self = shift;
109 | my $value = shift;
110 | my $booleans = shift;
111 | if (ref($value) eq "HASH") {
112 | for my $k (keys %$value) {
113 | $value->{$k} = $self->_canonicalize_value($value->{$k},$booleans);
114 | }
115 | return $value;
116 | } elsif (ref($value) eq "ARRAY") {
117 | for my $i (0 .. $#$value) {
118 | $value->[$i] = $self->_canonicalize_value($value->[$i],$booleans);
119 | }
120 | return $value;
121 | } elsif (JSON::is_bool($value)) {
122 | $self->dump_scalar($value,$booleans);
123 | } else {
124 | return $value;
125 | }
126 | }
127 |
128 | =back
129 |
130 | =cut
131 |
132 | 1;
133 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/Platform/MacOS.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::Platform::MacOS;
2 |
3 | use strict;
4 | use vars qw($VERSION);
5 | $VERSION = '0.34';
6 | $VERSION = eval $VERSION;
7 | use Module::Build::Base;
8 | use vars qw(@ISA);
9 | @ISA = qw(Module::Build::Base);
10 |
11 | use ExtUtils::Install;
12 |
13 | sub have_forkpipe { 0 }
14 |
15 | sub new {
16 | my $class = shift;
17 | my $self = $class->SUPER::new(@_);
18 |
19 | # $Config{sitelib} and $Config{sitearch} are, unfortunately, missing.
20 | foreach ('sitelib', 'sitearch') {
21 | $self->config($_ => $self->config("install$_"))
22 | unless $self->config($_);
23 | }
24 |
25 | # For some reason $Config{startperl} is filled with a bunch of crap.
26 | (my $sp = $self->config('startperl')) =~ s/.*Exit \{Status\}\s//;
27 | $self->config(startperl => $sp);
28 |
29 | return $self;
30 | }
31 |
32 | sub make_executable {
33 | my $self = shift;
34 | require MacPerl;
35 | foreach (@_) {
36 | MacPerl::SetFileInfo('McPL', 'TEXT', $_);
37 | }
38 | }
39 |
40 | sub dispatch {
41 | my $self = shift;
42 |
43 | if( !@_ and !@ARGV ) {
44 | require MacPerl;
45 |
46 | # What comes first in the action list.
47 | my @action_list = qw(build test install);
48 | my %actions = map {+($_, 1)} $self->known_actions;
49 | delete @actions{@action_list};
50 | push @action_list, sort { $a cmp $b } keys %actions;
51 |
52 | my %toolserver = map {+$_ => 1} qw(test disttest diff testdb);
53 | foreach (@action_list) {
54 | $_ .= ' *' if $toolserver{$_};
55 | }
56 |
57 | my $cmd = MacPerl::Pick("What build command? ('*' requires ToolServer)", @action_list);
58 | return unless defined $cmd;
59 | $cmd =~ s/ \*$//;
60 | $ARGV[0] = ($cmd);
61 |
62 | my $args = MacPerl::Ask('Any extra arguments? (ie. verbose=1)', '');
63 | return unless defined $args;
64 | push @ARGV, $self->split_like_shell($args);
65 | }
66 |
67 | $self->SUPER::dispatch(@_);
68 | }
69 |
70 | sub ACTION_realclean {
71 | my $self = shift;
72 | chmod 0666, $self->{properties}{build_script};
73 | $self->SUPER::ACTION_realclean;
74 | }
75 |
76 | # ExtUtils::Install has a hard-coded '.' directory in versions less
77 | # than 1.30. We use a sneaky trick to turn that into ':'.
78 | #
79 | # Note that we do it here in a cross-platform way, so this code could
80 | # actually go in Module::Build::Base. But we put it here to be less
81 | # intrusive for other platforms.
82 |
83 | sub ACTION_install {
84 | my $self = shift;
85 |
86 | return $self->SUPER::ACTION_install(@_)
87 | if eval {ExtUtils::Install->VERSION('1.30'); 1};
88 |
89 | local $^W = 0; # Avoid a 'redefine' warning
90 | local *ExtUtils::Install::find = sub {
91 | my ($code, @dirs) = @_;
92 |
93 | @dirs = map { $_ eq '.' ? File::Spec->curdir : $_ } @dirs;
94 |
95 | return File::Find::find($code, @dirs);
96 | };
97 |
98 | return $self->SUPER::ACTION_install(@_);
99 | }
100 |
101 | 1;
102 | __END__
103 |
104 | =head1 NAME
105 |
106 | Module::Build::Platform::MacOS - Builder class for MacOS platforms
107 |
108 | =head1 DESCRIPTION
109 |
110 | The sole purpose of this module is to inherit from
111 | C and override a few methods. Please see
112 | L for the docs.
113 |
114 | =head2 Overridden Methods
115 |
116 | =over 4
117 |
118 | =item new()
119 |
120 | MacPerl doesn't define $Config{sitelib} or $Config{sitearch} for some
121 | reason, but $Config{installsitelib} and $Config{installsitearch} are
122 | there. So we copy the install variables to the other location
123 |
124 | =item make_executable()
125 |
126 | On MacOS we set the file type and creator to MacPerl so it will run
127 | with a double-click.
128 |
129 | =item dispatch()
130 |
131 | Because there's no easy way to say "./Build test" on MacOS, if
132 | dispatch is called with no arguments and no @ARGV a dialog box will
133 | pop up asking what action to take and any extra arguments.
134 |
135 | Default action is "test".
136 |
137 | =item ACTION_realclean()
138 |
139 | Need to unlock the Build program before deleting.
140 |
141 | =back
142 |
143 | =head1 AUTHOR
144 |
145 | Michael G Schwern
146 |
147 |
148 | =head1 SEE ALSO
149 |
150 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
151 |
152 | =cut
153 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Agent/Jolokia/Logger.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | package JMX::Jmx4Perl::Agent::Jolokia::Logger;
3 |
4 | use vars qw($HAS_COLOR);
5 | use strict;
6 |
7 | =head1 NAME
8 |
9 | JMX::Jmx4Perl::Agent::Jolokia::Logger - Simple logging abstraction for the
10 | Jolokia agent manager
11 |
12 | =head1 DESCRIPTION
13 |
14 | Simple Logger used throughout 'jolokia' and its associated modules for
15 | output. It knows about coloring and a quiet mode, where no output is generated
16 | at all.
17 |
18 | =cut
19 |
20 | BEGIN {
21 | $HAS_COLOR = eval "require Term::ANSIColor; Term::ANSIColor->import(qw(:constants)); 1";
22 | }
23 |
24 |
25 | =head1 METHODS
26 |
27 | =over 4
28 |
29 | =item $logger = JMX::Jmx4Perl::Agent::Jolokia::Logger->new(quiet=>1,color=>1)
30 |
31 | Creates a logger. Dependening on the options (C and C) output can
32 | be supressed completely or coloring can be used. Coloring only works, if the
33 | Module L is available (which is checked during runtime).
34 |
35 | =cut
36 |
37 | sub new {
38 | my $class = shift;
39 | my $self = ref($_[0]) eq "HASH" ? $_[0] : { @_ };
40 |
41 | my $quiet = delete $self->{quiet};
42 | $HAS_COLOR &&= $self->{color};
43 |
44 | # No-op logger
45 | return new JMX::Jmx4Perl::Agent::Jolokia::Logger::None
46 | if $quiet;
47 |
48 | bless $self,(ref($class) || $class);
49 | }
50 |
51 | =item $log->debug("....");
52 |
53 | Debug output
54 |
55 | =cut
56 |
57 | sub debug {
58 | my $self = shift;
59 | if ($self->{debug}) {
60 | print "+ ",join("",@_),"\n";
61 | }
62 | }
63 |
64 | =item $log->info("....","[em]","....","[/em]",...);
65 |
66 | Info output. The tag "C<[em]>" can be used to higlight a portion of the
67 | output. The tag must be provided in an extra element in the given list.
68 |
69 | =cut
70 |
71 |
72 | sub info {
73 | my $self = shift;
74 | my $text = $self->_resolve_color(@_);
75 | my ($cs,$ce) = $HAS_COLOR ? (DARK . CYAN,RESET) : ("","");
76 | print $cs . "*" . $ce . " " . $text . "\n";
77 | }
78 |
79 | =item $log->warn(...)
80 |
81 | Warning output (printed in yellow)
82 |
83 | =cut
84 |
85 |
86 | sub warn {
87 | my $self = shift;
88 | my $text = join "",@_;
89 | my ($cs,$ce) = $HAS_COLOR ? (YELLOW,RESET) : ("","");
90 | print $cs. "! " . $text . $ce ."\n";
91 | }
92 |
93 | =item $log->warn(...)
94 |
95 | Error output (printed in red)
96 |
97 | =cut
98 |
99 |
100 | sub error {
101 | my $self = shift;
102 | my $text = join "",@_;
103 | my ($cs,$ce) = $HAS_COLOR ? (RED,RESET) : ("","");
104 | print $cs . $text . $ce . "\n";
105 | }
106 |
107 | sub _resolve_color {
108 | my $self = shift;
109 | return join "",map {
110 | if (lc($_) eq "[em]") {
111 | $HAS_COLOR ? GREEN : ""
112 | } elsif (lc($_) eq "[/em]") {
113 | $HAS_COLOR ? RESET : ""
114 | } else {
115 | $_
116 | }} @_;
117 | }
118 |
119 | =back
120 |
121 | =head1 LICENSE
122 |
123 | This file is part of jmx4perl.
124 | Jmx4perl is free software: you can redistribute it and/or modify
125 | it under the terms of the GNU General Public License as published by
126 | The Free Software Foundation, either version 2 of the License, or
127 | (at your option) any later version.
128 |
129 | jmx4perl is distributed in the hope that it will be useful,
130 | but WITHOUT ANY WARRANTY; without even the implied warranty of
131 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
132 | GNU General Public License for more details.
133 |
134 | You should have received a copy of the GNU General Public License
135 | along with jmx4perl. If not, see .
136 |
137 | A commercial license is available as well. Please contact roland@cpan.org for
138 | further details.
139 |
140 | =head1 AUTHOR
141 |
142 | roland@cpan.org
143 |
144 | =cut
145 |
146 |
147 | package JMX::Jmx4Perl::Agent::Jolokia::Logger::None;
148 | use base qw(JMX::Jmx4Perl::Agent::Jolokia::Logger);
149 |
150 | =head1 NAME
151 |
152 | JMX::Jmx4Perl::Agent::Jolokia::Logger::None - No-op logger
153 |
154 | =head1 DESCRIPTION
155 |
156 | No-op logger used when quiet mode is switched on. Doesn't print
157 | out anything.
158 |
159 | =cut
160 |
161 | sub info { }
162 | sub warn { }
163 | sub error { }
164 | sub debug { }
165 |
166 |
167 | 1;
168 |
--------------------------------------------------------------------------------
/it/t/58_check_multi_config.t:
--------------------------------------------------------------------------------
1 | use FindBin;
2 | use strict;
3 | use warnings;
4 | use Test::More qw(no_plan);
5 | use Data::Dumper;
6 | use JMX::Jmx4Perl::Alias;
7 | use It;
8 |
9 | require "check_jmx4perl/base.pl";
10 |
11 | my $jmx = It->new(verbose =>1)->jmx4perl;
12 | my ($ret,$content);
13 |
14 | # ====================================================
15 | # Configuration check
16 | my $config_file = $FindBin::Bin . "/../check_jmx4perl/multi_check.cfg";
17 |
18 | # Simple multicheck
19 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check memory");
20 | #print ($ret,$content);
21 | is($ret,0,"Memory with value OK");
22 | ok($content =~ /\(base\)/,"First level inheritance");
23 | ok($content =~ /\(grandpa\)/,"Second level inheritance");
24 | ok($content =~ /Heap Memory/,"Heap Memory Included");
25 | ok($content =~ /NonHeap Memory/,"NonHeap Memory included");
26 | #print Dumper($ret,$content);
27 |
28 | # Nested multichecks
29 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check nested");
30 | #print Dumper($ret,$content);
31 | is($ret,0,"Multicheck with value OK");
32 | ok($content =~ /\(base\)/,"First level inheritance");
33 | ok($content =~ /\(grandpa\)/,"Second level inheritance");
34 | ok($content =~ /Thread-Count/,"Threads");
35 | ok($content =~ /'Thread-Count'/,"Threads");
36 | ok($content =~ /Heap Memory/,"Heap Memory Included");
37 | ok($content =~ /NonHeap Memory/,"Non Heap Memory included");
38 |
39 | # Multicheck with reference to checks with parameters
40 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check with_inner_args");
41 | is($ret,0,"Multicheck with value OK");
42 | ok($content =~ /HelloLabel/,"First param");
43 | ok($content =~ /WithInnerArgs/,"WithInnerArgs");
44 |
45 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check with_outer_args WithOuterArgs");
46 | is($ret,0,"Multicheck with value OK");
47 | ok($content =~ /HelloLabel/,"First param");
48 | ok($content =~ /WithOuterArgs/,"WithOuterArgs");
49 |
50 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check nested_with_args");
51 | is($ret,0,"Multicheck with value OK");
52 | ok($content =~ /HelloLabel/,"First param");
53 | ok($content =~ /NestedWithArgs/,"NestedWithArgs");
54 |
55 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check nested_with_outer_args NestedWithOuterArgs");
56 | is($ret,0,"Multicheck with value OK");
57 | ok($content =~ /HelloLabel/,"First param");
58 | ok($content =~ /NestedWithOuterArgs/,"NestedWithOuterArgs");
59 |
60 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check overloaded_multi_check");
61 | #print Dumper($ret,$content);
62 | is($ret,0,"Multicheck with argument for operation");
63 | ok($content =~ /Value 1 in range/,"OperationWithArgument");
64 |
65 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check failing_multi_check");
66 | #print Dumper($ret,$content);
67 | is($ret,2,"Failing memory multicheck is CRITICAL");
68 | ok($content =~ /memory_non_heap/,"Failed check name is contained in summary");
69 |
70 | # Check labeling of failed tests
71 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check label_test");
72 | #print "==========================================\n";
73 | #print Dumper($ret,$content);
74 | is($ret,2,"Should fail as critical");
75 | my @lines = split /\n/,$content;
76 | is($#lines,2,"3 lines has been returned");
77 | ok($lines[0] =~ /bla/ && $lines[0] =~ /blub/,"Name of checks should be returned as critical values");
78 | #print Dumper($ret,$content);
79 |
80 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check error_multi_check");
81 | is($ret,3,"Should fail as UNKNOWN");
82 | @lines = split /\n/,$content;
83 | is($#lines,3,"4 lines has been returned");
84 | ok($lines[1] =~ /kaputt/ && $lines[1] =~ /UNKNOWN/,"First line is UNKNOWN Check");
85 | #print Dumper($ret,$content);
86 |
87 | ($ret,$content) = exec_check_perl4jmx("--unknown-is-critical --config $config_file --check error_multi_check");
88 | is($ret,2,"Should fail as CRITICAL");
89 | @lines = split /\n/,$content;
90 | is($#lines,3,"4 lines has been returned");
91 | ok($lines[0] =~ /kaputt/ && $lines[0] =~ /CRITICAL/,"First line is UNKNOWN Check");
92 |
93 | #print Dumper($ret,$content);
94 |
95 |
96 | # TODO:
97 |
98 | # Unknown multicheck name
99 |
100 | # Unknown nested multicheck name
101 |
102 | # Unknown check name within a multi check
103 |
104 | # No multicheck name
105 |
--------------------------------------------------------------------------------
/config/websphere/http.cfg:
--------------------------------------------------------------------------------
1 | # ============================================
2 | # HTTP Checks
3 |
4 | include threads.cfg
5 |
6 | # HTTP Thread Pool Utilization
7 | # Check of relative pool size, i.e. the ratio between actual created threads
8 | # to the number of maximal available threads.
9 |
10 | Use was_thread_pool_size('WebContainer',$0,$1)
11 |
12 |
13 | # Relative check of all active threads out of the threadpool for the web container
14 |
15 | Use was_thread_pool_active('WebContainer',$0,$1)
16 |
17 |
18 | # Web-Sessions
19 |
20 | # Check for the number of session uses. The maximal number of sessions is not available
21 | # and should be provided as argument to this check (default is 200).
22 | #
23 | # A unique part of the name contained in the 'mbeanIdentifier' key of the MBean
24 | # must be used for the name (e.g. 'jolokia' for the Jolokia agent).
25 | #
26 | # $0: Unique part of the name of the web app (see above)
27 | # $1: Maximum number of session (default: 200)
28 | # $2: Critical (default: 90%)
29 | # $3: Warning (default: 80%)
30 |
31 | MBean WebSphere:type=SessionManager,mbeanIdentifier=*${0}*,*
32 | Attribute stats
33 | Path */*/statistics/LiveCount/current
34 |
35 | # Base value as the number of maximal possible sessions
36 | # (or if a proper MBean attribute is found, this could be inserted here)
37 | Base ${1:200}
38 |
39 | Critical ${2:90}
40 | Warning ${3:80}
41 |
42 | Label $0 : %.2r% sessions in use (%v / %b)
43 | Name ${0}-http-sessions
44 |
45 |
46 | # HTTP Request Count
47 | # Check for the number of requests per minute for a specific servlet.
48 | #
49 | # $0: Part of the servlet name (see above)
50 | # $1: Critical as requests / minute (no default)
51 | # $2: Warning as requests / minute (no default)
52 |
53 | Use was_request_count($0,$1,$2)
54 | MBean WebSphere:type=Servlet,mbeanIdentifier=*${0}*,*
55 |
56 |
57 | # Check for the number of requests per minute for a specific JSP
58 | #
59 | # $0: Part of the JSP name (see above)
60 | # $1: Critical as requests / minute (1000)
61 | # $2: Warning as requests / minute (800)
62 |
63 | Use was_request_count($0,$1,$2)
64 | MBean WebSphere:type=JSP,mbeanIdentifier=*${0}*,*
65 |
66 |
67 | # Base Check for requests counts (servlet or JSPs)
68 | # $0: Part of the servlet name (see above)
69 | # $1: Critical as requests / minute (1000)
70 | # $2: Warning as requests / minute (800)
71 |
72 | Attribute stats
73 | Path */*/statistics/RequestCount/count
74 | Delta 60
75 |
76 | Critical ${1:1000}
77 | Warning ${2:800}
78 |
79 | Label $0 : %2.2q requests / minute
80 | Name ${0}-request-count
81 |
82 |
83 | # HTTP Service Time
84 | #
85 | # Check of average processing time per request for a servlet.
86 | #
87 | # $0: Part of the servlet name (see above)
88 | # $1: Critical (default: 10000ms)
89 | # $2: Warning (default: 5000ms)
90 |
91 | Use was_service_time($0,$1,$2)
92 | MBean WebSphere:type=Servlet,mbeanIdentifier=*${0}*,*
93 | BaseMBean WebSphere:type=Servlet,mbeanIdentifier=*${0}*,*
94 |
95 |
96 | # Check of average processing time per request for a JSP
97 | #
98 | # $0: Part of JSP name (see above)
99 | # $1: Critical (default: 10000ms)
100 | # $2: Warning (default: 5000ms)
101 |
102 | Use was_service_time($0,$1,$2)
103 | MBean WebSphere:type=JSP,mbeanIdentifier=*${0}*,*
104 | BaseMBean WebSphere:type=JSP,mbeanIdentifier=*${0}*,*
105 |
106 |
107 | # Base check for total service time checks (suggestion for
108 | # improvements: Currently the overall average is measured. It would be
109 | # much better to use only the average till the last
110 | # measurement. Therefore a "Delta" should be used (without
111 | # normalization), but unfortunately the base value is not used as 'delta'
112 | # yet.
113 |
114 | Attribute stats
115 | Path */*/statistics/ServiceTime/totalTime
116 |
117 | BaseAttribute stats
118 | BasePath */*/statistics/ServiceTime/count
119 |
120 | Delta
121 |
122 | # * 100 because the value is a 'relative' check typical used for percentages
123 | Critical{1:1000000}
124 | Warning ${2:500000}
125 |
126 | Label %2.2q ms ∅ processing time per request (%v ms total for %b requests)
127 | Name $0-request-processing-time
128 |
129 |
130 |
--------------------------------------------------------------------------------
/scripts/j4psh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | =head1 NAME
4 |
5 | j4psh - A JMX Shell
6 |
7 | =cut
8 |
9 | use Getopt::Long
10 | ;
11 | use strict;
12 | use JMX::Jmx4Perl::Config;
13 | use JMX::Jmx4Perl::J4psh;
14 | use Config::General;
15 |
16 | =head1 SYNOPSIS
17 |
18 | j4psh [options]
19 |
20 | j4psh --help
21 |
22 | j4psh --version
23 |
24 | Options:
25 | --user Credential used for authentication
26 | --password
27 | --proxy URL to use as proxy proxy
28 | --proxy-user Authentication information for a proxy
29 | --proxy-password
30 | --target JSR-160 JMX Service URL to be used as the target server
31 | --target-user Credential for the target server if --target is given
32 | --target-password
33 | --option key=val Options for tuning the output of jmx4perl. Known keys are
34 | format : Either 'json' or 'data'
35 | booleans : Pair of strings separated by slash to use for printing
36 | boolean values (Default: [true]/[false])
37 | indent : Space indent when printing complex data structures
38 | --config Path to an optional configuration file (default: ~/.j4p). Can be a directory
39 | in which case /jmx4perl.cfg is used.
40 | --color [yes|no] Color option (default: yes)
41 |
42 | An optional argument can be used to directly connect to an agent URL or
43 | symbolic name as defined in the configuration file. If not given, the shell
44 | does no initial connect.
45 |
46 | =head1 DESCRIPTION
47 |
48 | B is a frontend to C providing an interactive shell for
49 | accessing JMX MBeans on a remote Java server.
50 |
51 | =over 4
52 |
53 | =item *
54 |
55 | Readline and history support based on GNU Readline/History as known from other
56 | shells like 'bash'. When GNU Readline is not available, a pure Perl Module is
57 | used instead.
58 |
59 | =item *
60 |
61 | Context sensitive argument completion, e.g. on MBean names and attributes.
62 |
63 | =item *
64 |
65 | Colored output (can be switched off)
66 |
67 | =item *
68 |
69 | Multi-Server support
70 |
71 | =item *
72 |
73 | Remote operation via HTTP(S)
74 |
75 | =back
76 |
77 | =cut
78 |
79 | my %opts = ();
80 | my $result = GetOptions(\%opts,
81 | "user|u=s","password|p=s",
82 | "proxy=s",
83 | "proxy-user=s","proxy-password=s",
84 | "config=s",
85 | "version!",
86 | "color=s",
87 | "option|opts|o=s%",
88 | "target|t=s","target-user=s","target-password=s",
89 | "help|h!" => sub { &Getopt::Long::HelpMessage() }
90 | );
91 |
92 | my $server = shift;
93 |
94 | if ($opts{version}) {
95 | print "j4psh ",$JMX::Jmx4Perl::VERSION,"\n";
96 | exit(0);
97 | }
98 |
99 | # Parse configuration files
100 | my $j4p_config = new JMX::Jmx4Perl::Config($opts{config});
101 |
102 | # Create global context object
103 | my $j4psh = new JMX::Jmx4Perl::J4psh(initial_server => $server,config => $j4p_config,args => \%opts);
104 |
105 | # Let the shell run
106 | $j4psh->run;
107 |
108 | =head1 LICENSE
109 |
110 | This file is part of jmx4perl.
111 |
112 | Jmx4perl is free software: you can redistribute it and/or modify
113 | it under the terms of the GNU General Public License as published by
114 | the Free Software Foundation, either version 2 of the License, or
115 | (at your option) any later version.
116 |
117 | jmx4perl is distributed in the hope that it will be useful,
118 | but WITHOUT ANY WARRANTY; without even the implied warranty of
119 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120 | GNU General Public License for more details.
121 |
122 | You should have received a copy of the GNU General Public License
123 | along with jmx4perl. If not, see .
124 |
125 | A commercial license is available as well. Please contact roland@cpan.org for
126 | further details.
127 |
128 | =head1 PROFESSIONAL SERVICES
129 |
130 | Just in case you need professional support for this module (or Nagios or JMX in
131 | general), you might want to have a look at
132 | http://www.consol.com/open-source-monitoring/consulting/. Contact roland.huss@consol.de for
133 | further information (or use the contact form at http://www.consol.com/contact/)
134 |
135 | =head1 AUTHOR
136 |
137 | roland@cpan.org
138 |
139 | =cut
140 |
141 | 1;
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/it/t/57_check_config.t:
--------------------------------------------------------------------------------
1 | use FindBin;
2 | use strict;
3 | use warnings;
4 | use Test::More qw(no_plan);
5 | use Data::Dumper;
6 | use JMX::Jmx4Perl::Alias;
7 | use It;
8 |
9 | require "check_jmx4perl/base.pl";
10 |
11 | my $jmx = It->new(verbose =>1)->jmx4perl;
12 | my ($ret,$content);
13 |
14 | # ====================================================
15 | # Configuration check
16 | my $config_file = $FindBin::Bin . "/../check_jmx4perl/checks.cfg";
17 |
18 | for my $check (qw(memory_heap memory_heap2)) {
19 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check $check");
20 | is($ret,0,"$check: Memory with value OK");
21 | ok($content =~ /\(base\)/,"$check: First level inheritance");
22 | ok($content =~ /\(grandpa\)/,"$check: Second level inheritance");
23 | ok($content !~ /\$\{1:default_name\}/,"$check: Default replacement");
24 | ok($content =~ /default_name/,"$check: Default replacement");
25 | }
26 |
27 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check blubber");
28 | is($ret,3,"Unknown check");
29 | ok($content =~ /blubber/,"Unknown check name contained");
30 |
31 | # ========================================================================
32 | # With arguments
33 |
34 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check outer_arg OuterArg");
35 | #print Dumper($ret,$content);
36 | is($ret,0,"OuterArg OK");
37 | ok($content =~ /OuterArg/,"OuterArg replaced");
38 | ok($content =~ /Warning: 80/,"Warning included in label");
39 | ok($content =~ /Critical: 90/,"Critical included in label");
40 |
41 | # No replacement
42 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check outer_arg");
43 | is($ret,0,"OuterArg OK");
44 | ok($content =~ /default_name/,"OuterArg not-replaced");
45 |
46 | # ===========================================================================
47 | # No default value
48 |
49 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check def_placeholder_1");
50 | is($ret,1,"WARNING");
51 | ok($content =~ /warning/i,"Warning expected");
52 |
53 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check def_placeholder_1 1");
54 | is($ret,1,"WARNING");
55 | ok($content =~ /warning/i,"Warning expected");
56 |
57 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check def_placeholder_2");
58 | is($ret,1,"WARNING");
59 | ok($content =~ /warning/i,"Warning expected");
60 |
61 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check def_placeholder_2 1");
62 | is($ret,2,"CRITICAL");
63 | ok($content =~ /critical/i,"Critical expected");
64 |
65 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check def_placeholder_2 1 2 Blubber");
66 | is($ret,2,"CRITICAL");
67 | ok($content =~ /critical/i,"Critical expected");
68 | ok($content =~ /Blubber/,"Name replacement from command line");
69 |
70 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check invalid_method 10 20");
71 | is($ret,3,"UNKNOWN");
72 | ok($content =~ /Unknown.*method/,"Unknown request method");
73 |
74 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --method invalid --check thread_count 10 20");
75 | is($ret,3,"UNKNOWN");
76 | ok($content =~ /Unknown.*method/,"Unknown request method");
77 |
78 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --method get --check thread_count 300 400");
79 | #print Dumper($ret,$content);
80 | is($ret,0,"OK");
81 | ok($content =~ /in range/,"In range");
82 |
83 | # =============================================================================
84 | # With scripting
85 |
86 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check script_check Eden|Java");
87 | #print Dumper($ret,$content);
88 | is($ret,2);
89 | ok($content =~ /threshold/i,"Script-Check: Threshold contained");
90 |
91 |
92 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check script_multi_check Perm|non-heap");
93 | ok($ret != 3);
94 | #print Dumper($ret,$content);
95 | ok($content =~ /Perm/,"Multi-Script-Check: Perm contained");
96 | ok($content =~ /Eden/,"Multi-Script-Check: Eden contained");
97 | ok($content =~ /thread_count/,"Multi-Script-Check: Thread_count contained");
98 |
99 | # ===========================================================================
100 | # Double values
101 |
102 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check double_min");
103 | $content =~ /double_min=(.*?);/;
104 | my $min = $1;
105 | #print Dumper($min,$ret ,$content,$1);
106 | is($min,"0.000000","Small double numbers are converted to floats");
107 |
108 | # ===========================================================================
109 | # Without Thresholds
110 |
111 | ($ret,$content) = exec_check_perl4jmx("--config $config_file --check without_threshold");
112 |
113 | #print Dumper($content);
114 |
--------------------------------------------------------------------------------
/inc/Module-Build/Module/Build/YAML.pm:
--------------------------------------------------------------------------------
1 | package Module::Build::YAML;
2 |
3 | use strict;
4 | use vars qw($VERSION @EXPORT @EXPORT_OK);
5 | $VERSION = "0.50";
6 | @EXPORT = ();
7 | @EXPORT_OK = qw(Dump Load DumpFile LoadFile);
8 |
9 | sub new {
10 | my $this = shift;
11 | my $class = ref($this) || $this;
12 | my $self = {};
13 | bless $self, $class;
14 | return($self);
15 | }
16 |
17 | sub Dump {
18 | shift if ($_[0] eq __PACKAGE__ || ref($_[0]) eq __PACKAGE__);
19 | my $yaml = "";
20 | foreach my $item (@_) {
21 | $yaml .= "---\n";
22 | $yaml .= &_yaml_chunk("", $item);
23 | }
24 | return $yaml;
25 | }
26 |
27 | sub Load {
28 | shift if ($_[0] eq __PACKAGE__ || ref($_[0]) eq __PACKAGE__);
29 | die "not yet implemented";
30 | }
31 |
32 | # This is basically copied out of YAML.pm and simplified a little.
33 | sub DumpFile {
34 | shift if ($_[0] eq __PACKAGE__ || ref($_[0]) eq __PACKAGE__);
35 | my $filename = shift;
36 | local $/ = "\n"; # reset special to "sane"
37 | my $mode = '>';
38 | if ($filename =~ /^\s*(>{1,2})\s*(.*)$/) {
39 | ($mode, $filename) = ($1, $2);
40 | }
41 | open my $OUT, "$mode $filename"
42 | or die "Can't open $filename for writing: $!";
43 | binmode($OUT, ':utf8') if $] >= 5.008;
44 | print $OUT Dump(@_);
45 | close $OUT;
46 | }
47 |
48 | # This is basically copied out of YAML.pm and simplified a little.
49 | sub LoadFile {
50 | shift if ($_[0] eq __PACKAGE__ || ref($_[0]) eq __PACKAGE__);
51 | my $filename = shift;
52 | open my $IN, $filename
53 | or die "Can't open $filename for reading: $!";
54 | binmode($IN, ':utf8') if $] >= 5.008;
55 | return Load(do { local $/; <$IN> });
56 | close $IN;
57 | }
58 |
59 | sub _yaml_chunk {
60 | my ($indent, $values) = @_;
61 | my $yaml_chunk = "";
62 | my $ref = ref($values);
63 | my ($value, @allkeys, %keyseen);
64 | if (!$ref) { # a scalar
65 | $yaml_chunk .= &_yaml_value($values) . "\n";
66 | }
67 | elsif ($ref eq "ARRAY") {
68 | foreach $value (@$values) {
69 | $yaml_chunk .= "$indent-";
70 | $ref = ref($value);
71 | if (!$ref) {
72 | $yaml_chunk .= " " . &_yaml_value($value) . "\n";
73 | }
74 | else {
75 | $yaml_chunk .= "\n";
76 | $yaml_chunk .= &_yaml_chunk("$indent ", $value);
77 | }
78 | }
79 | }
80 | else { # assume "HASH"
81 | if ($values->{_order} && ref($values->{_order}) eq "ARRAY") {
82 | @allkeys = @{$values->{_order}};
83 | $values = { %$values };
84 | delete $values->{_order};
85 | }
86 | push(@allkeys, sort keys %$values);
87 | foreach my $key (@allkeys) {
88 | next if (!defined $key || $key eq "" || $keyseen{$key});
89 | $keyseen{$key} = 1;
90 | $yaml_chunk .= "$indent$key:";
91 | $value = $values->{$key};
92 | $ref = ref($value);
93 | if (!$ref) {
94 | $yaml_chunk .= " " . &_yaml_value($value) . "\n";
95 | }
96 | else {
97 | $yaml_chunk .= "\n";
98 | $yaml_chunk .= &_yaml_chunk("$indent ", $value);
99 | }
100 | }
101 | }
102 | return($yaml_chunk);
103 | }
104 |
105 | sub _yaml_value {
106 | my ($value) = @_;
107 | # undefs become ~
108 | return '~' if not defined $value;
109 |
110 | # empty strings will become empty strings
111 | return '""' if $value eq '';
112 |
113 | # allow simple scalars (without embedded quote chars) to be unquoted
114 | # (includes $%_+=-\;:,./)
115 | return $value if $value !~ /["'`~\n!\@\#^\&\*\(\)\{\}\[\]\|<>\?]/;
116 |
117 | # quote and escape strings with special values
118 | return "'$value'"
119 | if $value !~ /['`~\n!\#^\&\*\(\)\{\}\[\]\|\?]/; # nothing but " or @ or < or > (email addresses)
120 |
121 | $value =~ s/\n/\\n/g; # handle embedded newlines
122 | $value =~ s/"/\\"/g; # handle embedded quotes
123 | return qq{"$value"};
124 | }
125 |
126 | 1;
127 |
128 | __END__
129 |
130 | =head1 NAME
131 |
132 | Module::Build::YAML - Provides just enough YAML support so that Module::Build works even if YAML.pm is not installed
133 |
134 | =head1 SYNOPSIS
135 |
136 | use Module::Build::YAML;
137 |
138 | ...
139 |
140 | =head1 DESCRIPTION
141 |
142 | Provides just enough YAML support so that Module::Build works even if YAML.pm is not installed.
143 |
144 | Currently, this amounts to the ability to write META.yml files when C
145 | is executed via the Dump() and DumpFile() functions/methods.
146 |
147 | =head1 AUTHOR
148 |
149 | Stephen Adkins
150 |
151 | =head1 COPYRIGHT
152 |
153 | Copyright (c) 2006. Stephen Adkins. All rights reserved.
154 |
155 | This program is free software; you can redistribute it and/or modify it
156 | under the same terms as Perl itself.
157 |
158 | See L
159 |
160 | =cut
161 |
162 |
--------------------------------------------------------------------------------
/lib/JMX/Jmx4Perl/Response.pm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | =head1 NAME
4 |
5 | JMX::Jmx4Perl::Response - A jmx4perl response
6 |
7 | =head1 SYNOPSIS
8 |
9 | my $jmx_response = $jmx_agent->request($jmx_request);
10 | my $value = $jmx_response->value();
11 |
12 | =head1 DESCRIPTION
13 |
14 | A L is the result of an JMX request and encapsulates
15 | the answer as returned by a L backend. Depending on the
16 | C it either contains the result of a valid request or a error message.
17 | The status is modelled after HTTP response codes (see
18 | L). For now, only the
19 | codes C<200> and C<400 .. 599> codes are used to specified successful request
20 | and errors respectively.
21 |
22 | =head1 METHODS
23 |
24 | =over
25 |
26 | =cut
27 |
28 | package JMX::Jmx4Perl::Response;
29 |
30 | use strict;
31 | use vars qw(@EXPORT);
32 |
33 | =item $response = JMX::Jmx4Perl::Response->new($status,$request,$value,$error,$stacktrace)
34 |
35 | Internal constructor for creating a response which is use withing requesting
36 | the backend. C<$error> and C<$stacktrace> are optional and should only provided
37 | when C<$status != 200>.
38 |
39 | =cut
40 |
41 | sub new {
42 | my $class = shift;
43 | my $self = { @_ };
44 | return bless $self,(ref($class) || $class);
45 | }
46 |
47 | =item $status = $response->status()
48 |
49 | Return the status code of this response. Status codes are modelled after HTTP
50 | return codes. C<200> is the code for a suceeded request. Any code in the range
51 | 500 - 599 specifies an error.
52 |
53 | =cut
54 |
55 | sub status {
56 | return shift->{status};
57 | }
58 |
59 | =item $timestamp = $response->timestamp()
60 |
61 | Get the timestamp (i.e. epoch seconds) when the request was executed on the
62 | serverside.
63 |
64 | =cut
65 |
66 | sub timestamp {
67 | return shift->{timestamp};
68 | }
69 |
70 | =item $history = $response->history()
71 |
72 | Get the history if history tracking is switched on. History tracking is
73 | switchen on by executing a certain JMX operation on the C
74 | MBean. See the alias C and L for details.
76 |
77 | The returned arrayref (if any) contains hashes with two values: C
78 | contains the historical value and C the timestamp when this value
79 | was recorded.
80 |
81 | =cut
82 |
83 | sub history {
84 | return shift->{history};
85 | }
86 |
87 | =item $ok = $response->is_ok()
88 |
89 | Return true if this object contains a valid response (i.e. the status code is
90 | equal 200)
91 |
92 | =cut
93 |
94 | sub is_ok {
95 | return shift->{status} == 200;
96 | }
97 |
98 | =item $fault = $response->is_error()
99 |
100 | Opposite of C, i.e. return true if the status code is B equal to
101 | 200
102 |
103 | =cut
104 |
105 | sub is_error {
106 | return shift->{status} != 200;;
107 | }
108 |
109 | =item $error = $response->error_text()
110 |
111 | Return the error text. Set only if C is C
112 |
113 | =cut
114 |
115 | sub error_text {
116 | return shift->{error};
117 | }
118 |
119 | =item $error = $response->stacktrace()
120 |
121 | Returns the stacktrace of an Java error if any. This is only set when
122 | C is C B and Java exception occured on the Java agent's
123 | side.
124 |
125 | =cut
126 |
127 | sub stacktrace { return shift->{stacktrace}; }
128 |
129 | =item $content = $response->value()
130 |
131 | Return the content of this response, which is a represents the JSON response as
132 | returned by the Java agent as a hash reference value. This is set only when C is
133 | true.
134 |
135 | =cut
136 |
137 | sub value {
138 | return shift->{value};
139 | }
140 |
141 | =item $request = $response->request()
142 |
143 | Return the L which lead to this response
144 |
145 | =cut
146 |
147 | sub request {
148 | return shift->{request};
149 | }
150 |
151 | =back
152 |
153 | =head1 LICENSE
154 |
155 | This file is part of jmx4perl.
156 |
157 | Jmx4perl is free software: you can redistribute it and/or modify
158 | it under the terms of the GNU General Public License as published by
159 | the Free Software Foundation, either version 2 of the License, or
160 | (at your option) any later version.
161 |
162 | jmx4perl is distributed in the hope that it will be useful,
163 | but WITHOUT ANY WARRANTY; without even the implied warranty of
164 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
165 | GNU General Public License for more details.
166 |
167 | You should have received a copy of the GNU General Public License
168 | along with jmx4perl. If not, see .
169 |
170 | A commercial license is available as well. Please contact roland@cpan.org for
171 | further details.
172 |
173 | =head1 AUTHOR
174 |
175 | roland@cpan.org
176 |
177 | =cut
178 |
179 |
180 | 1;
181 |
--------------------------------------------------------------------------------
/config/wildfly.cfg:
--------------------------------------------------------------------------------
1 | # Wildfly (JBoss AS 8) specific checks
2 | # ========================================================
3 |
4 | include "common.cfg"
5 |
6 | # Wildfly use Undertow instead of Tomcat as its servlet container,
7 | # webapp specific metrics changed completely.
8 |
9 | # Requests per minute for a servlet within a deployed war
10 | # $0: Web-Module name (i.e. the WAR file name)
11 | # $1: Servlet name
12 | # $2: Critical (optional)
13 | # $3: Warning (optional)
14 | # $4: Descriptive name (optional)
15 |
16 | MBean = jboss.as.expr:subsystem=undertow,deployment=$0,servlet=$1,*
17 | Use = count_per_minute("requests")
18 | Attribute = requestCount
19 | Name = ${4:request}
20 | Critical = ${2:6000}
21 | Warning = ${3:5000}
22 |
23 |
24 | # Average request processing time for a servlet within a deployed war
25 | # $0: Web-Module name (i.e. the WAR file name)
26 | # $1: Servlet name
27 | # $2: Critical (optional)
28 | # $3: Warning (optional)
29 | # $4: Descriptive name (optional)
30 |
31 | Value = jboss.as.expr:subsystem=undertow,deployment=$0,servlet=$1,*/totalRequestTime
32 | Base = jboss.as.expr:subsystem=undertow,deployment=$0,servlet=$1,*/requestCount
33 | Delta
34 | Label = $0 : $1 : %2.2f ms average request time
35 | Name = ${4:$0-$1-request-time}
36 | Critical = ${2:6000}
37 | Warning = ${3:5000}
38 |
39 |
40 | # Requests per minute for a servlet, deployed as part of an ear
41 | # $0: EAR Module (name of the EAR file)
42 | # $1: Web-Module name (i.e. the WAR file name within the EAR)
43 | # $2: Servlet name
44 | # $3: Critical (optional)
45 | # $4: Warning (optional)
46 | # $5: Descriptive name (optional)
47 |
48 | MBean = jboss.as.expr:subsystem=undertow,deployment=$0,subdeployment=$1,servlet=$2,*
49 | Use = count_per_minute("requests")
50 | Attribute = requestCount
51 | Name = ${5:request}
52 | Critical = ${3:6000}
53 | Warning = ${2:5000}
54 |
55 |
56 | # Average request processing time, deployed as part of an ear
57 | # $0: EAR Module name (i.e. the EAR file name)
58 | # $1: Web-Module name (i.e. the WAR file name)
59 | # $2: Servlet name
60 | # $3: Critical (optional)
61 | # $4: Warning (optional)
62 |
63 | Value = jboss.as.expr:subsystem=undertow,deployment=$0,subdeployment=$1,servlet=$2,*/totalRequestTime
64 | Base = jboss.as.expr:subsystem=undertow,deployment=$0,subdeployment=$1,servlet=$2,*/requestCount
65 | Delta
66 | Label = $0 : $1 : $2 : %2.2f ms average request time
67 | Name = $0-$1-$2-request
68 | Critical = ${3:6000}
69 | Warning = ${4:5000}
70 |
71 |
72 | # Check whether the webapplications deployment is in status OK
73 | # $0: Web-Module name (i.e. the WAR file name)
74 | # $1: Name (optional)
75 |
76 | Value = jboss.as.expr:deployment=$0/status
77 | String = 1
78 | Critical = !OK
79 | Label = $0 status
80 | Name = ${1:status}
81 |
82 |
83 | # Check whether a webapplication is enabled
84 | # $0: Web-Module name (i.e. the WAR file name)
85 | # $1: Name (optional)
86 |
87 | Value = jboss.as.expr:deployment=$0/enabled
88 | String = 1
89 | Critical = !true
90 | Label = $0 enabled
91 | Name = ${1:enabled}
92 |
93 |
94 | # Check number of active session for a webapp, deployed as a war
95 | # $0: Web-Module name (i.e. the WAR file name)
96 | # $1: Critical (optional) (absolute number of active sessions allowed)
97 | # $2: Warning (optional) (absolute number of active sessions allowed)
98 | # $3: Descriptive name (optional)
99 |
100 | Value = jboss.as.expr:subsystem=undertow,deployment=$0/activeSessions
101 | Label = %v active sessions
102 | Name = ${3:active sessions}
103 | Critical = ${1:1000}
104 | Warning = ${2:800}
105 |
106 |
107 | # Check number of active session for a webapp, deployed as part of an ear
108 | # $0: EAR Module (name of the EAR file)
109 | # $1: Web-Module name (i.e. the WAR file name within the ear)
110 | # $2: Critical (optional) (absolute number of active sessions allowed)
111 | # $3: Warning (optional) (absolute number of active sessions allowed)
112 | # $4: Descriptive name (optional)
113 |
114 | Value = jboss.as.expr:subsystem=undertow,deployment=$0,subdeployment=$1/activeSessions
115 | Label = %v active sessions
116 | Name = ${4:active sessions}
117 | Critical = ${2:1000}
118 | Warning = ${3:800}
119 |
120 |
121 | # Check for available database connections
122 | # $0: Name of datasource (e.g. "ExampleDS")
123 | # $1: Critical value (optional, default: 1)
124 | # $2: Warning value (optional, default: 5)
125 | # $3: Name (optional)
126 |
127 | Value = jboss.as.expr:data-source=${0},statistics=pool,subsystem=datasources/AvailableCount
128 | Name = ${3:dbpool_available}
129 | Label = %.2v DB connections available
130 | Critical = ${1:1:}
131 | Warning = ${2:5:}
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------