@@ -37,6 +37,7 @@ class NginxCollector(diamond.collector.Collector):
3737 def get_default_config_help (self ):
3838 config_help = super (NginxCollector , self ).get_default_config_help ()
3939 config_help .update ({
40+ 'precision' : 'Number of decimal places to report to' ,
4041 'req_host' : 'Hostname' ,
4142 'req_port' : 'Port' ,
4243 'req_path' : 'Path' ,
@@ -47,6 +48,7 @@ def get_default_config_help(self):
4748
4849 def get_default_config (self ):
4950 default_config = super (NginxCollector , self ).get_default_config ()
51+ default_config ['precision' ] = 0
5052 default_config ['req_host' ] = 'localhost'
5153 default_config ['req_port' ] = 8080
5254 default_config ['req_path' ] = '/nginx_status'
@@ -80,25 +82,41 @@ def collect(self):
8082 req = urllib2 .Request (url = url , headers = headers )
8183 try :
8284 handle = urllib2 .urlopen (req )
85+ precision = int (self .config ['precision' ])
8386 for l in handle .readlines ():
8487 l = l .rstrip ('\r \n ' )
8588 if activeConnectionsRE .match (l ):
8689 self .publish_gauge (
8790 'active_connections' ,
88- int (activeConnectionsRE .match (l ).group ('conn' )))
91+ int (activeConnectionsRE .match (l ).group ('conn' )),
92+ precision )
8993 elif totalConnectionsRE .match (l ):
9094 m = totalConnectionsRE .match (l )
9195 req_per_conn = float (m .group ('req' )) / \
9296 float (m .group ('acc' ))
93- self .publish_counter ('conn_accepted' , int (m .group ('conn' )))
94- self .publish_counter ('conn_handled' , int (m .group ('acc' )))
95- self .publish_counter ('req_handled' , int (m .group ('req' )))
96- self .publish_gauge ('req_per_conn' , float (req_per_conn ))
97+ self .publish_counter ('conn_accepted' ,
98+ int (m .group ('conn' )),
99+ precision )
100+ self .publish_counter ('conn_handled' ,
101+ int (m .group ('acc' )),
102+ precision )
103+ self .publish_counter ('req_handled' ,
104+ int (m .group ('req' )),
105+ precision )
106+ self .publish_gauge ('req_per_conn' ,
107+ float (req_per_conn ),
108+ precision )
97109 elif connectionStatusRE .match (l ):
98110 m = connectionStatusRE .match (l )
99- self .publish_gauge ('act_reads' , int (m .group ('reading' )))
100- self .publish_gauge ('act_writes' , int (m .group ('writing' )))
101- self .publish_gauge ('act_waits' , int (m .group ('waiting' )))
111+ self .publish_gauge ('act_reads' ,
112+ int (m .group ('reading' )),
113+ precision )
114+ self .publish_gauge ('act_writes' ,
115+ int (m .group ('writing' )),
116+ precision )
117+ self .publish_gauge ('act_waits' ,
118+ int (m .group ('waiting' )),
119+ precision )
102120 except IOError , e :
103121 self .log .error ("Unable to open %s" % url )
104122 except Exception , e :
0 commit comments