1 import { Component } from '@angular/core';
3 import _ from 'lodash';
5 import { MonitorService } from '~/app/shared/api/monitor.service';
6 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
9 selector: 'cd-monitor',
10 templateUrl: './monitor.component.html',
11 styleUrls: ['./monitor.component.scss']
13 export class MonitorComponent {
20 constructor(private monitorService: MonitorService) {
23 { prop: 'name', name: $localize`Name`, cellTransformation: CellTemplate.routerLink },
24 { prop: 'rank', name: $localize`Rank` },
25 { prop: 'public_addr', name: $localize`Public Address` },
27 prop: 'cdOpenSessions',
28 name: $localize`Open Sessions`,
29 cellTransformation: CellTemplate.sparkline,
30 comparator: (dataA: any, dataB: any) => {
31 // We get the last value of time series to compare:
32 const lastValueA = _.last(dataA);
33 const lastValueB = _.last(dataB);
35 if (!lastValueA || !lastValueB || lastValueA === lastValueB) {
39 return lastValueA > lastValueB ? 1 : -1;
47 { prop: 'name', name: $localize`Name`, cellTransformation: CellTemplate.routerLink },
48 { prop: 'rank', name: $localize`Rank` },
49 { prop: 'public_addr', name: $localize`Public Address` }
55 this.monitorService.getMonitor().subscribe((data: any) => {
56 data.in_quorum.map((row: any) => {
57 row.cdOpenSessions = row.stats.num_sessions.map((i: string) => i[1]);
58 row.cdLink = '/perf_counters/mon/' + row.name;
59 row.cdParams = { fromLink: '/monitor' };
63 data.out_quorum.map((row: any) => {
64 row.cdLink = '/perf_counters/mon/' + row.name;
65 row.cdParams = { fromLink: '/monitor' };
69 this.inQuorum.data = [...data.in_quorum];
70 this.notInQuorum.data = [...data.out_quorum];
71 this.mon_status = data.mon_status;