1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-11 05:40:11 +02:00

B&W graphs: Implementing disk and memory

This commit is contained in:
Tom Gallacher 2016-11-21 14:09:52 +00:00 committed by Sérgio Ramos
parent fe99517cb3
commit 6822feb508
7 changed files with 59 additions and 32 deletions

View File

@ -8,7 +8,7 @@ const actions = {
disk: [] disk: []
}); });
const newData = ['cpu', 'mem'].reduce((sum, key) => { const newData = ['cpu', 'mem', 'disk'].reduce((sum, key) => {
const item = { const item = {
...action.payload.stats[key], ...action.payload.stats[key],
when: action.payload.when when: action.payload.when

View File

@ -19,7 +19,9 @@ module.exports = React.createClass({
stacked = false, stacked = false,
xAxe = false, xAxe = false,
yAxe = false, yAxe = false,
legend = false legend = false,
max = 100,
min = 0
} = this.props; } = this.props;
const _labels = !Array.isArray(labels) const _labels = !Array.isArray(labels)
@ -33,13 +35,13 @@ module.exports = React.createClass({
scales: { scales: {
xAxes: [{ xAxes: [{
barPercentage: 1.0, barPercentage: 1.0,
categoryPercentage: 1.0, categoryPercentage: 1.0
}], }],
yAxes: [{ yAxes: [{
ticks: { ticks: {
min: 0, min: min,
max: 100 max: max
}, }
}] }]
}, },
legend: { legend: {

View File

@ -18,7 +18,7 @@ module.exports = ({
label: key, label: key,
backgroundColor: colors[key], backgroundColor: colors[key],
altBackgroundColor: colors['alt'], altBackgroundColor: colors['alt'],
data: buildArray(windowSize).map((v, i) => ((data[i] || {})[key] || { firstQuartile: 0, thirdQuartile: 0, median: 0, max: 0, min: 0 })) data: buildArray(windowSize).map((v, i) => ((data[i] || {})[key] || { firstQuartile: 0, thirdQuartile: 0, median: 0, max: 0, min: 0 })).reverse()
}; };
}); });

View File

@ -4,8 +4,8 @@ const Chart = require('./base');
const React = require('react'); const React = require('react');
const colors = { const colors = {
user: 'rgb(255, 99, 132)', perc: 'rgba(54, 74, 205, 0.2)',
sys: 'rgb(255, 159, 64)' alt: 'rgba(245, 93, 93, 0.2)'
}; };
module.exports = ({ module.exports = ({
@ -14,20 +14,15 @@ module.exports = ({
}) => { }) => {
const datasets = [{ const datasets = [{
label: 'disk', label: 'disk',
backgroundColor: 'rgb(255, 159, 64)', backgroundColor: colors['perc'],
data: buildArray(windowSize).map((v, i) => { altBackgroundColor: colors['alt'],
return data[i] ? (data[i].total - data[i].free) : 0; data: buildArray(windowSize).map((v, i) => ((data[i] || {})['perc'] || { firstQuartile: 0, thirdQuartile: 0, median: 0, max: 0, min: 0 })).reverse()
})
}]; }];
const labels = buildArray(windowSize).map((v, i) => {
return data[i] ? pretty(datasets[0].data[i]) : '';
});
return ( return (
<Chart <Chart
datasets={datasets} datasets={datasets}
labels={labels} labels={datasets[0].data.length}
legend={true} legend={true}
/> />
); );

View File

@ -3,8 +3,8 @@ const Chart = require('./base');
const React = require('react'); const React = require('react');
const colors = { const colors = {
user: 'rgb(255, 99, 132)', perc: 'rgba(54, 74, 205, 0.2)',
sys: 'rgb(255, 159, 64)' alt: 'rgba(245, 93, 93, 0.2)'
}; };
module.exports = ({ module.exports = ({
@ -13,8 +13,9 @@ module.exports = ({
}) => { }) => {
const datasets = [{ const datasets = [{
label: 'mem', label: 'mem',
backgroundColor: 'rgb(255, 99, 132)', backgroundColor: colors['perc'],
data: buildArray(windowSize).map((v, i) => ((data[i] || {}).used || 0)) altBackgroundColor: colors['alt'],
data: buildArray(windowSize).map((v, i) => ((data[i] || {}).perc || { firstQuartile: 0, thirdQuartile: 0, median: 0, max: 0, min: 0 })).reverse()
}]; }];
return ( return (

View File

@ -104,7 +104,6 @@ module.exports = function(Chart) {
var obj = me.getDataset().data[index]; var obj = me.getDataset().data[index];
var value = Number(obj.stddev); var value = Number(obj.stddev);
console.log('stddev >>', value);
return value; return value;
}, },

View File

@ -15,7 +15,7 @@ const getCPU = (fn) => {
}; };
const getPerc = (fn) => { const getPerc = (fn) => {
async.timesSeries(20, (n, next) => { async.timesSeries(5, (n, next) => {
osutils.cpuUsage((p) => { osutils.cpuUsage((p) => {
const percentage = p * 100; const percentage = p * 100;
next(null, percentage); next(null, percentage);
@ -35,18 +35,48 @@ const getPerc = (fn) => {
}; };
const getMem = (fn) => { const getMem = (fn) => {
async.timesSeries(10, (n, next) => {
const free = os.freemem(); const free = os.freemem();
const total = os.totalmem(); const total = os.totalmem();
const using = total - free; const using = total - free;
const perc = (using / total) * 100; const perc = (using / total) * 100;
setTimeout(() => {
return fn(null, { next(null, perc);
used: perc }, 500);
}, (err, sample) => {
fn(err, {
perc: {
firstQuartile: statistics.quantile(sample, 0.25),
median: statistics.median(sample),
thirdQuartile: statistics.quantile(sample, 0.75),
max: statistics.max(sample),
min: statistics.min(sample),
stddev: statistics.sampleStandardDeviation(sample)
}
});
}); });
}; };
const getDisk = (fn) => { const getDisk = (fn) => {
disk.check('/', fn); async.timesSeries(5, (n, next) => {
disk.check('/', (err, data) => {
setTimeout(() => {
const perc = (data.available / data.total) * 100;
next(err, perc);
}, 2000);
});
}, (err, sample) => {
fn(err, {
perc: {
firstQuartile: statistics.quantile(sample, 0.25),
median: statistics.median(sample),
thirdQuartile: statistics.quantile(sample, 0.75),
max: statistics.max(sample),
min: statistics.min(sample),
stddev: statistics.sampleStandardDeviation(sample)
}
});
});
}; };
const getStats = (fn) => { const getStats = (fn) => {