]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
e2e0194de84a06e39fba4de1edc946f5846e4005
[ceph-ci.git] /
1 import { Component, Input, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
3 import { PerformanceCounterService } from '~/app/shared/api/performance-counter.service';
4 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
5 import { CdTableFetchDataContext } from '~/app/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: $localize`Name`,
40         prop: 'name',
41         flexGrow: 1
42       },
43       {
44         name: $localize`Description`,
45         prop: 'description',
46         flexGrow: 1
47       },
48       {
49         name: $localize`Value`,
50         prop: 'value',
51         cellTemplate: this.valueTpl,
52         flexGrow: 1
53       }
54     ];
55   }
56
57   getCounters(context: CdTableFetchDataContext) {
58     this.performanceCounterService.get(this.serviceType, this.serviceId).subscribe(
59       (resp: object[]) => {
60         this.counters = resp;
61       },
62       (error) => {
63         if (error.status === 404) {
64           error.preventDefault();
65           this.counters = null;
66         } else {
67           context.error();
68         }
69       }
70     );
71   }
72 }