1 import { Component, OnDestroy, OnInit } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import * as _ from 'lodash';
5 import { Subscription } from 'rxjs/Subscription';
7 import { HealthService } from '../../../shared/api/health.service';
8 import { Permissions } from '../../../shared/models/permissions';
9 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
13 } from '../../../shared/services/feature-toggles.service';
14 import { RefreshIntervalService } from '../../../shared/services/refresh-interval.service';
15 import { PgCategoryService } from '../../shared/pg-category.service';
16 import { HealthPieColor } from '../health-pie/health-pie-color.enum';
19 selector: 'cd-health',
20 templateUrl: './health.component.html',
21 styleUrls: ['./health.component.scss']
23 export class HealthComponent implements OnInit, OnDestroy {
25 interval = new Subscription();
26 permissions: Permissions;
27 enabledFeature$: FeatureTogglesMap$;
30 private healthService: HealthService,
32 private authStorageService: AuthStorageService,
33 private pgCategoryService: PgCategoryService,
34 private featureToggles: FeatureTogglesService,
35 private refreshIntervalService: RefreshIntervalService
37 this.permissions = this.authStorageService.getPermissions();
38 this.enabledFeature$ = this.featureToggles.get();
43 this.interval = this.refreshIntervalService.intervalData$.subscribe(() => {
49 this.interval.unsubscribe();
53 this.healthService.getMinimalHealth().subscribe((data: any) => {
54 this.healthData = data;
58 prepareReadWriteRatio(chart) {
59 const ratioLabels = [];
62 ratioLabels.push(this.i18n('Writes'));
63 ratioData.push(this.healthData.client_perf.write_op_per_sec);
64 ratioLabels.push(this.i18n('Reads'));
65 ratioData.push(this.healthData.client_perf.read_op_per_sec);
67 chart.dataset[0].data = ratioData;
68 chart.labels = ratioLabels;
71 prepareRawUsage(chart, data) {
72 const percentAvailable = Math.round(
74 ((data.df.stats.total_bytes - data.df.stats.total_used_raw_bytes) /
75 data.df.stats.total_bytes)
78 const percentUsed = Math.round(
79 100 * (data.df.stats.total_used_raw_bytes / data.df.stats.total_bytes)
82 chart.dataset[0].data = [data.df.stats.total_used_raw_bytes, data.df.stats.total_avail_bytes];
83 if (chart === 'doughnut') {
84 chart.options.cutoutPercentage = 65;
87 `${this.i18n('Used')} (${percentUsed}%)`,
88 `${this.i18n('Avail.')} (${percentAvailable}%)`
92 preparePgStatus(chart, data) {
93 const categoryPgAmount = {};
103 HealthPieColor.DEFAULT_GREEN,
104 HealthPieColor.DEFAULT_BLUE,
105 HealthPieColor.DEFAULT_ORANGE,
106 HealthPieColor.DEFAULT_RED
111 _.forEach(data.pg_info.statuses, (pgAmount, pgStatesText) => {
112 const categoryType = this.pgCategoryService.getTypeByStates(pgStatesText);
114 if (_.isUndefined(categoryPgAmount[categoryType])) {
115 categoryPgAmount[categoryType] = 0;
117 categoryPgAmount[categoryType] += pgAmount;
120 chart.dataset[0].data = this.pgCategoryService
122 .map((categoryType) => categoryPgAmount[categoryType]);
125 isClientReadWriteChartShowable() {
126 const readOps = this.healthData.client_perf.read_op_per_sec || 0;
127 const writeOps = this.healthData.client_perf.write_op_per_sec || 0;
129 return readOps + writeOps > 0;