-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display stats for all nodes running stats container
- Loading branch information
Showing
14 changed files
with
375 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/Python | ||
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/Python |
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 |
---|---|---|
|
@@ -35,3 +35,12 @@ | |
|
||
app/.build | ||
stats/.build | ||
|
||
linux-metrics | ||
bin/ | ||
install/ | ||
include/ | ||
lib/ | ||
pyvenv.cfg | ||
.Python | ||
.env |
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,25 @@ | ||
class CPUStats { | ||
constructor(stats) { | ||
this.stats = stats; | ||
} | ||
|
||
label() { | ||
return this.percent(); | ||
} | ||
|
||
level() { | ||
const percent = 100 - this.stats.cpu_usage.idle; | ||
|
||
if (percent < 75) { | ||
return 'success'; | ||
} else if (percent < 90) { | ||
return 'warning'; | ||
} else { | ||
return 'danger'; | ||
} | ||
} | ||
|
||
percent() { | ||
return numeral(100 - this.stats.cpu_usage.idle).format('0.00') + '%'; | ||
} | ||
} |
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,36 @@ | ||
class MemoryStats { | ||
constructor(stats) { | ||
this.stats = stats; | ||
} | ||
|
||
label() { | ||
const free = this.formatNumber(this.free()); | ||
const total = this.formatNumber(this.stats.total); | ||
|
||
return `${free} / ${total}`; | ||
} | ||
|
||
level() { | ||
const percent = 100 * (this.stats.used / this.stats.total); | ||
|
||
if (percent < 75) { | ||
return 'success'; | ||
} else if (percent < 90) { | ||
return 'warning'; | ||
} else { | ||
return 'danger'; | ||
} | ||
} | ||
|
||
percent() { | ||
return numeral(this.stats.used / this.stats.total).format('0.00%'); | ||
} | ||
|
||
free() { | ||
return this.stats.total - this.stats.used; | ||
} | ||
|
||
formatNumber(number) { | ||
return numeral(number).format('0.00b'); | ||
} | ||
} |
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,81 @@ | ||
class NodeStats extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.initialize(props); | ||
} | ||
|
||
initialize(props) { | ||
const { stats } = props; | ||
const { memory, cpu } = (stats || {}); | ||
|
||
this.memory = memory ? new MemoryStats(memory) : null; | ||
this.cpu = cpu ? new CPUStats(cpu) : null; | ||
} | ||
|
||
progress(options) { | ||
const { percent, level, label, className } = options; | ||
|
||
return ( | ||
<div className={'progress position-relative ' + className} | ||
style={{ height: '2em' }}> | ||
<div className={'progress-bar bg-' + level} | ||
style={{ width: percent }}> | ||
<span className={'label'}> | ||
{label} | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
renderMemory() { | ||
if (!this.memory) return null; | ||
|
||
return this.progress({ | ||
percent: this.memory.percent(), | ||
label: this.memory.label(), | ||
level: this.memory.level(), | ||
className: 'memory' | ||
}); | ||
} | ||
|
||
renderCPU() { | ||
if (!this.cpu) return null; | ||
|
||
return this.progress({ | ||
percent: this.cpu.percent(), | ||
label: this.cpu.label(), | ||
level: this.cpu.level(), | ||
className: 'cpu' | ||
}); | ||
} | ||
|
||
render() { | ||
this.initialize(this.props); | ||
|
||
return ( | ||
<div className={'node-stats'}> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<th> | ||
{'RAM'} | ||
</th> | ||
<td> | ||
{this.renderMemory()} | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
{'CPU'} | ||
</th> | ||
<td> | ||
{this.renderCPU()} | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
} | ||
} |
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
Oops, something went wrong.