Skip to content

Commit

Permalink
Fix .gitignore, and add files
Browse files Browse the repository at this point in the history
  • Loading branch information
Irfan Habib committed Sep 30, 2018
1 parent c48de76 commit 24bdc99
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ src/frontend/assets/logo.png
src/frontend/assets/login-bg.jpg
src/frontend/app/custom.module.ts
src/frontend/app/custom-import.module.ts
src/frontend/app/custom
# src/frontend/app/custom
src/frontend/assets/custom
src/frontend/sass/custom
src/frontend/index.html
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="kubernetes-node-metric-stats-card">
<mat-card>
<mat-card-header>
<mat-card-title>Summary of {{title}} Usage for Last {{period}} in {{unit}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<div class="app-metadata">
<app-kubernetes-node-simple-metric key="Mean" value="{{ mean$ | async }}"></app-kubernetes-node-simple-metric>
<app-kubernetes-node-simple-metric key="Maximum" value="{{ max$ | async }}"></app-kubernetes-node-simple-metric>
</div>
</mat-card-content>
</mat-card>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { KubernetesNodeMetricStatsCardComponent } from './kubernetes-node-metric-stats-card.component';

describe('KubernetesNodeMetricStatsCardComponent', () => {
let component: KubernetesNodeMetricStatsCardComponent;
let fixture: ComponentFixture<KubernetesNodeMetricStatsCardComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ KubernetesNodeMetricStatsCardComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(KubernetesNodeMetricStatsCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { Observable, of as observableOf, Subscription } from 'rxjs';
import { KubernetesNodeService, KubeNodeMetric } from '../../../services/kubernetes-node.service';
import { MetricStatistic } from '../../../store/kube.types';
import { IMetrics } from '../../../../../store/types/base-metric.types';

@Component({
selector: 'app-kubernetes-node-metric-stats-card',
templateUrl: './kubernetes-node-metric-stats-card.component.html',
styleUrls: ['./kubernetes-node-metric-stats-card.component.scss']
})
export class KubernetesNodeMetricStatsCardComponent implements OnInit, OnDestroy {

@Input()
title = 'Memory';

@Input()
metric: KubeNodeMetric;

@Input()
period = 'Hour';

@Input()
unit: string;

max$: Observable<number>;
mean$: Observable<number>;
subscriptions: Subscription[] = [];
constructor(
public kubeNodeService: KubernetesNodeService
) {

}

ngOnInit() {

const maxMetric = this.kubeNodeService.setupMetricObservable(this.metric, MetricStatistic.MAXIMUM);
this.subscriptions.push(maxMetric.pollerSub);
this.max$ = maxMetric.entity$;

const meanMetric = this.kubeNodeService.setupMetricObservable(this.metric, MetricStatistic.AVERAGE);
this.subscriptions.push(meanMetric.pollerSub);
this.mean$ = meanMetric.entity$;
}


ngOnDestroy() {
this.subscriptions.forEach(s => s.unsubscribe());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="kubernetes-node-metrics-chart">
<mat-card>
<mat-card-header>
<mat-card-content class="kubernetes-node-metrics-chart__content">
<app-metrics-chart [title]="title" [metricsConfig]="instanceMetricConfig" [chartConfig]="instanceChartConfig"></app-metrics-chart>
</mat-card-content>
</mat-card-header>
</mat-card>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.kubernetes-node-metrics-chart{
padding-top: 40px;
width: 100%;
&__content{
width: 100%;
height: 300px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { KubernetesNodeMetricsChartComponent } from './kubernetes-node-metrics-chart.component';

describe('KubernetesNodeMetricsChartComponent', () => {
let component: KubernetesNodeMetricsChartComponent;
let fixture: ComponentFixture<KubernetesNodeMetricsChartComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ KubernetesNodeMetricsChartComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(KubernetesNodeMetricsChartComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Component, Input, OnInit } from '@angular/core';

import { MetricsConfig } from '../../../../../shared/components/metrics-chart/metrics-chart.component';
import { MetricsLineChartConfig } from '../../../../../shared/components/metrics-chart/metrics-chart.types';
import { IMetricMatrixResult } from '../../../../../store/types/base-metric.types';
import { IMetricApplication } from '../../../../../store/types/metric.types';
import { MetricsChartHelpers } from '../../../../../shared/components/metrics-chart/metrics.component.helpers';
import { FetchKubernetesMetricsAction } from '../../../store/kubernetes.actions';

@Component({
selector: 'app-kubernetes-node-metrics-chart',
templateUrl: './kubernetes-node-metrics-chart.component.html',
styleUrls: ['./kubernetes-node-metrics-chart.component.scss']
})
export class KubernetesNodeMetricsChartComponent implements OnInit {

@Input()
private nodeName: string;
@Input()
private endpointGuid: string;
@Input()
private yAxisLabel: string;
@Input()
private metricName: string;
@Input()
private seriesTranslation: string;
@Input()
public title: string;

public instanceChartConfig: MetricsLineChartConfig;
public instanceMetricConfig: MetricsConfig<IMetricMatrixResult<IMetricApplication>>;
constructor() { }

private buildChartConfig() {
const lineChartConfig = new MetricsLineChartConfig();
lineChartConfig.xAxisLabel = 'Time';
lineChartConfig.yAxisLabel = this.yAxisLabel;
lineChartConfig.showLegend = false;
return lineChartConfig;
}

ngOnInit() {
this.instanceChartConfig = this.buildChartConfig();
const query = `${this.metricName}{instance="${this.nodeName}"}[1h]&time=${(new Date()).getTime() / 1000}`;
this.instanceMetricConfig = {
getSeriesName: result => result.metric.name ? result.metric.name : result.metric.id,
mapSeriesItemName: MetricsChartHelpers.getDateSeriesName,
sort: MetricsChartHelpers.sortBySeriesName,
mapSeriesItemValue: this.getmapSeriesItemValue(),
metricsAction: new FetchKubernetesMetricsAction(
this.nodeName,
this.endpointGuid,
query,
),
};
}

private getmapSeriesItemValue() {
switch (this.seriesTranslation) {
case 'mb':
return (bytes) => bytes / 1000000;
default:
return undefined;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="kube-node-metric">
<div class="kube-node-metric__key">
<span class="kube-node-metric__key__span">{{ key }}</span>
</div>
<div class="kube-node-metric__value">
<span class="kube-node-metric__value__span">{{ value }}</span>
</div>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { KubernetesNodeSimpleMetricComponent } from './kubernetes-node-simple-metric.component';

describe('KubernetesNodeSimpleMetricComponent', () => {
let component: KubernetesNodeSimpleMetricComponent;
let fixture: ComponentFixture<KubernetesNodeSimpleMetricComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ KubernetesNodeSimpleMetricComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(KubernetesNodeSimpleMetricComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component, OnInit, Input } from '@angular/core';

@Component({
selector: 'app-kubernetes-node-simple-metric',
templateUrl: './kubernetes-node-simple-metric.component.html',
styleUrls: ['./kubernetes-node-simple-metric.component.scss']
})
export class KubernetesNodeSimpleMetricComponent implements OnInit {

@Input()
key: string;

@Input()
value: number;

constructor() { }

ngOnInit() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="kube-node-condition">
<div class="kube-node-condition__title">
<mat-icon [fontSet]="icons[condition][1]">{{ icons[condition][0] }}</mat-icon>
<span class="kube-node-condition__title__span">{{ titles[condition] }}</span>
</div>
<app-boolean-indicator [isTrue]="(condition$ | async)?.status == 'True'" type="yes-no"></app-boolean-indicator>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.kube-node-condition {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-right: 20px;
padding-top: 20px;
&__title{
display: flex;
justify-content: center;
&__span{
margin-left: 10px;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { KubernetesNodeConditionComponent } from './kubernetes-node-condition.component';

describe('KubernetesNodeConditionComponent', () => {
let component: KubernetesNodeConditionComponent;
let fixture: ComponentFixture<KubernetesNodeConditionComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ KubernetesNodeConditionComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(KubernetesNodeConditionComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Component, OnInit, Input } from '@angular/core';
import { ConditionType, Condition } from '../../../../../store/kube.types';
import { KubernetesNodeService } from '../../../../../services/kubernetes-node.service';
import { map, filter } from 'rxjs/operators';
import { Observable } from 'rxjs';

@Component({
selector: 'app-kubernetes-node-condition',
templateUrl: './kubernetes-node-condition.component.html',
styleUrls: ['./kubernetes-node-condition.component.scss']
})
export class KubernetesNodeConditionComponent implements OnInit {


@Input()
condition: ConditionType;
condition$: Observable<Condition>;

public titles = {
'Ready': 'Ready',
'OutOfDisk': 'Out of Disk',
'MemoryPressure': 'Memory Pressure',
'DiskPressure': 'Disk Pressure'
};

public icons = {
'Ready': ['done_outline', 'material-icons'],
'OutOfDisk': ['storage', 'stratos-icons'],
'MemoryPressure': ['memory', 'material-icons'],
'DiskPressure': ['storage', 'stratos-icons'],
};

constructor(
public kubeNodeService: KubernetesNodeService
) { }

ngOnInit() {

this.condition$ = this.kubeNodeService.node$.pipe(
filter(p => !!p && !!p.entity),
map(p => p.entity.status.conditions),
map(conditions => conditions.filter(o => o.type === this.condition)[0])
);
}
}

0 comments on commit 24bdc99

Please sign in to comment.