1 import { Component, OnDestroy, OnInit } from '@angular/core';
3 import _ from 'lodash';
4 import { Observable, Subscription, timer } from 'rxjs';
5 import { take } from 'rxjs/operators';
6 import moment from 'moment';
8 import { HealthService } from '~/app/shared/api/health.service';
9 import { OsdService } from '~/app/shared/api/osd.service';
10 import { PrometheusService } from '~/app/shared/api/prometheus.service';
11 import { Promqls as queries } from '~/app/shared/enum/dashboard-promqls.enum';
12 import { Icons } from '~/app/shared/enum/icons.enum';
13 import { DashboardDetails } from '~/app/shared/models/cd-details';
14 import { Permissions } from '~/app/shared/models/permissions';
15 import { AlertmanagerAlert } from '~/app/shared/models/prometheus-alerts';
16 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
20 } from '~/app/shared/services/feature-toggles.service';
21 import { RefreshIntervalService } from '~/app/shared/services/refresh-interval.service';
22 import { SummaryService } from '~/app/shared/services/summary.service';
23 import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
24 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
25 import { OrchestratorService } from '~/app/shared/api/orchestrator.service';
28 selector: 'cd-dashboard-v3',
29 templateUrl: './dashboard-v3.component.html',
30 styleUrls: ['./dashboard-v3.component.scss']
32 export class DashboardV3Component extends PrometheusListHelper implements OnInit, OnDestroy {
33 detailsCardData: DashboardDetails = {};
34 osdSettingsService: any;
36 interval = new Subscription();
37 permissions: Permissions;
38 enabledFeature$: FeatureTogglesMap$;
42 healthData$: Observable<Object>;
43 prometheusAlerts$: Observable<AlertmanagerAlert[]>;
54 alerts: AlertmanagerAlert[];
56 categoryPgAmount: Record<string, number> = {};
58 queriesResults: any = {
64 READCLIENTTHROUGHPUT: '',
65 WRITECLIENTTHROUGHPUT: '',
68 timerGetPrometheusDataSub: Subscription;
70 readonly lastHourDateObject = {
71 start: moment().unix() - 3600,
77 private summaryService: SummaryService,
78 private orchestratorService: OrchestratorService,
79 private osdService: OsdService,
80 private authStorageService: AuthStorageService,
81 private featureToggles: FeatureTogglesService,
82 private healthService: HealthService,
83 public prometheusService: PrometheusService,
84 private refreshIntervalService: RefreshIntervalService,
85 public prometheusAlertService: PrometheusAlertService
87 super(prometheusService);
88 this.permissions = this.authStorageService.getPermissions();
89 this.enabledFeature$ = this.featureToggles.get();
94 this.interval = this.refreshIntervalService.intervalData$.subscribe(() => {
96 this.getCapacityCardData();
98 this.getPrometheusData(this.lastHourDateObject);
99 this.getDetailsCardData();
103 this.interval.unsubscribe();
104 if (this.timerGetPrometheusDataSub) {
105 this.timerGetPrometheusDataSub.unsubscribe();
110 this.healthService.getMinimalHealth().subscribe((data: any) => {
111 this.healthData = data;
115 toggleAlertsWindow(type: string, isToggleButton: boolean = false) {
116 this.triggerPrometheusAlerts();
117 if (isToggleButton) {
118 this.showAlerts = !this.showAlerts;
119 this.flexHeight = !this.flexHeight;
122 (this.alertType === type && type !== 'danger') ||
123 (this.alertType !== 'warning' && type === 'danger')
125 this.showAlerts = !this.showAlerts;
126 this.flexHeight = !this.flexHeight;
129 type === 'danger' ? (this.alertType = 'critical') : (this.alertType = type);
130 this.textClass = `text-${type}`;
131 this.borderClass = `border-${type}`;
134 getDetailsCardData() {
135 this.healthService.getClusterFsid().subscribe((data: string) => {
136 this.detailsCardData.fsid = data;
138 this.orchestratorService.getName().subscribe((data: string) => {
139 this.detailsCardData.orchestrator = data;
141 this.summaryService.subscribe((summary) => {
142 const version = summary.version.replace('ceph version ', '').split(' ');
143 this.detailsCardData.cephVersion =
144 version[0] + ' ' + version.slice(2, version.length).join(' ');
148 getCapacityCardData() {
149 this.osdSettingsService = this.osdService
152 .subscribe((data: any) => {
153 this.osdSettings = data;
155 this.capacityService = this.healthService.getClusterCapacity().subscribe((data: any) => {
156 this.capacity = data;
160 triggerPrometheusAlerts() {
161 this.prometheusService.ifAlertmanagerConfigured(() => {
162 this.prometheusService.getAlerts().subscribe((alerts) => {
163 this.alerts = alerts;
168 getPrometheusData(selectedTime: any) {
169 this.prometheusService.ifPrometheusConfigured(() => {
170 if (this.timerGetPrometheusDataSub) {
171 this.timerGetPrometheusDataSub.unsubscribe();
173 this.timerGetPrometheusDataSub = timer(0, this.timerTime).subscribe(() => {
174 selectedTime = this.updateTimeStamp(selectedTime);
176 for (const queryName in queries) {
177 if (queries.hasOwnProperty(queryName)) {
178 const query = queries[queryName];
179 let interval = selectedTime.step;
181 if (query.includes('rate') && selectedTime.step < 20) {
183 } else if (query.includes('rate')) {
184 interval = selectedTime.step * 2;
187 const intervalAdjustedQuery = query.replace(/\[(.*?)\]/g, `[${interval}s]`);
189 this.prometheusService
191 params: intervalAdjustedQuery,
192 start: selectedTime['start'],
193 end: selectedTime['end'],
194 step: selectedTime['step']
196 .subscribe((data: any) => {
197 if (data.result.length) {
198 this.queriesResults[queryName] = data.result[0].values;
207 private updateTimeStamp(selectedTime: any): any {
208 let formattedDate = {};
209 const date: number = selectedTime['start'] + this.timerTime / 1000;
210 const dateNow: number = selectedTime['end'] + this.timerTime / 1000;
214 step: selectedTime['step']
216 return formattedDate;