Skip to content

Commit

Permalink
[wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Irfan Habib committed Sep 30, 2018
1 parent d8a2554 commit c48de76
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IMetricMatrixResult } from '../../../../../store/types/base-metric.type
import { MetricsChartHelpers } from '../../../../../shared/components/metrics-chart/metrics.component.helpers';
import { IMetricApplication } from '../../../../../store/types/metric.types';
import { FetchKubernetesMetricsAction } from '../../../store/kubernetes.actions';

@Component({
selector: 'app-pod-chart',
templateUrl: './pod-chart.component.html',
Expand All @@ -15,6 +16,9 @@ export class PodChartComponent implements OnInit {
@Input()
private podName: string;

@Input()
private aggregate: string;

@Input()
private endpointGuid: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
<p>
kubernetes-node-metrics works!
</p>
<div class="kubernetes-node-metrics">
<app-tile>
<app-tile-group>
<app-tile>
<app-kubernetes-node-metric-stats-card title="Memory" [metric]="memoryMetric" [unit]="memoryUnit"></app-kubernetes-node-metric-stats-card>
</app-tile>
<app-tile>
<app-kubernetes-node-metric-stats-card title="CPU" [metric]="cpuMetric" [unit]="cpuUnit"></app-kubernetes-node-metric-stats-card>
</app-tile>
</app-tile-group>
<app-tile-group>
<app-tile>
<app-kubernetes-node-metrics-chart
[nodeName]="kubeNodeService.nodeName"
[endpointGuid]="kubeNodeService.kubeGuid"
[yAxisLabel]=""
[metricName]="memoryMetric"
title = "Memory Usage"
></app-kubernetes-node-metrics-chart>
</app-tile>
</app-tile-group>
<app-tile-group>
<app-tile>
<app-kubernetes-node-metrics-chart
[nodeName]="kubeNodeService.nodeName"
[endpointGuid]="kubeNodeService.kubeGuid"
[yAxisLabel]=""
[metricName]="cpuMetric"
title= "CPU Usage"
></app-kubernetes-node-metrics-chart>
</app-tile>
</app-tile-group>
</app-tile>
</div>

Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { Component, OnInit } from '@angular/core';
import { KubernetesNodeService, KubeNodeMetric } from '../../services/kubernetes-node.service';

@Component({
selector: 'app-kubernetes-node-metrics',
templateUrl: './kubernetes-node-metrics.component.html',
styleUrls: ['./kubernetes-node-metrics.component.scss']
})
export class KubernetesNodeMetricsComponent implements OnInit {
memoryMetric: KubeNodeMetric;
cpuMetric: KubeNodeMetric;
memoryUnit: string;
cpuUnit: string;

constructor() { }
constructor(
public kubeNodeService: KubernetesNodeService
) { }

ngOnInit() {

this.memoryMetric = KubeNodeMetric.MEMORY;
this.cpuMetric = KubeNodeMetric.CPU;
this.memoryUnit = 'bytes';
this.cpuUnit = 'secs';
}

}
8 changes: 7 additions & 1 deletion src/frontend/app/custom/kubernetes/kubernetes.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ import { KubernetesAppsTabComponent } from './tabs/kubernetes-apps-tab/kubernete
import { KubernetesNamespacesTabComponent } from './tabs/kubernetes-namespaces-tab/kubernetes-namespaces-tab.component';
import { KubernetesNodesTabComponent } from './tabs/kubernetes-nodes-tab/kubernetes-nodes-tab.component';
import { KubernetesPodsTabComponent } from './tabs/kubernetes-pods-tab/kubernetes-pods-tab.component';
import { KubernetesNodeMetricsChartComponent } from './kubernetes-node/kubernetes-node-metrics/kubernetes-node-metrics-chart/kubernetes-node-metrics-chart.component';
import { KubernetesNodeMetricStatsCardComponent } from './kubernetes-node/kubernetes-node-metrics/kubernetes-node-metric-stats-card/kubernetes-node-metric-stats-card.component';
import { KubernetesNodeSimpleMetricComponent } from './kubernetes-node/kubernetes-node-metrics/kubernetes-node-simple-metric/kubernetes-node-simple-metric.component';

@NgModule({
imports: [
Expand Down Expand Up @@ -110,7 +113,10 @@ import { KubernetesPodsTabComponent } from './tabs/kubernetes-pods-tab/kubernete
KubernetesNodePodsLinkComponent,
KubernetesNodeInfoCardComponent,
KubernetesNodeMetricsComponent,
KubernetesNodeConditionComponent
KubernetesNodeConditionComponent,
KubernetesNodeMetricsChartComponent,
KubernetesNodeMetricStatsCardComponent,
KubernetesNodeSimpleMetricComponent
],
providers: [
KubernetesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ import { Store } from '@ngrx/store';
import { AppState } from '../../../store/app-state';
import { PaginationMonitorFactory } from '../../../shared/monitors/pagination-monitor.factory';
import { getIdFromRoute } from '../../../features/cloud-foundry/cf.helpers';
import { KubernetesNode } from '../store/kube.types';
import { kubernetesNodesSchemaKey, entityFactory } from '../../../store/helpers/entity-factory';
import { KubernetesNode, MetricStatistic } from '../store/kube.types';
import { kubernetesNodesSchemaKey, entityFactory, metricSchemaKey } from '../../../store/helpers/entity-factory';
import { EntityServiceFactory } from '../../../core/entity-service-factory.service';
import { GetKubernetesNode } from '../store/kubernetes.actions';
import { GetKubernetesNode, FetchKubernetesMetricsAction } from '../store/kubernetes.actions';
import { first, shareReplay, filter, map } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { EntityInfo } from '../../../store/types/api.types';
import { EntityMonitorFactory } from '../../../shared/monitors/entity-monitor.factory.service';
import { IMetrics } from '../../../store/types/base-metric.types';
import { MetricsAction } from '../../../store/actions/metrics.actions';


export enum KubeNodeMetric {
CPU = 'container_cpu_usage_seconds_total',
MEMORY = 'container_memory_usage_bytes'
}

@Injectable()
export class KubernetesNodeService {
Expand All @@ -25,13 +34,13 @@ export class KubernetesNodeService {
public activatedRoute: ActivatedRoute,
public store: Store<AppState>,
public paginationMonitorFactory: PaginationMonitorFactory,
public entityServiceFactory: EntityServiceFactory
public entityServiceFactory: EntityServiceFactory,
public entityMonitorFactory: EntityMonitorFactory

) {
this.nodeName = getIdFromRoute(activatedRoute, 'nodeName');
this.kubeGuid = kubeEndpointService.kubeGuid;


const nodeEntityService = this.entityServiceFactory.create<KubernetesNode>(
kubernetesNodesSchemaKey,
entityFactory(kubernetesNodesSchemaKey),
Expand All @@ -51,4 +60,24 @@ export class KubernetesNodeService {
map(p => p.entity)
);
}



public setupMetricObservable(metric: KubeNodeMetric, metricStatistic: MetricStatistic) {

const query = `${metricStatistic}(${metricStatistic}_over_time(${metric}{kubernetes_io_hostname="${this.nodeName}"}[1h]))`;
const metricsAction = new FetchKubernetesMetricsAction(this.nodeName, this.kubeGuid, query);
const metricsId = MetricsAction.buildMetricKey(this.nodeName, query);
const metricsMonitor = this.entityMonitorFactory.create<IMetrics>(metricsId, metricSchemaKey, entityFactory(metricSchemaKey));
this.store.dispatch(metricsAction);
const pollSub = metricsMonitor.poll(30000, () => this.store.dispatch(metricsAction),
request => ({ busy: request.fetching, error: request.error, message: request.message }))
.subscribe();
return {
entity$: metricsMonitor.entity$.pipe(filter(metrics => !!metrics), map(metrics => {
return metrics.result[0].value[1];
})),
pollerSub: pollSub
};
}
}
6 changes: 5 additions & 1 deletion src/frontend/app/custom/kubernetes/store/kube.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ export interface Requests {
memory: string;
cpu: string;
}

export enum MetricStatistic {
AVERAGE = 'avg',
MAXIMUM = 'max',
MINOMUM = 'min'
}

export interface VolumeMount {
name: string;
Expand Down

0 comments on commit c48de76

Please sign in to comment.