Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
Updated for Local 2.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
claygriffiths committed Oct 30, 2017
1 parent 2c163d1 commit 15f03da
Show file tree
Hide file tree
Showing 5 changed files with 1,830 additions and 34 deletions.
33 changes: 16 additions & 17 deletions lib/SiteInfoStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _require = require('smoothie');

var SmoothieChart = _require.SmoothieChart;
var TimeSeries = _require.TimeSeries;
var _require = require('smoothie'),
SmoothieChart = _require.SmoothieChart,
TimeSeries = _require.TimeSeries;

var childProcess = require('child_process');
var readline = require('readline');
Expand All @@ -37,7 +36,7 @@ module.exports = function (context) {
function SiteInfoStats(props) {
_classCallCheck(this, SiteInfoStats);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(SiteInfoStats).call(this, props));
var _this = _possibleConstructorReturn(this, (SiteInfoStats.__proto__ || Object.getPrototypeOf(SiteInfoStats)).call(this, props));

_this.statsProcess = undefined;
_this.memorySeries = undefined;
Expand Down Expand Up @@ -80,7 +79,7 @@ module.exports = function (context) {

if (line.indexOf(site.container) !== -1) {

var matches = /^[a-z0-9]+\s+([0-9.%]+)\s+([0-9.]+ MiB)/gmi.exec(line);
var matches = /^[a-z0-9]+\s+([0-9.%]+)\s+([0-9.]+\s*MiB)/gmi.exec(line);

if (!matches) {
return;
Expand All @@ -89,10 +88,10 @@ module.exports = function (context) {
var time = new Date().getTime();

var cpuResult = matches[1].replace('%', '');
var memoryResult = matches[2].replace(' MiB', '');
var memoryResult = matches[2].replace(/\s*MiB/, '');

_this2.cpuSeries.append(time, cpuResult);
_this2.memorySeries.append(time, matches[2].replace(' MiB', ''));
_this2.memorySeries.append(time, matches[2].replace(/\s*MiB/, ''));

_this2.setState({
cpu: cpuResult,
Expand Down Expand Up @@ -134,7 +133,7 @@ module.exports = function (context) {

this.cpuSeries = new TimeSeries();

chart.addTimeSeries(this.cpuSeries, { lineWidth: 1, strokeStyle: '#4e95c6' });
chart.addTimeSeries(this.cpuSeries, { lineWidth: 1, strokeStyle: '#51bb7b' });
chart.streamTo(this.refs['chart-cpu'], 1000);
}
}, {
Expand Down Expand Up @@ -171,13 +170,13 @@ module.exports = function (context) {

this.memorySeries = new TimeSeries();

chart.addTimeSeries(this.memorySeries, { lineWidth: 1, strokeStyle: '#7f4eb3' });
chart.addTimeSeries(this.memorySeries, { lineWidth: 1, strokeStyle: '#51bb7b' });
chart.streamTo(this.refs['chart-memory'], 1000);

childProcess.execFile(context.environment.dockerPath, ['stats', '--no-stream', site.container], { env: context.environment.dockerEnv }, function (error, stdout, stderr) {
var maxMemoryMatch = /\/ ([0-9.]+ MiB)/gmi.exec(stdout);
var maxMemoryMatch = /\/ ([0-9.]+\s*MiB)/gmi.exec(stdout);

chart.options.maxValue = parseInt(maxMemoryMatch[1].replace(' MiB', ''));
chart.options.maxValue = parseInt(maxMemoryMatch[1].replace(/\s*MiB/, ''));
chart.options.minValue = 0;
chart.updateValueRange();
});
Expand All @@ -200,17 +199,17 @@ module.exports = function (context) {

return React.createElement(
'div',
{ style: { display: 'flex', flexDirection: 'column', flex: 1 } },
{ style: { display: 'flex', flexDirection: 'column', flex: 1, padding: '15px 0' } },
React.createElement(
'div',
{ style: { height: '50%', boxSizing: 'border-box', padding: '15px 0' }, ref: 'chart-cpu-container' },
React.createElement(
'h4',
{ className: 'padded-horizontally-more', style: { marginTop: 0 } },
{ className: 'padded-horizontally-more', style: { margin: '0 30px 15px' } },
'CPU Usage',
React.createElement(
'span',
{ style: { float: 'right', fontFamily: 'monospace', color: '#4e95c6' } },
{ style: { float: 'right', fontFamily: 'monospace', color: '#51bb7b' } },
this.state.cpu ? this.state.cpu + '%' : ''
)
),
Expand All @@ -221,11 +220,11 @@ module.exports = function (context) {
{ style: { height: '50%', boxSizing: 'border-box', padding: '0' }, ref: 'chart-memory-container' },
React.createElement(
'h4',
{ className: 'padded-horizontally-more', style: { marginTop: 0 } },
{ className: 'padded-horizontally-more', style: { margin: '0 30px 15px' } },
'Memory Usage',
React.createElement(
'span',
{ style: { float: 'right', fontFamily: 'monospace', color: '#7f4eb3' } },
{ style: { float: 'right', fontFamily: 'monospace', color: '#51bb7b' } },
this.state.memory ? this.state.memory + ' MiB' : ''
)
),
Expand Down
6 changes: 3 additions & 3 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module.exports = function (context) {

var hooks = context.hooks;
var React = context.React;
var _context$ReactRouter = context.ReactRouter;
var Link = _context$ReactRouter.Link;
var Route = _context$ReactRouter.Route;
var _context$ReactRouter = context.ReactRouter,
Link = _context$ReactRouter.Link,
Route = _context$ReactRouter.Route;


var SiteInfoStats = require('./SiteInfoStats')(context);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "local-addon-stats",
"productName": "Local Stats",
"version": "1.0.0",
"version": "1.1.0",
"author": "Flywheel",
"contributors": [{
"name": "Clay Griffiths",
Expand Down Expand Up @@ -36,6 +36,6 @@
"smoothie": "^1.27.0"
},
"engines": {
"local-by-flywheel": "^1.1.0"
"local-by-flywheel": "^2.0.0"
}
}
24 changes: 12 additions & 12 deletions src/SiteInfoStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = function (context) {

if (line.indexOf(site.container) !== -1) {

let matches = (/^[a-z0-9]+\s+([0-9.%]+)\s+([0-9.]+ MiB)/gmi).exec(line);
let matches = (/^[a-z0-9]+\s+([0-9.%]+)\s+([0-9.]+\s*MiB)/gmi).exec(line);

if ( !matches ) {
return;
Expand All @@ -67,10 +67,10 @@ module.exports = function (context) {
let time = new Date().getTime();

let cpuResult = matches[1].replace('%', '');
let memoryResult = matches[2].replace(' MiB', '');
let memoryResult = matches[2].replace(/\s*MiB/, '');

this.cpuSeries.append(time, cpuResult);
this.memorySeries.append(time, matches[2].replace(' MiB', ''));
this.memorySeries.append(time, matches[2].replace(/\s*MiB/, ''));

this.setState({
cpu: cpuResult,
Expand Down Expand Up @@ -114,7 +114,7 @@ module.exports = function (context) {

this.cpuSeries = new TimeSeries();

chart.addTimeSeries(this.cpuSeries, {lineWidth: 1, strokeStyle: '#4e95c6'});
chart.addTimeSeries(this.cpuSeries, {lineWidth: 1, strokeStyle: '#51bb7b'});
chart.streamTo(this.refs['chart-cpu'], 1000);

};
Expand Down Expand Up @@ -151,13 +151,13 @@ module.exports = function (context) {

this.memorySeries = new TimeSeries();

chart.addTimeSeries(this.memorySeries, {lineWidth: 1, strokeStyle: '#7f4eb3'});
chart.addTimeSeries(this.memorySeries, {lineWidth: 1, strokeStyle: '#51bb7b'});
chart.streamTo(this.refs['chart-memory'], 1000);

childProcess.execFile(context.environment.dockerPath, ['stats', '--no-stream', site.container], {env: context.environment.dockerEnv}, (error, stdout, stderr) => {
let maxMemoryMatch = (/\/ ([0-9.]+ MiB)/gmi).exec(stdout);
let maxMemoryMatch = (/\/ ([0-9.]+\s*MiB)/gmi).exec(stdout);

chart.options.maxValue = parseInt(maxMemoryMatch[1].replace(' MiB', ''));
chart.options.maxValue = parseInt(maxMemoryMatch[1].replace(/\s*MiB/, ''));
chart.options.minValue = 0;
chart.updateValueRange();
});
Expand All @@ -180,19 +180,19 @@ module.exports = function (context) {
render() {

return (
<div style={{display: 'flex', flexDirection: 'column', flex: 1}}>
<div style={{display: 'flex', flexDirection: 'column', flex: 1, padding: '15px 0'}}>
<div style={{height: '50%', boxSizing: 'border-box', padding: '15px 0'}} ref="chart-cpu-container">
<h4 className="padded-horizontally-more" style={{marginTop: 0}}>
<h4 className="padded-horizontally-more" style={{margin: '0 30px 15px'}}>
CPU Usage
<span style={{float: 'right', fontFamily: 'monospace', color: '#4e95c6'}}>{this.state.cpu ? this.state.cpu + '%' : ''}</span>
<span style={{float: 'right', fontFamily: 'monospace', color: '#51bb7b'}}>{this.state.cpu ? this.state.cpu + '%' : ''}</span>
</h4>

<canvas width="" height="" ref="chart-cpu"></canvas>
</div>
<div style={{height: '50%', boxSizing: 'border-box', padding: '0'}} ref="chart-memory-container">
<h4 className="padded-horizontally-more" style={{marginTop: 0}}>
<h4 className="padded-horizontally-more" style={{margin: '0 30px 15px'}}>
Memory Usage
<span style={{float: 'right', fontFamily: 'monospace', color: '#7f4eb3'}}>{this.state.memory ? this.state.memory + ' MiB' : ''}</span>
<span style={{float: 'right', fontFamily: 'monospace', color: '#51bb7b'}}>{this.state.memory ? this.state.memory + ' MiB' : ''}</span>
</h4>

<canvas width="400" height="200" ref="chart-memory"></canvas>
Expand Down
Loading

0 comments on commit 15f03da

Please sign in to comment.