Last active
August 29, 2015 14:16
-
-
Save smarigowda/cf35c70e258a59e04002 to your computer and use it in GitHub Desktop.
Audit Log Parser
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
console.log('node 01 and node 02'); | |
console.log('latency summary of each transaction type including message direction IN/ OUT'); | |
var file = 'file_path'; | |
function qtile (leaves, ptile) { | |
return d3.quantile(leaves.map(function(d) { return +d.latency }).sort(), ptile); | |
} | |
function report(file) { | |
d3.csv(file, function(data) { | |
d3.select('body').append('h2').text('Report -- ' + file); | |
d3.select('body').append('h2').text('Labels'); | |
d3.select('body').append('h2').text('Operation COUNT, SUM Latency, MAX Latency, MIN Latency, 90th Percentile Latency, 95th Percentile Latency') | |
console.log(data) | |
//var datafiltered = data.filter(function(d) { return +d.latency >= 1000; }); | |
var nested = d3.nest() | |
.key(function(d) { return d.service }) | |
.key(function(d) { return d.operation }) | |
//.key(function(d) { return d.corid }) | |
.key(function(d) { return d.transtype }) | |
.key(function(d) { return d.status }) | |
.rollup(function(leaves) { return { | |
"length": leaves.length, | |
"latency_sum": d3.sum(leaves, function(d) { return parseInt(d.latency); }), | |
"latency_max": d3.max(leaves, function(d) { return parseInt(d.latency); }), | |
"latency_min": d3.min(leaves, function(d) { return parseInt(d.latency); }), | |
"latency_90pctile": Math.floor(qtile(leaves, 0.90)), | |
"latency_95pctile": Math.floor(qtile(leaves, 0.95)) | |
}}) | |
.entries(data); | |
console.log('nested object....'); | |
console.log(nested); | |
// list all services | |
nested.map(function(d) { console.log(d.key); }); | |
// filter a service | |
// var aservice = nested.filter(function(d) { console.log(d.key); return d.key == " PersonaliseDocumentService" }); | |
// console.log(aservice); | |
// service | |
var sel1 = d3.select('body') | |
.selectAll("div#one") | |
.data(nested).enter() // bind all objects having service as key | |
.append('div') | |
.attr('id', 'one').text(function(d) { return 'service = ' + d.key; }) | |
.style('color', 'maroon'); | |
// operation | |
var sel2 = sel1.selectAll('div#one') // select all elements corresponding to 'service' | |
.data(function(d) { return d.values; }) // for each service, bind 'operation' objects | |
.enter() | |
.append('div') | |
.attr('id', 'two') | |
.text(function(d) { return d.key; }) | |
.style('color', 'blue'); | |
// transaction type | |
var sel3 = sel2.selectAll('div#two') // select all elements corresponding to 'operation' | |
.data(function(d) { return d.values; }) // for each operation, bind 'transaction type' objects | |
.enter() | |
.append('div') | |
.attr('id', 'three') | |
.text(function(d) { return d.key; }) | |
.style('color', 'peru'); | |
// status IN or OUT | |
var table = sel3.selectAll('div#three') // select all elements corresponding to 'transaction type' | |
.data(function(d) { return d.values; }) // for each transaction type, bind 'IN/OUT' objects | |
.enter() | |
.append('div') | |
.attr('id', 'four') | |
// now, table is a selection with leaf objects data bound | |
//.data(['count', 'sum', 'max', 'min', '90 pct', '95 pct' ]) | |
table.append('table') | |
// .append('tr') // for each element, append a 'tr' | |
// .selectAll('th') // new empty selection | |
// .data(['', '', '', '', '', '', '' ]) // binding to create header row | |
// .enter() | |
// .append('th') // ceate 7 header elements | |
// .text(function(d) { return d }) // empty string at the moment | |
// .style('border', '1px solid black'); | |
d3.selectAll('table') | |
.append('tr') // appends and creates a new selection | |
//.html(function(d) { return '<td style="color: #990000;">' + d.key + '</td><td>' + d.values.length + '</td><td>' + d.values.latency_sum + '</td><td>'+ d.values.latency_max + '</td><td>' + d.values.latency_min + '</td><td>'+ d.values.latency_90pctile + '</td><td>' + d.values.latency_95pctile +'</td>' }); | |
.selectAll('td') // empty at the moment | |
.data(function(d) { return d3.entries(d.values) }) // 6 leaf elements, d3.entries converts a plain object into array of objects | |
.enter() | |
.append('td') // create 6 td elements | |
.text(function(d) { return d.value; }); | |
d3.selectAll('tr') | |
.append('td') | |
.text(function(d) { return d.key }) | |
.style('color', function(d) { return d.key.indexOf('FAILED') == -1 ? 'Chartreuse' : 'red' }); | |
}); | |
} | |
report(file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A d3.js program to parse audit logs and generate HTML report.