Permalink
Browse files

generalize nginx parsing to work for api traffic

  • Loading branch information...
1 parent eac50eb commit e99d50bb50279681773cea7d76f458947b5eaf40 @mmcgrana mmcgrana committed Mar 24, 2012
Showing with 15 additions and 14 deletions.
  1. +4 −4 src/pulse/def.clj
  2. +11 −10 src/pulse/parse.clj
View
@@ -1101,19 +1101,19 @@
(defstat api-response-500-errors
(per-minute
- (fn [evt] (and (kv? evt :http_domain "api.heroku.com") (kv? evt :http_status 500)))))
+ (fn [evt] (and (nginx-request? evt) (kv? evt :http_domain "api.heroku.com") (kv? evt :http_status 500)))))
(defstat api-response-502-errors
(per-minute
- (fn [evt] (and (kv? evt :http_domain "api.heroku.com") (kv? evt :http_status 502)))))
+ (fn [evt] (and (nginx-request? evt) (kv? evt :http_domain "api.heroku.com") (kv? evt :http_status 502)))))
(defstat api-response-503-errors
(per-minute
- (fn [evt] (and (kv? evt :http_domain "api.heroku.com") (kv? evt :http_status 503)))))
+ (fn [evt] (and (nginx-request? evt) (kv? evt :http_domain "api.heroku.com") (kv? evt :http_status 503)))))
(defstat api-response-504-errors
(per-minute
- (fn [evt] (and (kv? evt :http_domain "api.heroku.com") (kv? evt :http_status 504)))))
+ (fn [evt] (and (nginx-request? evt) (kv? evt :http_domain "api.heroku.com") (kv? evt :http_status 504)))))
(defstat api-request-time
(mean 60
View
@@ -64,23 +64,24 @@
(merge evt (parse-msg-attrs (:msg evt))))
(def nginx-access-re
- ; http_host http_method,_url,_version http_status,_bytes,_referrer,_user_agent,_domain
- #"^([0-9\.]+) - - \[\d\d\/[a-zA-z]{3}\/\d\d\d\d:\d\d:\d\d:\d\d [\-\+]\d\d00\] \"([a-zA-Z]+) (\S+) HTTP\/(...)\" (\d+) (\d+) \"([^\"]+)\" \"([^\"]+)\" (\S+)$")
+ ; http_host ;http_user http_method,_url,_version http_status,_bytes,_referrer,_user_agent,_domain
+ #"^([0-9\.]+) - (\S+) \[\d\d\/[a-zA-z]{3}\/\d\d\d\d:\d\d:\d\d:\d\d [\-\+]\d\d00\] \"([a-zA-Z]+) (\S+) HTTP\/(...)\" (\d+) (\d+) \"([^\"]+)\" \"([^\"]+)\" (\S+)$")
(defn inflate-nginx-access [evt]
(if (= (:source evt) "nginx")
(let [m (re-matcher nginx-access-re (:msg evt))]
(if (.find m)
(merge evt
{:http_host (.group m 1)
- :http_method (.group m 2)
- :http_url (.group m 3)
- :http_version (.group m 4)
- :http_status (parse-long (.group m 5))
- :http_bytes (parse-long (.group m 6))
- :http_referrer (.group m 7)
- :http_user_agent (.group m 8)
- :http_domain (.group m 9)})))))
+ :http_user (.group m 2)
+ :http_method (.group m 3)
+ :http_url (.group m 4)
+ :http_version (.group m 5)
+ :http_status (parse-long (.group m 6))
+ :http_bytes (parse-long (.group m 7))
+ :http_referrer (.group m 8)
+ :http_user_agent (.group m 9)
+ :http_domain (.group m 10)})))))
(def varnish-access-re
#"^[0-9\.]+ - - .*\" (\d\d\d) .*$")

0 comments on commit e99d50b

Please sign in to comment.