Skip to content

Commit

Permalink
feat(dashboard): cpu utilization by core
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Sep 15, 2017
1 parent 5307093 commit f6f54f0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/api/stats/cpu.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function cpu(): Observable<IOutput> {
.mergeMap(() => cpuLoad()) .mergeMap(() => cpuLoad())
.map((res: ICpuData) => { .map((res: ICpuData) => {
return { type: 'cpu', data: res }; return { type: 'cpu', data: res };
}); })
.share();
} }


function cpuLoad(): Promise<ICpuData> { function cpuLoad(): Promise<ICpuData> {
Expand Down
3 changes: 2 additions & 1 deletion src/api/stats/memory.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function memory(): Observable<IOutput> {
.mergeMap(() => getMemory()) .mergeMap(() => getMemory())
.map((res: IMemoryData) => { .map((res: IMemoryData) => {
return { type: 'memory', data: res }; return { type: 'memory', data: res };
}); })
.share();
} }


function getMemory(): Promise<IMemoryData> { function getMemory(): Promise<IMemoryData> {
Expand Down
29 changes: 22 additions & 7 deletions src/app/components/app-dashboard/app-dashboard.component.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ <h1>Dashboard</h1>
</div> </div>
</div> </div>
<div class="column is-5"> <div class="column is-5">
<div class="content-box">
<div class="content-box-header">
<h2>CPU</h2>
<h3>Total CPU Usage</h3>
</div>
<app-progress-chart [percent]="cpuPercent"></app-progress-chart>
</div>
<div class="content-box"> <div class="content-box">
<div class="content-box-header"> <div class="content-box-header">
<h2>Memory</h2> <h2>Memory</h2>
Expand Down Expand Up @@ -65,6 +58,28 @@ <h3>Overall Memory Consumption</h3>
</span> </span>
</div> </div>
</div> </div>
<div class="content-box">
<div class="content-box-header">
<h2>CPU</h2>
<h3>Total CPU Usage</h3>
</div>
<app-progress-chart [percent]="cpuPercent"></app-progress-chart>
</div>
<div class="content-box" *ngIf="cpuCores?.length">
<div class="content-box-header">
<h2>CPU Cores</h2>
<h3>CPU Cores Utilization</h3>
</div>
<div class="info-data-container" *ngFor="let core of cpuCores; let i = index">
<span class="label-txt">Core {{ i }}</span>
<div class="data-progress-container green">
<span class="data-progress-bar" [style.width]="core + '%'"></span>
</div>
<span class="data-txt">
{{ core }}%
</span>
</div>
</div>
</div> </div>


</div> </div>
Expand Down
6 changes: 6 additions & 0 deletions src/app/components/app-dashboard/app-dashboard.component.ts
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit, OnDestroy } from '@angular/core'; import { Component, OnInit, OnDestroy } from '@angular/core';
import { StatsService } from '../../services/stats.service'; import { StatsService } from '../../services/stats.service';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { schemeCategory20b } from 'd3';


@Component({ @Component({
selector: 'app-dashboard', selector: 'app-dashboard',
Expand All @@ -9,20 +10,24 @@ import { Subscription } from 'rxjs/Subscription';
export class AppDashboardComponent implements OnInit, OnDestroy { export class AppDashboardComponent implements OnInit, OnDestroy {
loading: boolean; loading: boolean;
sub: Subscription; sub: Subscription;
colors: string[];
memory: { total: number, free: number, used: number }; memory: { total: number, free: number, used: number };
memoryHuman: { total: string, free: string, used: string }; memoryHuman: { total: string, free: string, used: string };
memoryPercentage: string; memoryPercentage: string;
runs: { success: {}, failed: {} }; runs: { success: {}, failed: {} };
cpuPercent: number; cpuPercent: number;
cpuCores: number[];


constructor(private statsService: StatsService) { constructor(private statsService: StatsService) {
this.loading = true; this.loading = true;


this.colors = schemeCategory20b;
this.memory = { total: null, free: null, used: null }; this.memory = { total: null, free: null, used: null };
this.memoryHuman = { total: null, free: null, used: null }; this.memoryHuman = { total: null, free: null, used: null };
this.memoryPercentage = '0'; this.memoryPercentage = '0';
this.runs = { success: {}, failed: {} }; this.runs = { success: {}, failed: {} };
this.cpuPercent = 0; this.cpuPercent = 0;
this.cpuCores = [];
} }


ngOnInit() { ngOnInit() {
Expand All @@ -45,6 +50,7 @@ export class AppDashboardComponent implements OnInit, OnDestroy {
this.memoryPercentage = Number(this.memory.used / this.memory.total * 100).toFixed(2); this.memoryPercentage = Number(this.memory.used / this.memory.total * 100).toFixed(2);
} else if (e.type === 'cpu') { } else if (e.type === 'cpu') {
this.cpuPercent = e.data.load; this.cpuPercent = e.data.load;
this.cpuCores = e.data.cores.map(core => core.total);
} }
}); });


Expand Down
5 changes: 5 additions & 0 deletions src/app/styles/dashboard.sass
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@


.label-txt .label-txt
color: $color color: $color
min-width: 50px
font-size: 13px
font-weight: $weight-semibold


.data-txt .data-txt
color: $color-secondary color: $color-secondary
min-width: 20px
text-align: center


.data-progress-container .data-progress-container
height: 4px height: 4px
Expand Down

0 comments on commit f6f54f0

Please sign in to comment.