Last active
December 18, 2015 16:49
-
-
Save dadoonet/5814066 to your computer and use it in GitHub Desktop.
Convert a nodes stats response (JSON Format) to a CSV representation for easier cluster overview
Uses NodeJS
This file contains hidden or 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
curl -XGET 'http://localhost:9200/_nodes/stats?all=true&pretty=true' > nodes.stats.json | |
node stats_converter.js | |
# Or | |
node stats_converter.js filename |
This file contains hidden or 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
var fs = require('fs'); | |
var filename; | |
if (process.argv.length > 1) { | |
filename = process.argv[2]; | |
} else { | |
filename = "nodes.stats.json"; | |
} | |
var file = __dirname + '/' + filename; | |
console.log("Reading content of " + file); | |
fs.readFile(file, 'utf8', function (err, data) { | |
if (err) { | |
console.log('Error: ' + err); | |
return; | |
} | |
data = JSON.parse(data); | |
var firstline = | |
"hostname,memory,heap,docs.count,docs.deleted,size,indexed,indextime,queries,querytime,merges,mergetime,refresh,refreshtime"; | |
console.log(firstline); | |
Object.keys(data.nodes).forEach(function(element) { | |
var node = data.nodes[element]; | |
var displaySize = function(size) { | |
return Math.round(size/1024/1024); | |
}; | |
var displayTime = function(time) { | |
return Math.round(time/1000/3600); | |
}; | |
var line = | |
node.hostname + "," + | |
displaySize(node.os.mem.free_in_bytes+node.os.mem.used_in_bytes) + "," + | |
displaySize(node.jvm.mem.heap_committed_in_bytes) + "," + | |
node.indices.docs.count + "," + | |
node.indices.docs.deleted + "," + | |
displaySize(node.indices.store.size_in_bytes) + "," + | |
node.indices.indexing.index_total + "," + | |
displayTime(node.indices.indexing.index_time_in_millis) + "," + | |
node.indices.search.query_total + "," + | |
displayTime(node.indices.search.query_time_in_millis) + "," + | |
node.indices.merges.total + "," + | |
displayTime(node.indices.merges.total_time_in_millis) + "," + | |
node.indices.refresh.total + "," + | |
displayTime(node.indices.refresh.total_time_in_millis); | |
console.log(line); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment