@@ -37,6 +37,7 @@ class NginxCollector(diamond.collector.Collector):
37
37
def get_default_config_help (self ):
38
38
config_help = super (NginxCollector , self ).get_default_config_help ()
39
39
config_help .update ({
40
+ 'precision' : 'Number of decimal places to report to' ,
40
41
'req_host' : 'Hostname' ,
41
42
'req_port' : 'Port' ,
42
43
'req_path' : 'Path' ,
@@ -47,6 +48,7 @@ def get_default_config_help(self):
47
48
48
49
def get_default_config (self ):
49
50
default_config = super (NginxCollector , self ).get_default_config ()
51
+ default_config ['precision' ] = 0
50
52
default_config ['req_host' ] = 'localhost'
51
53
default_config ['req_port' ] = 8080
52
54
default_config ['req_path' ] = '/nginx_status'
@@ -80,25 +82,41 @@ def collect(self):
80
82
req = urllib2 .Request (url = url , headers = headers )
81
83
try :
82
84
handle = urllib2 .urlopen (req )
85
+ precision = int (self .config ['precision' ])
83
86
for l in handle .readlines ():
84
87
l = l .rstrip ('\r \n ' )
85
88
if activeConnectionsRE .match (l ):
86
89
self .publish_gauge (
87
90
'active_connections' ,
88
- int (activeConnectionsRE .match (l ).group ('conn' )))
91
+ int (activeConnectionsRE .match (l ).group ('conn' )),
92
+ precision )
89
93
elif totalConnectionsRE .match (l ):
90
94
m = totalConnectionsRE .match (l )
91
95
req_per_conn = float (m .group ('req' )) / \
92
96
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 )
97
109
elif connectionStatusRE .match (l ):
98
110
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 )
102
120
except IOError , e :
103
121
self .log .error ("Unable to open %s" % url )
104
122
except Exception , e :
0 commit comments