]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/monitor/monitor.component.ts
c9a95592224abb002f06632e18aba59d9fb0f1cc
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / monitor / monitor.component.ts
1 import { Component } from '@angular/core';
2
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import * as _ from 'lodash';
5
6 import { MonitorService } from '../../../shared/api/monitor.service';
7 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
8
9 @Component({
10 selector: 'cd-monitor',
11 templateUrl: './monitor.component.html',
12 styleUrls: ['./monitor.component.scss']
13 })
14 export class MonitorComponent {
15 mon_status: any;
16 inQuorum: any;
17 notInQuorum: any;
18
19 interval: any;
20
21 constructor(private monitorService: MonitorService, private i18n: I18n) {
22 this.inQuorum = {
23 columns: [
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') },
27 {
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);
35
36 if (!lastValueA || !lastValueB || lastValueA === lastValueB) {
37 return 0;
38 }
39
40 return lastValueA > lastValueB ? 1 : -1;
41 }
42 }
43 ],
44 data: []
45 };
46
47 this.notInQuorum = {
48 columns: [
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') }
52 ],
53 data: []
54 };
55 }
56
57 refresh() {
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' };
63 return row;
64 });
65
66 data.out_quorum.map((row: any) => {
67 row.cdLink = '/perf_counters/mon/' + row.name;
68 row.cdParams = { fromLink: '/monitor' };
69 return row;
70 });
71
72 this.inQuorum.data = [...data.in_quorum];
73 this.notInQuorum.data = [...data.out_quorum];
74 this.mon_status = data.mon_status;
75 });
76 }
77 }