]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/shared/smart-list/smart-list.component.ts
import ceph quincy 17.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / shared / smart-list / smart-list.component.ts
CommitLineData
f91f0fd5 1import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
9f95a23c 2
f67539c2
TL
3import { NgbNav } from '@ng-bootstrap/ng-bootstrap';
4import _ from 'lodash';
9f95a23c 5
f67539c2
TL
6import { HostService } from '~/app/shared/api/host.service';
7import { OsdService } from '~/app/shared/api/osd.service';
8import { CdTableColumn } from '~/app/shared/models/cd-table-column';
9f95a23c 9import {
33c7a0ef
TL
10 AtaSmartDataV1,
11 IscsiSmartDataV1,
9f95a23c
TL
12 NvmeSmartDataV1,
13 SmartDataResult,
14 SmartError,
15 SmartErrorResult
f67539c2 16} from '~/app/shared/models/smart';
9f95a23c
TL
17
18@Component({
19 selector: 'cd-smart-list',
20 templateUrl: './smart-list.component.html',
21 styleUrls: ['./smart-list.component.scss']
22})
23export class SmartListComponent implements OnInit, OnChanges {
f67539c2
TL
24 @ViewChild('innerNav')
25 nav: NgbNav;
f91f0fd5 26
9f95a23c
TL
27 @Input()
28 osdId: number = null;
29 @Input()
30 hostname: string = null;
31
32 loading = false;
33 incompatible = false;
34 error = false;
35
36 data: { [deviceId: string]: SmartDataResult | SmartErrorResult } = {};
37
38 smartDataColumns: CdTableColumn[];
33c7a0ef 39 scsiSmartDataColumns: CdTableColumn[];
9f95a23c 40
f91f0fd5
TL
41 isEmpty = _.isEmpty;
42
f67539c2 43 constructor(private osdService: OsdService, private hostService: HostService) {}
9f95a23c
TL
44
45 isSmartError(data: any): data is SmartError {
46 return _.get(data, 'error') !== undefined;
47 }
48
49 isNvmeSmartData(data: any): data is NvmeSmartDataV1 {
50 return _.get(data, 'device.protocol', '').toLowerCase() === 'nvme';
51 }
52
33c7a0ef 53 isAtaSmartData(data: any): data is AtaSmartDataV1 {
9f95a23c
TL
54 return _.get(data, 'device.protocol', '').toLowerCase() === 'ata';
55 }
56
33c7a0ef
TL
57 isIscsiSmartData(data: any): data is IscsiSmartDataV1 {
58 return _.get(data, 'device.protocol', '').toLowerCase() === 'scsi';
59 }
60
9f95a23c
TL
61 private fetchData(data: any) {
62 const result: { [deviceId: string]: SmartDataResult | SmartErrorResult } = {};
63 _.each(data, (smartData, deviceId) => {
64 if (this.isSmartError(smartData)) {
65 let userMessage = '';
66 if (smartData.smartctl_error_code === -22) {
f67539c2
TL
67 userMessage = $localize`Smartctl has received an unknown argument \
68(error code ${smartData.smartctl_error_code}). \
e306af50 69You may be using an incompatible version of smartmontools. Version >= 7.0 of \
f67539c2 70smartmontools is required to successfully retrieve data.`;
9f95a23c 71 } else {
f67539c2 72 userMessage = $localize`An error with error code ${smartData.smartctl_error_code} occurred.`;
9f95a23c
TL
73 }
74 const _result: SmartErrorResult = {
75 error: smartData.error,
76 smartctl_error_code: smartData.smartctl_error_code,
77 smartctl_output: smartData.smartctl_output,
78 userMessage: userMessage,
79 device: smartData.dev,
80 identifier: smartData.nvme_vendor
81 };
82 result[deviceId] = _result;
83 return;
84 }
9f95a23c
TL
85 // Prepare S.M.A.R.T data
86 if (smartData.json_format_version[0] === 1) {
87 // Version 1.x
33c7a0ef
TL
88 if (this.isAtaSmartData(smartData)) {
89 result[deviceId] = this.extractAtaData(smartData);
90 } else if (this.isIscsiSmartData(smartData)) {
91 result[deviceId] = this.extractIscsiData(smartData);
9f95a23c
TL
92 } else if (this.isNvmeSmartData(smartData)) {
93 result[deviceId] = this.extractNvmeData(smartData);
94 }
95 return;
96 } else {
97 this.incompatible = true;
98 }
99 });
100 this.data = result;
101 this.loading = false;
102 }
103
104 private extractNvmeData(smartData: NvmeSmartDataV1): SmartDataResult {
33c7a0ef 105 const info = _.omitBy(smartData, (_value: string, key: string) =>
9f95a23c
TL
106 ['nvme_smart_health_information_log'].includes(key)
107 );
108 return {
109 info: info,
110 smart: {
111 nvmeData: smartData.nvme_smart_health_information_log
112 },
113 device: smartData.device.name,
114 identifier: smartData.serial_number
115 };
116 }
117
33c7a0ef
TL
118 private extractIscsiData(smartData: IscsiSmartDataV1): SmartDataResult {
119 const info = _.omitBy(smartData, (_value: string, key: string) =>
120 ['scsi_error_counter_log', 'scsi_grown_defect_list'].includes(key)
121 );
122 return {
123 info: info,
124 smart: {
125 scsi_error_counter_log: smartData.scsi_error_counter_log,
126 scsi_grown_defect_list: smartData.scsi_grown_defect_list
127 },
128 device: info.device.name,
129 identifier: info.serial_number
130 };
131 }
132
133 private extractAtaData(smartData: AtaSmartDataV1): SmartDataResult {
134 const info = _.omitBy(smartData, (_value: string, key: string) =>
9f95a23c
TL
135 ['ata_smart_attributes', 'ata_smart_selective_self_test_log', 'ata_smart_data'].includes(key)
136 );
137 return {
138 info: info,
139 smart: {
140 attributes: smartData.ata_smart_attributes,
141 data: smartData.ata_smart_data
142 },
143 device: info.device.name,
144 identifier: info.serial_number
145 };
146 }
147
148 private updateData() {
149 this.loading = true;
150
151 if (this.osdId !== null) {
f67539c2
TL
152 this.osdService.getSmartData(this.osdId).subscribe({
153 next: this.fetchData.bind(this),
154 error: (error) => {
155 error.preventDefault();
156 this.error = error;
157 this.loading = false;
158 }
9f95a23c
TL
159 });
160 } else if (this.hostname !== null) {
f67539c2
TL
161 this.hostService.getSmartData(this.hostname).subscribe({
162 next: this.fetchData.bind(this),
163 error: (error) => {
164 error.preventDefault();
165 this.error = error;
166 this.loading = false;
167 }
9f95a23c
TL
168 });
169 }
170 }
171
172 ngOnInit() {
173 this.smartDataColumns = [
f67539c2
TL
174 { prop: 'id', name: $localize`ID` },
175 { prop: 'name', name: $localize`Name` },
176 { prop: 'raw.value', name: $localize`Raw` },
177 { prop: 'thresh', name: $localize`Threshold` },
178 { prop: 'value', name: $localize`Value` },
179 { prop: 'when_failed', name: $localize`When Failed` },
180 { prop: 'worst', name: $localize`Worst` }
9f95a23c 181 ];
33c7a0ef
TL
182
183 this.scsiSmartDataColumns = [
184 {
185 prop: 'correction_algorithm_invocations',
186 name: $localize`Correction Algorithm Invocations`
187 },
188 {
189 prop: 'errors_corrected_by_eccdelayed',
190 name: $localize`Errors Corrected by ECC (Delayed)`
191 },
192 { prop: 'errors_corrected_by_eccfast', name: $localize`Errors Corrected by ECC (Fast)` },
193 {
194 prop: 'errors_corrected_by_rereads_rewrites',
195 name: $localize`Errors Corrected by Rereads/Rewrites`
196 },
197 { prop: 'gigabytes_processed', name: $localize`Gigabyes Processed` },
198 { prop: 'total_errors_corrected', name: $localize`Total Errors Corrected` },
199 { prop: 'total_uncorrected_errors', name: $localize`Total Errors Uncorrected` }
200 ];
9f95a23c
TL
201 }
202
203 ngOnChanges(changes: SimpleChanges): void {
204 this.data = {}; // Clear previous data
205 if (changes.osdId) {
206 this.osdId = changes.osdId.currentValue;
207 } else if (changes.hostname) {
208 this.hostname = changes.hostname.currentValue;
209 }
210 this.updateData();
211 }
212}