1 import { Component } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import * as _ from 'lodash';
6 import { MonitorService } from '../../../shared/api/monitor.service';
7 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
10 selector: 'cd-monitor',
11 templateUrl: './monitor.component.html',
12 styleUrls: ['./monitor.component.scss']
14 export class MonitorComponent {
21 constructor(private monitorService: MonitorService, private i18n: I18n) {
24 { prop: 'name', name: this.i18n('Name'), cellTransformation: CellTemplate.routerLink },
25 { prop: 'rank', name: this.i18n('Rank') },
26 { prop: 'public_addr', name: this.i18n('Public Address') },
28 prop: 'cdOpenSessions',
29 name: this.i18n('Open Sessions'),
30 cellTransformation: CellTemplate.sparkline,
31 comparator: (dataA: any, dataB: any) => {
32 // We get the last value of time series to compare:
33 const lastValueA = _.last(dataA);
34 const lastValueB = _.last(dataB);
36 if (!lastValueA || !lastValueB || lastValueA === lastValueB) {
40 return lastValueA > lastValueB ? 1 : -1;
49 { prop: 'name', name: this.i18n('Name'), cellTransformation: CellTemplate.routerLink },
50 { prop: 'rank', name: this.i18n('Rank') },
51 { prop: 'public_addr', name: this.i18n('Public Address') }
58 this.monitorService.getMonitor().subscribe((data: any) => {
59 data.in_quorum.map((row: any) => {
60 row.cdOpenSessions = row.stats.num_sessions.map((i: string) => i[1]);
61 row.cdLink = '/perf_counters/mon/' + row.name;
62 row.cdParams = { fromLink: '/monitor' };
66 data.out_quorum.map((row: any) => {
67 row.cdLink = '/perf_counters/mon/' + row.name;
68 row.cdParams = { fromLink: '/monitor' };
72 this.inQuorum.data = [...data.in_quorum];
73 this.notInQuorum.data = [...data.out_quorum];
74 this.mon_status = data.mon_status;