]> 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 dc33c5356344c989ee53cffd189863745e5f5621..ed8c721eaf3e1f6b3440d091c4c829dc01edf366 100644 (file)
@@ -1,8 +1,13 @@
 import { DatePipe } from '@angular/common';
 import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
 
-import { LogsService } from '../../../shared/api/logs.service';
-import { Icons } from '../../../shared/enum/icons.enum';
+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',
@@ -14,13 +19,14 @@ export class LogsComponent implements OnInit, OnDestroy {
   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]' },
@@ -28,21 +34,26 @@ export class LogsComponent implements OnInit, OnDestroy {
   ];
   priority = 'All';
   search = '';
-  selectedDate: Date;
-  startTime: Date = new Date();
-  endTime: Date = new Date();
+  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
-  ) {
-    this.startTime.setHours(0, 0);
-    this.endTime.setHours(23, 59);
-  }
+  ) {}
 
   ngOnInit() {
     this.getInfo();
     this.ngZone.runOutsideAngular(() => {
+      this.getDaemonDetails();
       this.interval = window.setInterval(() => {
         this.ngZone.run(() => {
           this.getInfo();
@@ -55,23 +66,37 @@ export class LogsComponent implements OnInit, OnDestroy {
     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}`;
@@ -79,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 };
@@ -111,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);
   }
@@ -124,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;
+  }
 }