Skip to content

Commit

Permalink
feat(core-memstats-flow): implememt memory card
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed Jun 2, 2020
1 parent 3abc83b commit fa96913
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
40 changes: 40 additions & 0 deletions src/app/@dataflow/rclone/core-memstats-flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { AjaxFlowInteralNode, CombErr } from '../core';
import { IRcloneServer } from '../extra';
import { PostFlow } from './post-flow';

export interface CoreMemstatsFlowOutNode {
'mem-stats': {
Alloc: number;
BuckHashSys: number;
Frees: number;
GCSys: number;
HeapAlloc: number;
HeapIdle: number;
HeapInuse: number;
HeapObjects: number;
HeapReleased: number;
HeapSys: number;
MCacheInuse: number;
MCacheSys: number;
MSpanInuse: number;
MSpanSys: number;
Mallocs: number;
OtherSys: number;
StackInuse: number;
StackSys: number;
Sys: number;
TotalAlloc: number;
};
}

export abstract class CoreMemstatsFlow extends PostFlow<IRcloneServer, CoreMemstatsFlowOutNode> {
// public prerequest$: Observable<CombErr<IRcloneServer>>;
protected cmd = 'core/memstats';
protected params = {};
protected cacheSupport = true;
protected reconstructAjaxResult(x: AjaxFlowInteralNode): CombErr<CoreMemstatsFlowOutNode> {
if (x[1].length !== 0) return [{}, x[1]] as any;
const rsp = x[0].ajaxRsp.response;
return [{ 'mem-stats': rsp }, []];
}
}
1 change: 1 addition & 0 deletions src/app/@dataflow/rclone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './operations-deletefile-flow';
export * from './sync-copy-flow';
export * from './sync-move-flow';
export * from './operations-purge-flow';
export * from './core-memstats-flow';
52 changes: 49 additions & 3 deletions src/app/pages/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { combineLatest } from 'rxjs';
import { combineLatest, Subject } from 'rxjs';
import { map, takeWhile } from 'rxjs/operators';
import { CombErr } from '../../@dataflow/core';
import { CoreStatsFlow, CoreStatsFlowInNode } from '../../@dataflow/rclone';
import { CoreMemstatsFlow, CoreStatsFlow, CoreStatsFlowInNode } from '../../@dataflow/rclone';
import { FormatBytes } from '../../utils/format-bytes';
import { ConnectionService } from '../connection.service';

@Component({
Expand Down Expand Up @@ -65,7 +66,7 @@ import { ConnectionService } from '../connection.service';
<app-rng-summary [stats$]="stats$"> </app-rng-summary>
</nb-tab>
<nb-tab tabTitle="Memory">
Memory stats
<app-rng-kv-table [keys]="memKeys" [data]="memVals"> </app-rng-kv-table>
</nb-tab>
<nb-tab tabTitle="Cache">
Cache stats
Expand Down Expand Up @@ -101,6 +102,33 @@ export class DashboardComponent implements OnInit, OnDestroy {

private visable = false;

memKeys = [
{ key: 'Alloc' },
{ key: 'BuckHashSys' },
{ key: 'Frees' },
{ key: 'GCSys' },
{ key: 'HeapAlloc' },
{ key: 'HeapIdle' },
{ key: 'HeapInuse' },
{ key: 'HeapObjects' },
{ key: 'HeapReleased' },
{ key: 'HeapSys' },
{ key: 'MCacheInuse' },
{ key: 'MCacheSys' },
{ key: 'MSpanInuse' },
{ key: 'MSpanSys' },
{ key: 'Mallocs' },
{ key: 'OtherSys' },
{ key: 'StackInuse' },
{ key: 'StackSys' },
{ key: 'Sys' },
{ key: 'TotalAlloc' },
];
memVals = {};

private memTrigger = new Subject<number>();
mem$: CoreMemstatsFlow;

ngOnInit(): void {
const outer = this;
this.visable = true;
Expand All @@ -114,6 +142,24 @@ export class DashboardComponent implements OnInit, OnDestroy {
);
})();
this.stats$.deploy();

this.mem$ = new (class extends CoreMemstatsFlow {
public prerequest$ = combineLatest([
outer.memTrigger,
outer.cmdService.listCmd$.verify(this.cmd),
]).pipe(map(x => x[1]));
})();
this.mem$.deploy();
this.mem$.getOutput().subscribe(x => {
if (x[1].length !== 0) return;
this.memVals = { ...x[0]['mem-stats'] };
for (const key in this.memVals) {
if (this.memVals.hasOwnProperty(key)) {
this.memVals[key] = FormatBytes(this.memVals[key], 3);
}
}
});
this.memTrigger.next(1);
}
ngOnDestroy() {
this.visable = false;
Expand Down

0 comments on commit fa96913

Please sign in to comment.