Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show partition replica usage and limit in kafka:info (#168)
* Show partition replica usage and limit in kafka:info * Add pixelbar dep * Add utilization bars to kafka:info * Use the proper multiplication sign * Make a simpler utilization bar This drops pixelBar in favor of a builtin utilizationBar that does not use awesome unicode to fill partial blocks, because this leads to font issues. * floor() not round() for utilizationBar
- Loading branch information
Showing
6 changed files
with
123 additions
and
30 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const chalk = require('chalk') | ||
|
||
module.exports = function (current, total, width = 10) { | ||
let percentage = current / total | ||
if (percentage > 1) percentage = 1 | ||
if (percentage < 0) percentage = 0 | ||
const filled = Math.floor(percentage * width) | ||
const empty = width - filled | ||
let output = chalk.blue('█'.repeat(filled)) | ||
output += '·'.repeat(empty) | ||
return `[${output}]` | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const mocha = require('mocha') | ||
const describe = mocha.describe | ||
const it = mocha.it | ||
|
||
const utilizationBar = require('../../lib/utilizationBar') | ||
|
||
describe('utilizationBar', function () { | ||
const cases = [ | ||
[0, 100, '[··········]', '[···············]'], | ||
[100, 100, '[\u001b[34m██████████\u001b[39m]', '[\u001b[34m███████████████\u001b[39m]'], | ||
[99, 100, '[\u001b[34m█████████\u001b[39m·]', '[\u001b[34m██████████████\u001b[39m·]'], | ||
[50, 100, '[\u001b[34m█████\u001b[39m·····]', '[\u001b[34m███████\u001b[39m········]'], | ||
[110, 100, '[\u001b[34m██████████\u001b[39m]', '[\u001b[34m███████████████\u001b[39m]'], | ||
[-50, 100, '[··········]', '[···············]'] | ||
] | ||
cases.forEach(function (testcase) { | ||
const current = testcase[0] | ||
const total = testcase[1] | ||
const expected10 = testcase[2] | ||
const expected15 = testcase[3] | ||
it(`Renders a ${current}/${total} bar correctly`, function () { | ||
expect(utilizationBar(current, total)).to.equal(expected10) | ||
expect(utilizationBar(current, total, 15)).to.equal(expected15) | ||
}) | ||
}) | ||
}) |
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