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