Created
March 22, 2017 01:08
-
-
Save Pompeu/3073f3701f93373a823b3e0076473304 to your computer and use it in GitHub Desktop.
parse.js
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
| /* | |
| ** SIEGE 3.0.8 | |
| ** Preparing 100 concurrent users for battle. | |
| The server is now under siege... | |
| Lifting the server siege... done. | |
| Transactions: 9700 hits | |
| Availability: 100.00 % | |
| Elapsed time: 19.19 secs | |
| Data transferred: 0.16 MB | |
| Response time: 0.20 secs | |
| Transaction rate: 505.47 trans/sec | |
| Throughput: 0.01 MB/sec | |
| Concurrency: 99.47 | |
| Successful transactions: 9700 | |
| Failed transactions: 0 | |
| Longest transaction: 0.27 | |
| Shortest transaction: 0.10 | |
| FILE: /var/log/siege.log | |
| You can disable this annoying message by editing | |
| the .siegerc file in your home directory; change | |
| the directive 'show-logfile' to false. | |
| */ | |
| 'use strict' | |
| const Bluebird = require('bluebird') | |
| const readFile = Bluebird.promisify(require('fs').readFile) | |
| const getIndexOf = (file, pattern) => file.indexOf(pattern) | |
| const firthPatternDelemiter = 'done.' | |
| const lastPatterDelemiter = 'FILE:' | |
| const firthPatternToReplace = /done./g | |
| const removeFisthParth = file => | |
| file | |
| .substring(getIndexOf(file, firthPatternDelemiter)) | |
| .replace(firthPatternToReplace, '') | |
| const indexOfLastPart = file => getIndexOf(file, lastPatterDelemiter) | |
| const replaceLastPart = file => | |
| file.substring(0, indexOfLastPart(file) != -1 ? indexOfLastPart(file) : file.length); | |
| const trimAll = str => str.trim() | |
| const mapToObject = file => file.split('\n').reduce((acc, line) => { | |
| const splitedLine = line.split(':'); | |
| const key = splitedLine[0]; | |
| const value = splitedLine[1].replace(/[a-zA-Z\/% ]/g, ''); | |
| acc[`${key}`] = `${value}`; | |
| return acc; | |
| }, {}); | |
| readFile('./log.log', 'utf8') | |
| .then(removeFisthParth) | |
| .then(replaceLastPart) | |
| .then(trimAll) | |
| .then(mapToObject) | |
| .then(console.log) | |
| // result | |
| /* | |
| { Transactions: '9700', | |
| Availability: '100.00', | |
| 'Elapsed time': '19.19', | |
| 'Data transferred': '0.16', | |
| 'Response time': '0.20', | |
| 'Transaction rate': '505.47', | |
| Throughput: '0.01', | |
| Concurrency: '99.47', | |
| 'Successful transactions': '9700', | |
| 'Failed transactions': '0', | |
| 'Longest transaction': '0.27', | |
| 'Shortest transaction': '0.10' } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment