2020-05-11 13:54:40 +02:00
#
2021-02-08 09:55:50 +01:00
# Copyright 2021 Centreon (http://www.centreon.com/)
2020-05-11 13:54:40 +02:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::activemq::jmx::mode::brokers ;
use base qw( centreon::plugins::templates::counter ) ;
use strict ;
use warnings ;
use Digest::MD5 qw( md5_hex ) ;
sub set_counters {
my ( $ self , % options ) = @ _ ;
$ self - > { maps_counters_type } = [
{ name = > 'brokers' , type = > 3 , cb_prefix_output = > 'prefix_broker_output' , cb_long_output = > 'broker_long_output' , indent_long_output = > ' ' , message_multiple = > 'All brokers are ok' ,
group = > [
{ name = > 'global' , type = > 0 , skipped_code = > { - 10 = > 1 } } ,
2020-05-11 16:16:43 +02:00
{ name = > 'queue' , display_long = > 1 , cb_prefix_output = > 'prefix_queue_output' , message_multiple = > 'All queues are ok' , type = > 1 , skipped_code = > { - 10 = > 1 } } ,
{ name = > 'topic' , display_long = > 1 , cb_prefix_output = > 'prefix_topic_output' , message_multiple = > 'All topics are ok' , type = > 1 , skipped_code = > { - 10 = > 1 } }
2020-05-11 13:54:40 +02:00
]
}
] ;
$ self - > { maps_counters } - > { global } = [
{ label = > 'store-usage' , nlabel = > 'broker.store.usage.percentage' , set = > {
key_values = > [ { name = > 'StorePercentUsage' } , { name = > 'display' } ] ,
output_template = > 'store usage: %.2f %%' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%.2f' , unit = > '%' , min = > 0 , max = > 100 , label_extra_instance = > 1 }
2020-05-11 13:54:40 +02:00
]
}
} ,
{ label = > 'temporary-usage' , nlabel = > 'broker.temporary.usage.percentage' , set = > {
key_values = > [ { name = > 'TempPercentUsage' } , { name = > 'display' } ] ,
output_template = > 'temporary usage: %.2f %%' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%.2f' , unit = > '%' , min = > 0 , max = > 100 , label_extra_instance = > 1 }
2020-05-11 13:54:40 +02:00
]
}
} ,
{ label = > 'memory-usage' , nlabel = > 'broker.memory.usage.percentage' , set = > {
key_values = > [ { name = > 'MemoryPercentUsage' } , { name = > 'display' } ] ,
output_template = > 'memory usage: %.2f %%' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%.2f' , unit = > '%' , min = > 0 , max = > 100 , label_extra_instance = > 1 }
2020-05-11 13:54:40 +02:00
]
}
}
] ;
2020-05-11 16:16:43 +02:00
foreach ( ( 'queue' , 'topic' ) ) {
$ self - > { maps_counters } - > { $ _ } = [
{ label = > $ _ . '-average-enqueue-time' , nlabel = > 'broker.' . $ _ . '.average.enqueue.time.milliseconds' , set = > {
key_values = > [ { name = > 'AverageEnqueueTime' } , { name = > 'display' } ] ,
output_template = > 'average time messages remained enqueued: %.3f ms' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%.3f' , unit = > 'ms' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-consumers-connected' , nlabel = > 'broker.' . $ _ . '.consumers.connected.count' , set = > {
key_values = > [ { name = > 'ConsumerCount' } , { name = > 'display' } ] ,
output_template = > 'consumers connected: %s' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%s' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-producers-connected' , nlabel = > 'broker.' . $ _ . '.producers.connected.count' , display_ok = > 0 , set = > {
key_values = > [ { name = > 'ProducerCount' } , { name = > 'display' } ] ,
output_template = > 'producers connected: %s' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%s' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-memory-usage' , nlabel = > 'broker.' . $ _ . '.memory.usage.percentage' , display_ok = > 0 , set = > {
key_values = > [ { name = > 'MemoryPercentUsage' } , { name = > 'display' } ] ,
output_template = > 'memory usage: %.2f %%' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%.2f' , unit = > '%' , min = > 0 , max = > 100 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-size' , nlabel = > 'broker.' . $ _ . '.size.count' , set = > {
key_values = > [ { name = > 'QueueSize' } , { name = > 'display' } ] ,
output_template = > 'queue size: %s' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%s' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-messages-enqueued' , nlabel = > 'broker.' . $ _ . '.messages.enqueued.count' , display_ok = > 0 , set = > {
key_values = > [ { name = > 'EnqueueCount' , diff = > 1 } , { name = > 'display' } ] ,
output_template = > 'messages enqueued: %s' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%s' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-messages-dequeued' , nlabel = > 'broker.' . $ _ . '.messages.dequeue.count' , display_ok = > 0 , set = > {
key_values = > [ { name = > 'DequeueCount' , diff = > 1 } , { name = > 'display' } ] ,
output_template = > 'messages dequeued: %s' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%s' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-messages-expired' , nlabel = > 'broker.' . $ _ . '.messages.expired.count' , display_ok = > 0 , set = > {
key_values = > [ { name = > 'ExpiredCount' , diff = > 1 } , { name = > 'display' } ] ,
output_template = > 'messages expired: %s' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%s' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-messages-inflighted' , nlabel = > 'broker.' . $ _ . '.messages.inflighted.count' , display_ok = > 0 , set = > {
key_values = > [ { name = > 'InFlightCount' , diff = > 1 } , { name = > 'display' } ] ,
output_template = > 'messages in-flighted: %s' ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%s' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
} ,
{ label = > $ _ . '-messages-size-average' , nlabel = > 'broker.' . $ _ . '.messages.size.average.bytes' , display_ok = > 0 , set = > {
key_values = > [ { name = > 'AverageMessageSize' } , { name = > 'display' } ] ,
output_template = > 'average messages size: %s %s' ,
output_change_bytes = > 1 ,
perfdatas = > [
2020-06-15 15:49:47 +02:00
{ template = > '%s' , unit = > 'B' , min = > 0 , label_extra_instance = > 1 }
2020-05-11 16:16:43 +02:00
]
}
2020-05-11 13:54:40 +02:00
}
2020-05-11 16:16:43 +02:00
] ;
}
2020-05-11 13:54:40 +02:00
}
sub broker_long_output {
my ( $ self , % options ) = @ _ ;
return "checking broker '" . $ options { instance_value } - > { display } . "'" ;
}
sub prefix_broker_output {
my ( $ self , % options ) = @ _ ;
return "Broker '" . $ options { instance_value } - > { display } . "' " ;
}
2020-05-11 16:16:43 +02:00
sub prefix_queue_output {
my ( $ self , % options ) = @ _ ;
return "queue '" . $ options { instance_value } - > { display } . "' " ;
}
sub prefix_topic_output {
2020-05-11 13:54:40 +02:00
my ( $ self , % options ) = @ _ ;
2020-05-11 16:16:43 +02:00
return "topic '" . $ options { instance_value } - > { display } . "' " ;
2020-05-11 13:54:40 +02:00
}
sub new {
my ( $ class , % options ) = @ _ ;
my $ self = $ class - > SUPER:: new ( package = > __PACKAGE__ , % options , statefile = > 1 , force_new_perfdata = > 1 ) ;
bless $ self , $ class ;
$ options { options } - > add_options ( arguments = > {
'filter-broker-name:s' = > { name = > 'filter_broker_name' } ,
2020-05-11 16:16:43 +02:00
'filter-destination-name:s' = > { name = > 'filter_destination_name' } ,
'filter-destination-type:s' = > { name = > 'filter_destination_type' }
2020-05-11 13:54:40 +02:00
} ) ;
return $ self ;
}
sub manage_selection {
my ( $ self , % options ) = @ _ ;
my $ request = [
{
2020-05-11 16:16:43 +02:00
mbean = > 'org.apache.activemq:brokerName=*,destinationName=*,destinationType=*,type=Broker' ,
2020-05-11 13:54:40 +02:00
attributes = > [
{ name = > 'AverageEnqueueTime' } , { name = > 'ConsumerCount' } ,
{ name = > 'ProducerCount' } , { name = > 'MemoryPercentUsage' } ,
{ name = > 'QueueSize' } , { name = > 'EnqueueCount' } ,
{ name = > 'DequeueCount' } , { name = > 'ExpiredCount' } ,
2020-05-11 15:46:01 +02:00
{ name = > 'InFlightCount' } , { name = > 'AverageMessageSize' }
2020-05-11 13:54:40 +02:00
]
} ,
{
mbean = > 'org.apache.activemq:brokerName=*,type=Broker' ,
attributes = > [
{ name = > 'StorePercentUsage' } , { name = > 'TempPercentUsage' } ,
{ name = > 'MemoryPercentUsage' }
]
}
] ;
my $ result = $ options { custom } - > get_attributes ( request = > $ request , nothing_quit = > 1 ) ;
$ self - > { cache_name } = 'activemq_' . $ self - > { mode } . '_' . md5_hex ( $ options { custom } - > get_connection_info ( ) ) . '_' .
( defined ( $ self - > { option_results } - > { filter_counters } ) ? md5_hex ( $ self - > { option_results } - > { filter_counters } ) : md5_hex ( 'all' ) ) . '_' .
( defined ( $ self - > { option_results } - > { filter_broker_name } ) ? md5_hex ( $ self - > { option_results } - > { filter_broker_name } ) : md5_hex ( 'all' ) ) . '_' .
2020-05-11 16:16:43 +02:00
( defined ( $ self - > { option_results } - > { filter_destination_name } ) ? md5_hex ( $ self - > { option_results } - > { filter_destination_name } ) : md5_hex ( 'all' ) ) . '_' .
( defined ( $ self - > { option_results } - > { filter_destination_type } ) ? md5_hex ( $ self - > { option_results } - > { filter_destination_type } ) : md5_hex ( 'all' ) ) ;
2020-05-11 13:54:40 +02:00
$ self - > { brokers } = { } ;
foreach my $ mbean ( keys %$ result ) {
2020-05-11 16:16:43 +02:00
next if ( $ mbean !~ /org.apache.activemq:brokerName=(.*?),(?:destinationName=(.*?),destinationType=(.*?),|type=Broker)/ ) ;
my ( $ broker_name , $ destination_name , $ destination_type ) = ( $ 1 , $ 2 , $ 3 ) ;
2020-05-11 13:54:40 +02:00
if ( defined ( $ self - > { option_results } - > { filter_broker_name } ) && $ self - > { option_results } - > { filter_broker_name } ne '' &&
$ broker_name !~ /$self->{option_results}->{filter_broker_name}/ ) {
$ self - > { output } - > output_add ( long_msg = > "skipping '" . $ broker_name . "': no matching filter." , debug = > 1 ) ;
next ;
}
2020-05-11 16:16:43 +02:00
if ( defined ( $ self - > { option_results } - > { filter_destination_type } ) && $ self - > { option_results } - > { filter_destination_type } ne '' &&
$ destination_type !~ /$self->{option_results}->{filter_destination_type}/ ) {
$ self - > { output } - > output_add ( long_msg = > "skipping '" . $ broker_name . "': no matching filter." , debug = > 1 ) ;
next ;
}
2020-05-11 13:54:40 +02:00
if ( ! defined ( $ self - > { brokers } - > { $ broker_name } ) ) {
$ self - > { brokers } - > { $ broker_name } = {
display = > $ broker_name ,
2020-05-11 16:16:43 +02:00
queue = > { } ,
topic = > { }
2020-05-11 13:54:40 +02:00
} ;
}
if ( defined ( $ destination_name ) ) {
2020-05-11 16:16:43 +02:00
my $ type = lc ( $ destination_type ) ;
next if ( $ type ne 'topic' && $ type ne 'queue' ) ;
2020-05-11 13:54:40 +02:00
if ( defined ( $ self - > { option_results } - > { filter_destination_name } ) && $ self - > { option_results } - > { filter_destination_name } ne '' &&
$ destination_name !~ /$self->{option_results}->{filter_destination_name}/ ) {
$ self - > { output } - > output_add ( long_msg = > "skipping '" . $ destination_name . "': no matching filter." , debug = > 1 ) ;
next ;
}
2020-05-11 16:16:43 +02:00
$ self - > { brokers } - > { $ broker_name } - > { $ type } - > { $ destination_name } = {
2020-05-11 13:54:40 +02:00
display = > $ destination_name ,
% { $ result - > { $ mbean } }
} ;
} else {
$ self - > { brokers } - > { $ broker_name } - > { global } = {
display = > $ broker_name ,
% { $ result - > { $ mbean } }
} ;
}
}
if ( scalar ( keys % { $ self - > { brokers } } ) <= 0 ) {
$ self - > { output } - > output_add ( short_msg = > 'no brokers found' ) ;
}
}
1 ;
__END__
= head1 MODE
Check brokers .
= over 8
= item B <--filter-broker-name>
Filter broker name ( Can be a regexp ) .
= item B <--filter-destination-name>
Filter destination name ( Can be a regexp ) .
2020-05-11 16:16:43 +02:00
= item B <--filter-destination-type>
Filter destination type ( Can be a regexp ) .
2020-05-11 13:54:40 +02:00
= item B <--warning-*> B <--critical-*>
Thresholds .
Can be: 'store-usage' ( % ) , 'temporary-usage' ( % ) , 'memory-usage' ( % ) ,
'queue-average-enqueue-time' ( ms ) , 'queue-consumers-connected' ,
'queue-producers-connected' , 'queue-memory-usage' ( % ) , 'queue-size' ,
2020-05-11 15:46:01 +02:00
'queue-messages-enqueued' , 'queue-messages-dequeued' , 'queue-messages-expired' ,
2020-05-11 16:16:43 +02:00
'queue-messages-inflighted' ,
'topic-average-enqueue-time' ( ms ) , 'topic-consumers-connected' ,
'topic-producers-connected' , 'topic-memory-usage' ( % ) , 'topic-size' ,
'topic-messages-enqueued' , 'topic-messages-dequeued' , 'topic-messages-expired' ,
'topic-messages-inflighted' .
2020-05-11 13:54:40 +02:00
= back
= cut