Created
May 8, 2013 07:43
-
-
Save lloydmeta/5538871 to your computer and use it in GitHub Desktop.
Javascript API function for RockMongo to find slowish endpoints based on nginx access logs gathered from instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Contains questionable Javascript and Regex. You have been warned. | |
function () { | |
var counting_object = { | |
count_hash : {}, | |
clean_endpoint : function(endpoint) { | |
return endpoint.replace(/posts\/[\d]+/,'posts/:id') | |
.replace(/post\/[\d]+/,'posts/:id') | |
.replace(/max_id=[\d]+/,"{some_max_id}") | |
.replace(/since_id=[\d]+/,"{some_since_id}") | |
.replace(/count=[\d]+/,"{some_count}") | |
.replace(/\?_=[\d]+/,"") | |
.replace(/code=[\a-zA-Z0-9_]+/,"{some_code}") | |
.replace(/frm_id=.*/,"{some_frm_id}") | |
.replace("&{some_frm_id}", "") | |
.replace("{some_frm_id", "") | |
}, | |
increment_for_endpoint : function(endpoint){ | |
var that = this, | |
clean_endpoint = that.clean_endpoint(endpoint); | |
if (that.count_hash[clean_endpoint] && that.count_hash[clean_endpoint] >= 1){ | |
that.count_hash[clean_endpoint] = that.count_hash[clean_endpoint] + 1; | |
}else{ | |
that.count_hash[clean_endpoint] = 1; | |
} | |
return that.count_hash[clean_endpoint]; | |
} | |
}; | |
var cur = db.access.find( | |
{ | |
"upstream_request_time":{ | |
$gte: 5.0 | |
} | |
} | |
); | |
var out = []; | |
cur.forEach(function(x){ | |
counting_object.increment_for_endpoint((x['path']+' -> '+x['method']))}); | |
return(counting_object.count_hash); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment