1 import { Component, ElementRef, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
3 import * as _ from 'lodash';
4 import * as moment from 'moment';
6 import { ChartTooltip } from '../../../shared/models/chart-tooltip';
9 selector: 'cd-cephfs-chart',
10 templateUrl: './cephfs-chart.component.html',
11 styleUrls: ['./cephfs-chart.component.scss']
13 export class CephfsChartComponent implements OnChanges, OnInit {
14 @ViewChild('chartCanvas')
15 chartCanvas: ElementRef;
16 @ViewChild('chartTooltip')
17 chartTooltip: ElementRef;
22 lhsCounter = 'mds_mem.ino';
23 rhsCounter = 'mds_server.handle_client_request';
30 if (_.isUndefined(this.mdsCounter)) {
34 const getTitle = (ts) => {
35 return moment(ts, 'x').format('LTS');
38 const getStyleTop = (tooltip) => {
39 return tooltip.caretY - tooltip.height - 15 + 'px';
42 const getStyleLeft = (tooltip) => {
43 return tooltip.caretX + 'px';
46 const chartTooltip = new ChartTooltip(
52 chartTooltip.getTitle = getTitle;
53 chartTooltip.checkOffset = true;
55 const lhsData = this.convert_timeseries(this.mdsCounter[this.lhsCounter]);
56 const rhsData = this.delta_timeseries(this.mdsCounter[this.rhsCounter]);
61 label: this.lhsCounter,
67 label: this.rhsCounter,
75 text: this.mdsCounter.name,
79 maintainAspectRatio: false,
119 // Pick the Unix timestamp of the first tooltip item.
120 title: function(tooltipItems, data) {
122 if (tooltipItems.length > 0) {
123 const item = tooltipItems[0];
124 ts = data.datasets[item.datasetIndex].data[item.index].x;
129 custom: (tooltip) => {
130 chartTooltip.customTooltips(tooltip);
143 const lhsData = this.convert_timeseries(this.mdsCounter[this.lhsCounter]);
144 const rhsData = this.delta_timeseries(this.mdsCounter[this.rhsCounter]);
146 this.chart.datasets[0].data = lhsData;
147 this.chart.datasets[1].data = rhsData;
150 // Convert ceph-mgr's time series format (list of 2-tuples
151 // with seconds-since-epoch timestamps) into what chart.js
152 // can handle (list of objects with millisecs-since-epoch
154 convert_timeseries(sourceSeries) {
156 _.each(sourceSeries, (dp) => {
166 delta_timeseries(sourceSeries) {
168 let prev = sourceSeries[0];
170 for (i = 1; i < sourceSeries.length; i++) {
171 const cur = sourceSeries[i];
172 const tdelta = cur[0] - prev[0];
173 const vdelta = cur[1] - prev[1];
174 const rate = vdelta / tdelta;