]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
b8c4774bec17f7500cc5541ac266a44178d17b62
[ceph-ci.git] /
1 import { Component, OnDestroy, OnInit } from '@angular/core';
2
3 import _ from 'lodash';
4 import { Observable, ReplaySubject, Subscription } from 'rxjs';
5
6 import { Permissions } from '~/app/shared/models/permissions';
7 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
8 import { RefreshIntervalService } from '~/app/shared/services/refresh-interval.service';
9 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
10 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
11 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
12 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
13 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
14 import { RgwUserService } from '~/app/shared/api/rgw-user.service';
15 import { PrometheusService } from '~/app/shared/api/prometheus.service';
16
17 import { RgwPromqls as queries } from '~/app/shared/enum/dashboard-promqls.enum';
18 import { HealthService } from '~/app/shared/api/health.service';
19 import { Icons } from '~/app/shared/enum/icons.enum';
20 import { RgwMultisiteService } from '~/app/shared/api/rgw-multisite.service';
21 import { shareReplay, switchMap, tap } from 'rxjs/operators';
22 import { RgwZonegroup } from '../models/rgw-multisite';
23
24 @Component({
25   selector: 'cd-rgw-overview-dashboard',
26   templateUrl: './rgw-overview-dashboard.component.html',
27   styleUrls: ['./rgw-overview-dashboard.component.scss']
28 })
29 export class RgwOverviewDashboardComponent implements OnInit, OnDestroy {
30   icons = Icons;
31
32   interval = new Subscription();
33   permissions: Permissions;
34   rgwDaemonCount = 0;
35   rgwRealmCount = 0;
36   rgwZonegroupCount = 0;
37   rgwZoneCount = 0;
38   rgwBucketCount = 0;
39   objectCount = 0;
40   UserCount = 0;
41   totalPoolUsedBytes = 0;
42   averageObjectSize = 0;
43   realmData: any;
44   daemonSub: Subscription;
45   realmSub: Subscription;
46   multisiteInfo: object[] = [];
47   ZonegroupSub: Subscription;
48   ZoneSUb: Subscription;
49   UserSub: Subscription;
50   HealthSub: Subscription;
51   BucketSub: Subscription;
52   queriesResults: any = {
53     RGW_REQUEST_PER_SECOND: '',
54     BANDWIDTH: '',
55     AVG_GET_LATENCY: '',
56     AVG_PUT_LATENCY: ''
57   };
58   timerGetPrometheusDataSub: Subscription;
59   chartTitles = ['Metadata Sync', 'Data Sync'];
60   realm: string;
61   zonegroup: string;
62   zone: string;
63   metadataSyncInfo: string;
64   replicaZonesInfo: any = [];
65   metadataSyncData: {};
66   showMultisiteCard = true;
67   loading = true;
68   multisiteSyncStatus$: Observable<any>;
69   subject = new ReplaySubject<any>();
70   syncCardLoading = true;
71
72   constructor(
73     private authStorageService: AuthStorageService,
74     private healthService: HealthService,
75     private refreshIntervalService: RefreshIntervalService,
76     private rgwDaemonService: RgwDaemonService,
77     private rgwRealmService: RgwRealmService,
78     private rgwZonegroupService: RgwZonegroupService,
79     private rgwZoneService: RgwZoneService,
80     private rgwBucketService: RgwBucketService,
81     private rgwUserService: RgwUserService,
82     private prometheusService: PrometheusService,
83     private rgwMultisiteService: RgwMultisiteService
84   ) {
85     this.permissions = this.authStorageService.getPermissions();
86   }
87
88   ngOnInit() {
89     this.interval = this.refreshIntervalService.intervalData$.subscribe(() => {
90       this.daemonSub = this.rgwDaemonService.list().subscribe((data: any) => {
91         this.rgwDaemonCount = data.length;
92       });
93       this.BucketSub = this.rgwBucketService.list().subscribe((data: any) => {
94         this.rgwBucketCount = data.length;
95       });
96       this.UserSub = this.rgwUserService.list().subscribe((data: any) => {
97         this.UserCount = data.length;
98       });
99       this.HealthSub = this.healthService.getClusterCapacity().subscribe((data: any) => {
100         this.objectCount = data['total_objects'];
101         this.totalPoolUsedBytes = data['total_pool_bytes_used'];
102         this.averageObjectSize = data['average_object_size'];
103       });
104       this.getSyncStatus();
105     });
106     this.realmSub = this.rgwRealmService.list().subscribe((data: any) => {
107       this.rgwRealmCount = data['realms'].length;
108     });
109     this.ZonegroupSub = this.rgwZonegroupService.list().subscribe((data: any) => {
110       this.rgwZonegroupCount = data['zonegroups'].length;
111     });
112     this.ZoneSUb = this.rgwZoneService.list().subscribe((data: any) => {
113       this.rgwZoneCount = data['zones'].length;
114     });
115     this.getPrometheusData(this.prometheusService.lastHourDateObject);
116     this.multisiteSyncStatus$ = this.subject.pipe(
117       switchMap(() =>
118         this.rgwMultisiteService.getSyncStatus().pipe(
119           tap((data: any) => {
120             this.loading = false;
121             this.replicaZonesInfo = data['dataSyncInfo'];
122             this.metadataSyncInfo = data['metadataSyncInfo'];
123             [this.realm, this.zonegroup, this.zone] = data['primaryZoneData'];
124           })
125         )
126       ),
127       tap(() => {
128         const zonegroup = new RgwZonegroup();
129         zonegroup.name = this.zonegroup;
130         this.rgwZonegroupService.get(zonegroup).subscribe((data: any) => {
131           this.showMultisiteCard = data['zones'].length !== 1;
132           this.syncCardLoading = false;
133         });
134       }),
135       shareReplay(1)
136     );
137   }
138
139   ngOnDestroy() {
140     this.interval.unsubscribe();
141     this.daemonSub.unsubscribe();
142     this.realmSub.unsubscribe();
143     this.ZonegroupSub.unsubscribe();
144     this.ZoneSUb.unsubscribe();
145     this.BucketSub.unsubscribe();
146     this.UserSub.unsubscribe();
147     this.HealthSub.unsubscribe();
148     if (this.timerGetPrometheusDataSub) {
149       this.timerGetPrometheusDataSub.unsubscribe();
150     }
151   }
152
153   getPrometheusData(selectedTime: any) {
154     this.queriesResults = this.prometheusService.getPrometheusQueriesData(
155       selectedTime,
156       queries,
157       this.queriesResults,
158       true
159     );
160   }
161
162   getSyncStatus() {
163     this.subject.next();
164   }
165
166   trackByFn(zone: any) {
167     return zone;
168   }
169 }