]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
5b9aa29cffec313a05a98c7f745f0cf0daf0da37
[ceph.git] /
1 import { Component, Input, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
3 import { PerformanceCounterService } from '../../../shared/api/performance-counter.service';
4 import { CdTableColumn } from '../../../shared/models/cd-table-column';
5
6 /**
7  * Display the specified performance counters in a datatable.
8  */
9 @Component({
10   selector: 'cd-table-performance-counter',
11   templateUrl: './table-performance-counter.component.html',
12   styleUrls: ['./table-performance-counter.component.scss']
13 })
14 export class TablePerformanceCounterComponent implements OnInit {
15   columns: Array<CdTableColumn> = [];
16   counters: Array<object> = [];
17
18   @ViewChild('valueTpl')
19   public valueTpl: TemplateRef<any>;
20
21   /**
22    * The service type, e.g. 'rgw', 'mds', 'mon', 'osd', ...
23    */
24   @Input()
25   serviceType: string;
26
27   /**
28    * The service identifier.
29    */
30   @Input()
31   serviceId: string;
32
33   constructor(private performanceCounterService: PerformanceCounterService) {}
34
35   ngOnInit() {
36     this.columns = [
37       {
38         name: 'Name',
39         prop: 'name',
40         flexGrow: 1
41       },
42       {
43         name: 'Description',
44         prop: 'description',
45         flexGrow: 1
46       },
47       {
48         name: 'Value',
49         cellTemplate: this.valueTpl,
50         flexGrow: 1
51       }
52     ];
53   }
54
55   getCounters() {
56     this.performanceCounterService.get(this.serviceType, this.serviceId).subscribe(
57       (resp: object[]) => {
58         this.counters = resp;
59       },
60       (error) => {
61         if (error.status === 404) {
62           error.preventDefault();
63           this.counters = null;
64         }
65       }
66     );
67   }
68 }