]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/logs/logs.component.ts
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / logs / logs.component.ts
index cd20503c3a35bfc62a2fe901553161bb5d0609a0..ed8c721eaf3e1f6b3440d091c4c829dc01edf366 100644 (file)
@@ -1,6 +1,13 @@
-import { Component, OnDestroy, OnInit } from '@angular/core';
+import { DatePipe } from '@angular/common';
+import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
 
-import { LogsService } from '../../../shared/api/logs.service';
+import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
+
+import { CephServiceService } from '~/app/shared/api/ceph-service.service';
+import { LogsService } from '~/app/shared/api/logs.service';
+import { Icons } from '~/app/shared/enum/icons.enum';
 
 @Component({
   selector: 'cd-logs',
@@ -11,13 +18,15 @@ export class LogsComponent implements OnInit, OnDestroy {
   contentData: any;
   clog: Array<any>;
   audit_log: Array<any>;
+  icons = Icons;
+  clogText: string;
+  auditLogText: string;
+  lokiServiceStatus$: Observable<boolean>;
+  promtailServiceStatus$: Observable<boolean>;
 
   interval: number;
-  bsConfig = {
-    dateInputFormat: 'YYYY-MM-DD',
-    containerClass: 'theme-default'
-  };
-  prioritys: Array<{ name: string; value: string }> = [
+  priorities: Array<{ name: string; value: string }> = [
+    { name: 'Debug', value: '[DBG]' },
     { name: 'Info', value: '[INF]' },
     { name: 'Warning', value: '[WRN]' },
     { name: 'Error', value: '[ERR]' },
@@ -25,42 +34,69 @@ export class LogsComponent implements OnInit, OnDestroy {
   ];
   priority = 'All';
   search = '';
-  selectedDate: Date;
-  startTime: Date = new Date();
-  endTime: Date = new Date();
-  constructor(private logsService: LogsService) {
-    this.startTime.setHours(0, 0);
-    this.endTime.setHours(23, 59);
-  }
+  selectedDate: NgbDateStruct;
+  startTime = { hour: 0, minute: 0 };
+  endTime = { hour: 23, minute: 59 };
+  maxDate = {
+    year: new Date().getFullYear(),
+    month: new Date().getMonth() + 1,
+    day: new Date().getDate()
+  };
+
+  constructor(
+    private logsService: LogsService,
+    private cephService: CephServiceService,
+    private datePipe: DatePipe,
+    private ngZone: NgZone
+  ) {}
 
   ngOnInit() {
     this.getInfo();
-    this.interval = window.setInterval(() => {
-      this.getInfo();
-    }, 5000);
+    this.ngZone.runOutsideAngular(() => {
+      this.getDaemonDetails();
+      this.interval = window.setInterval(() => {
+        this.ngZone.run(() => {
+          this.getInfo();
+        });
+      }, 5000);
+    });
   }
 
   ngOnDestroy() {
     clearInterval(this.interval);
   }
 
+  getDaemonDetails() {
+    this.lokiServiceStatus$ = this.cephService.getDaemons('loki').pipe(
+      map((data: any) => {
+        return data.length > 0 && data[0].status === 1;
+      })
+    );
+    this.promtailServiceStatus$ = this.cephService.getDaemons('promtail').pipe(
+      map((data: any) => {
+        return data.length > 0 && data[0].status === 1;
+      })
+    );
+  }
+
   getInfo() {
     this.logsService.getLogs().subscribe((data: any) => {
       this.contentData = data;
+      this.clogText = this.logToText(this.contentData.clog);
+      this.auditLogText = this.logToText(this.contentData.audit_log);
       this.filterLogs();
     });
   }
 
-  abstractfilters(): any {
+  abstractFilters(): any {
     const priority = this.priority;
-    const key = this.search.toLowerCase().replace(/,/g, '');
-
+    const key = this.search.toLowerCase();
     let yearMonthDay: string;
     if (this.selectedDate) {
-      const m = this.selectedDate.getMonth() + 1;
-      const d = this.selectedDate.getDate();
+      const m = this.selectedDate.month;
+      const d = this.selectedDate.day;
 
-      const year = this.selectedDate.getFullYear().toString();
+      const year = this.selectedDate.year;
       const month = m <= 9 ? `0${m}` : `${m}`;
       const day = d <= 9 ? `0${d}` : `${d}`;
       yearMonthDay = `${year}-${month}-${day}`;
@@ -68,12 +104,12 @@ export class LogsComponent implements OnInit, OnDestroy {
       yearMonthDay = '';
     }
 
-    const sHour = this.startTime ? this.startTime.getHours() : 0;
-    const sMinutes = this.startTime ? this.startTime.getMinutes() : 0;
+    const sHour = this.startTime?.hour ?? 0;
+    const sMinutes = this.startTime?.minute ?? 0;
     const sTime = sHour * 60 + sMinutes;
 
-    const eHour = this.endTime ? this.endTime.getHours() : 23;
-    const eMinutes = this.endTime ? this.endTime.getMinutes() : 59;
+    const eHour = this.endTime?.hour ?? 23;
+    const eMinutes = this.endTime?.minute ?? 59;
     const eTime = eHour * 60 + eMinutes;
 
     return { priority, key, yearMonthDay, sTime, eTime };
@@ -81,8 +117,9 @@ export class LogsComponent implements OnInit, OnDestroy {
 
   filterExecutor(logs: Array<any>, filters: any): Array<any> {
     return logs.filter((line) => {
-      const hour = parseInt(line.stamp.slice(11, 13), 10);
-      const minutes = parseInt(line.stamp.slice(14, 16), 10);
+      const localDate = this.datePipe.transform(line.stamp, 'mediumTime');
+      const hour = parseInt(localDate.split(':')[0], 10);
+      const minutes = parseInt(localDate.split(':')[1], 10);
       let prio: string, y_m_d: string, timeSpan: number;
 
       prio = filters.priority === 'All' ? line.priority : filters.priority;
@@ -99,7 +136,7 @@ export class LogsComponent implements OnInit, OnDestroy {
   }
 
   filterLogs() {
-    const filters = this.abstractfilters();
+    const filters = this.abstractFilters();
     this.clog = this.filterExecutor(this.contentData.clog, filters);
     this.audit_log = this.filterExecutor(this.contentData.audit_log, filters);
   }
@@ -112,4 +149,29 @@ export class LogsComponent implements OnInit, OnDestroy {
     this.selectedDate = null;
     this.filterLogs();
   }
+  resetFilter() {
+    this.priority = 'All';
+    this.search = '';
+    this.selectedDate = null;
+    this.startTime = { hour: 0, minute: 0 };
+    this.endTime = { hour: 23, minute: 59 };
+    this.filterLogs();
+
+    return false;
+  }
+
+  logToText(log: object) {
+    let logText = '';
+    for (const line of Object.keys(log)) {
+      logText =
+        logText +
+        this.datePipe.transform(log[line].stamp, 'medium') +
+        '\t' +
+        log[line].priority +
+        '\t' +
+        log[line].message +
+        '\n';
+    }
+    return logText;
+  }
 }