import { Component , OnInit , ChangeDetectionStrategy , ChangeDetectorRef } from '@angular/core' ; import { combineLatest } from 'rxjs' ; import { MetricsService } from './metrics.service' ; import { Metrics , Thread } from './metrics.model' ; @ Component ( { selector : 'jhi-metrics' , templateUrl : './metrics.component.html' , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class MetricsComponent implements OnInit { metrics ? : Metrics ; threads ? : Thread [ ] ; updatingMetrics = true ; constructor ( private metricsService , private changeDetector ) { } ngOnInit ( ) { this . refresh ( ) ; } refresh ( ) { this . updatingMetrics = true ; combineLatest ( [ this . metricsService . getMetrics ( ) , this . metricsService . threadDump ( ) ] ) . subscribe ( ( [ metrics , threadDump ] ) => { this . metrics = metrics ; this . threads = threadDump . threads ; this . updatingMetrics = false ; this . changeDetector . markForCheck ( ) ; } ) ; } metricsKeyExists ( key ) { return Boolean ( this . metrics ?. [ key ] ) ; } metricsKeyExistsAndObjectNotEmpty ( key ) { return Boolean ( this . metrics ?. [ key ] && JSON . stringify ( this . metrics [ key ] ) !== '{}' ) ; } }