2727
2828def process (rabbitmq , graphite ):
2929 logging .debug (
30- "Processing RabbitMQ: {} on graphite {}" .format (rabbitmq ["cluster_name" ], graphite ["host" ]))
30+ "Processing RabbitMQ: {0 } on graphite {1 }" .format (rabbitmq ["cluster_name" ], graphite ["host" ]))
3131 starttime = time .time ()
3232 sock = _socket_for_host_port (graphite ["host" ], graphite ["port" ])
3333 overview = rabbitClient .get_overview ()
@@ -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 , '{}_total_count' .format (m_instance ), overview ['object_totals' ][m_instance ])
39+ sock , graphite , rabbitmq , '{0 }_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_{0 }_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_{0 }_total_rate' .format (m_instance ), overview ['queue_totals' ]['{0 }_details' .format (
4949 m_instance )]
5050 ['rate' ])
5151
@@ -57,10 +57,10 @@ 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_{0 }_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_{0 }_total_rate' .format (m_instance ), overview ['message_stats' ]['{0 }_details' .format (m_instance )]
6464 ['rate' ])
6565
6666 # Connections metrics
@@ -75,10 +75,10 @@ def process(rabbitmq, graphite):
7575 for m_instance , m_instance_label in connections_dict .iteritems ():
7676 if connections is None :
7777 _send_graphite_metric (
78- sock , graphite , rabbitmq , 'connections.{}' .format (m_instance_label ), 0 )
78+ sock , graphite , rabbitmq , 'connections.{0 }' .format (m_instance_label ), 0 )
7979 elif m_instance in connections :
8080 _send_graphite_metric (sock , graphite , rabbitmq ,
81- 'connections.{}' .format (m_instance_label ), connections [m_instance ])
81+ 'connections.{0 }' .format (m_instance_label ), connections [m_instance ])
8282
8383 # Node metrics
8484 nodes = rabbitClient .get_nodes ()
@@ -101,7 +101,7 @@ def process(rabbitmq, graphite):
101101 if m_instance in node :
102102 # We multiply the metric value by 1 to handle boolean conversion
103103 _send_graphite_metric (sock , graphite , rabbitmq ,
104- 'nodes.{}.{}' .format (node ['name' ].replace ('.' , '_' ), m_instance_label ), node [m_instance ]* 1 )
104+ 'nodes.{0 }.{1 }' .format (node ['name' ].replace ('.' , '_' ), m_instance_label ), node [m_instance ]* 1 )
105105
106106 # Queues
107107 queues = rabbitClient .get_queues ()
@@ -115,7 +115,7 @@ def process(rabbitmq, graphite):
115115 for queue in queues :
116116 if m_instance in queue :
117117 _send_graphite_metric (sock , graphite , rabbitmq ,
118- 'queues.{}.{}' .format (queue ['name' ].replace ('.' , '_' ), m_instance ), queue [m_instance ])
118+ 'queues.{0 }.{1 }' .format (queue ['name' ].replace ('.' , '_' ), m_instance ), queue [m_instance ])
119119
120120 timediff = time .time () - starttime
121121 # Send time elapsed for scrapping metrics
@@ -124,15 +124,15 @@ def process(rabbitmq, graphite):
124124
125125 sock .close ()
126126
127- logging .info ('All metrics has been sent from RabbitMQ [{}] to Graphite [{}] in: {} sec' .format (
127+ logging .info ('All metrics has been sent from RabbitMQ [{0 }] to Graphite [{1 }] in: {2 } sec' .format (
128128 rabbitmq ["cluster_name" ], graphite ["host" ], round (timediff , 2 )))
129129
130130
131131def _send_graphite_metric (sock , graphite , rabbitmq , metricName , metricValue ):
132132 now = time .time ()
133133 metric = '{0}.{1}.{2} {3} {4}\n ' .format (
134134 graphite ["prefix" ], rabbitmq ["cluster_name" ], metricName , metricValue , now )
135- logging .debug ("Sending metric: {}" .format (metric ))
135+ logging .debug ("Sending metric: {0 }" .format (metric ))
136136 sock .sendall (metric )
137137
138138
@@ -150,29 +150,29 @@ def main():
150150 # load config file
151151 configFilePath = args .config
152152 if os .path .isfile (configFilePath ):
153- logging .debug ('Processing config file {}' .format (configFilePath ))
153+ logging .debug ('Processing config file {0 }' .format (configFilePath ))
154154 with open (configFilePath ) as configFile :
155155 conf = json .load (configFile )
156- logging .debug ('Graphite configuration: {}' .format (
156+ logging .debug ('Graphite configuration: {0 }' .format (
157157 conf ["graphite_servers" ]))
158- logging .debug ('RabbitMQ configuration: {}' .format (
158+ logging .debug ('RabbitMQ configuration: {0 }' .format (
159159 conf ["rabbitmq_clusters" ]))
160160 for rabbitmq in conf ["rabbitmq_clusters" ]:
161161 logging .debug (
162- 'Working on Rabbitmq cluster: {}' .format (rabbitmq ['cluster_name' ]))
163- rabbitClient = Client ('{}:{}' .format (
162+ 'Working on Rabbitmq cluster: {0 }' .format (rabbitmq ['cluster_name' ]))
163+ rabbitClient = Client ('{0 }:{1 }' .format (
164164 rabbitmq ['host' ], rabbitmq ['port' ]), rabbitmq ['username' ], rabbitmq ['password' ])
165165 for graphite in conf ["graphite_servers" ]:
166166 process (rabbitmq , graphite )
167167 else :
168- logging .error ('You must pass existing configFilePath, actual is {}' .format (
168+ logging .error ('You must pass existing configFilePath, actual is {0 }' .format (
169169 configFilePath ))
170170 sys .exit (1 )
171171
172172
173173def excepthook (type , value , tb ):
174174 # you can log the exception to a file here
175- logging .error ('ERROR: {} {}' .format (type , value ))
175+ logging .error ('ERROR: {0 } {1 }' .format (type , value ))
176176
177177 # the following line does the default (prints it to err)
178178 sys .__excepthook__ (type , value , tb )
0 commit comments