@@ -36,16 +36,16 @@ def process(rabbitmq, graphite):
3636 ['channels' , 'connections' , 'consumers' , 'exchanges' , 'queues' ]:
3737 if m_instance in overview ['object_totals' ]:
3838 _send_graphite_metric (
39- sock , graphite , rabbitmq , m_instance , overview ['object_totals' ][m_instance ])
39+ sock , graphite , rabbitmq , '{}_total_count' . format ( m_instance ) , overview ['object_totals' ][m_instance ])
4040
4141 # Aggregated Queue message stats
4242 for m_instance in \
4343 ['messages' , 'messages_ready' , 'messages_unacknowledged' ]:
4444 if m_instance in overview ['queue_totals' ]:
45- _send_graphite_metric (sock , graphite , rabbitmq , 'queue_total-{}-count ' .format (
45+ _send_graphite_metric (sock , graphite , rabbitmq , 'queue_{}_total_count ' .format (
4646 m_instance ), overview ['queue_totals' ][m_instance ])
4747
48- _send_graphite_metric (sock , graphite , rabbitmq , 'queue_total-{}-rate ' .format (m_instance ), overview ['queue_totals' ]['{}_details' .format (
48+ _send_graphite_metric (sock , graphite , rabbitmq , 'queue_{}_total_rate ' .format (m_instance ), overview ['queue_totals' ]['{}_details' .format (
4949 m_instance )]
5050 ['rate' ])
5151
@@ -57,33 +57,73 @@ def process(rabbitmq, graphite):
5757 'redeliver' , 'return_unroutable'
5858 ]:
5959 if m_instance in overview ['message_stats' ]:
60- _send_graphite_metric (sock , graphite , rabbitmq , 'message_total-{}-count ' .format (
60+ _send_graphite_metric (sock , graphite , rabbitmq , 'message_{}_total_count ' .format (
6161 m_instance ), overview ['message_stats' ][m_instance ])
6262
63- _send_graphite_metric (sock , graphite , rabbitmq , 'message_total-{}-rate ' .format (m_instance ), overview ['message_stats' ]['{}_details' .format (m_instance )]
63+ _send_graphite_metric (sock , graphite , rabbitmq , 'message_{}_total_rate ' .format (m_instance ), overview ['message_stats' ]['{}_details' .format (m_instance )]
6464 ['rate' ])
6565
66- # Configurable per-queue message counts
67- for queue_name in rabbitmq ["queues" ]:
68- messages_detail = None
69- try :
70- messages_detail = rabbitClient .get_messages (
71- rabbitmq ["vhost" ], queue_name , 1 , True )
72- except HTTPError as err :
73- logging .error (
74- 'Error Opening Queue [{}] details: {}'
75- .format (queue_name , err ))
76- if messages_detail is None :
77- count = 0
78- else :
79- # the consume message is not counted
80- count = messages_detail [0 ]['message_count' ] + 1
81- _send_graphite_metric (
82- sock , graphite , rabbitmq , 'msg_count-{}' .format (queue_name ), count )
66+ # Connections metrics
67+ connections = rabbitClient .get_connections ()
68+ connections_dict = {'channels' : 'channels' ,
69+ 'recv_oct' : 'received_bytes' ,
70+ 'recv_cnt' : 'received_packets' ,
71+ 'send_oct' : 'send_bytes' ,
72+ 'send_cnt' : 'send_packets' ,
73+ 'send_pend' : 'send_pending'
74+ }
75+ for m_instance , m_instance_label in connections_dict .iteritems ():
76+ if connections is None :
77+ _send_graphite_metric (
78+ sock , graphite , rabbitmq , 'connections.{}' .format (m_instance_label ), 0 )
79+ elif m_instance in connections :
80+ _send_graphite_metric (sock , graphite , rabbitmq ,
81+ 'connections.{}' .format (m_instance_label ), connections [m_instance ])
82+
83+ # Node metrics
84+ nodes = rabbitClient .get_nodes ()
85+ nodes_dict = {'running' : 'node_running' ,
86+ 'mem_used' : 'node_mem_used' ,
87+ 'mem_limit' : 'node_mem_limit' ,
88+ 'mem_alarm' : 'node_mem_alarm' ,
89+ 'disk_free' : 'node_disk_free' ,
90+ 'disk_free_alarm' : 'node_disk_free_alarm' ,
91+ 'disk_free_limit' : 'node_disk_free_limit' ,
92+ 'fd_used' : 'node_file_descriptor_used' ,
93+ 'fd_total' : 'node_file_descriptor_total' ,
94+ 'sockets_used' : 'node_sockets_used' ,
95+ 'sockets_total' : 'node_sockets_total' ,
96+ 'partitions_len' : 'node_partitions'
97+ }
98+ for m_instance , m_instance_label in nodes_dict .iteritems ():
99+ if nodes is not None :
100+ for node in nodes :
101+ if m_instance in node :
102+ # We multiply the metric value by 1 to handle boolean conversion
103+ _send_graphite_metric (sock , graphite , rabbitmq ,
104+ 'nodes.{}.{}' .format (node ['name' ].replace ('.' , '_' ), m_instance_label ), node [m_instance ]* 1 )
105+
106+ # Queues
107+ queues = rabbitClient .get_queues ()
108+ for m_instance in \
109+ ['messages_ready' , 'messages_unacknowledged' , 'messages' ,
110+ 'messages_ready_ram' , 'messages_unacknowledged_ram' , 'messages_ram' ,
111+ 'messages_persistent' , 'message_bytes' , 'message_bytes_ready' ,
112+ 'message_bytes_unacknowledged' , 'message_bytes_ram' , 'message_bytes_persistent' ,
113+ 'consumers' , 'consumer_utilisation' , 'memory' , 'head_message_timestamp' ]:
114+ if queues is not None :
115+ for queue in queues :
116+ if m_instance in queue :
117+ _send_graphite_metric (sock , graphite , rabbitmq ,
118+ 'queues.{}.{}' .format (queue ['name' ].replace ('.' , '_' ), m_instance ), queue [m_instance ])
119+
120+ timediff = time .time () - starttime
121+ # Send time elapsed for scrapping metrics
122+ _send_graphite_metric (sock , graphite , rabbitmq ,
123+ 'scraptime_elapsed_seconds' , timediff )
83124
84125 sock .close ()
85126
86- timediff = time .time () - starttime
87127 logging .info ('All metrics has been sent from RabbitMQ [{}] to Graphite [{}] in: {} sec' .format (
88128 rabbitmq ["cluster_name" ], graphite ["host" ], round (timediff , 2 )))
89129
0 commit comments