2015-10-28 19:42:43 +00:00
|
|
|
var Dashboard = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
this.reload();
|
|
|
|
},
|
|
|
|
|
|
|
|
reload: function() {
|
|
|
|
getURL("http://127.0.0.1:6464/stats.json", {}, function(resp) {
|
2015-10-28 23:22:21 +00:00
|
|
|
var newState = {};
|
|
|
|
var decode = function(point) {
|
|
|
|
return {
|
|
|
|
timestamp: point[0],
|
|
|
|
processed: point[1],
|
|
|
|
errors: point[2],
|
|
|
|
min: point[3],
|
|
|
|
p25: point[4],
|
|
|
|
mean: point[5],
|
|
|
|
median: point[6],
|
|
|
|
p75: point[7],
|
|
|
|
max: point[8],
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (name in resp) {
|
|
|
|
newState[name] = resp[name].map(decode);
|
|
|
|
}
|
|
|
|
this.setState(newState);
|
|
|
|
setTimeout(this.reload, 3000);
|
2015-10-28 19:42:43 +00:00
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
renderDaemons: function() {
|
|
|
|
var daemons = [];
|
|
|
|
for (name in this.state) {
|
|
|
|
daemons.push(<Daemon name={name} key={name} points={this.state[name]} />);
|
|
|
|
}
|
|
|
|
|
|
|
|
return daemons;
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
2015-10-31 19:00:50 +00:00
|
|
|
<div className="dashboard">
|
|
|
|
<Header />
|
|
|
|
<div className="daemons">{this.renderDaemons()}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var Header = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
return (
|
2015-10-31 19:55:38 +00:00
|
|
|
<div className="table-row table-header">
|
|
|
|
<div className="table-cell col-name">Daemon</div>
|
|
|
|
<div className="table-cell col-processed">Processed</div>
|
|
|
|
<div className="table-cell col-errors">Errors</div>
|
|
|
|
<div className="table-cell col-min">Min</div>
|
|
|
|
<div className="table-cell col-median">Median</div>
|
|
|
|
<div className="table-cell col-max">Max</div>
|
2015-10-31 19:00:50 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var StatsRow = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
var value = this.props.value;
|
|
|
|
return (
|
2015-10-31 19:55:38 +00:00
|
|
|
<div className="table-row">
|
|
|
|
<div className="table-cell col-name">{this.props.name}</div>
|
|
|
|
<div className="table-cell col-processed">{value.processed}</div>
|
|
|
|
<div className="table-cell col-errors">{value.errors}</div>
|
|
|
|
<div className="table-cell col-min">{formatDuration(value.min)}</div>
|
|
|
|
<div className="table-cell col-median">{formatDuration(value.median)}</div>
|
|
|
|
<div className="table-cell col-max">{formatDuration(value.max)}</div>
|
2015-10-31 19:00:50 +00:00
|
|
|
</div>
|
2015-10-28 19:42:43 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var Daemon = React.createClass({
|
|
|
|
render: function() {
|
2015-10-28 23:22:21 +00:00
|
|
|
var last = this.props.points[this.props.points.length - 1];
|
2015-10-28 19:42:43 +00:00
|
|
|
return (
|
|
|
|
<div className="daemon">
|
2015-10-31 19:00:50 +00:00
|
|
|
<StatsRow name={this.props.name} value={last} />
|
2015-10-31 19:55:38 +00:00
|
|
|
<LineChart points={this.props.points} />
|
2015-10-28 23:22:21 +00:00
|
|
|
<BoxPlot points={this.props.points} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var BoxPlot = React.createClass({
|
|
|
|
render: function(){
|
|
|
|
var points = this.props.points,
|
|
|
|
maxHeight = 140,
|
|
|
|
padding = 5;
|
|
|
|
|
|
|
|
var min, max;
|
|
|
|
points.map(function(point) {
|
|
|
|
if (min === undefined || point.min < min) {
|
|
|
|
min = point.min;
|
|
|
|
}
|
|
|
|
if (max === undefined || point.max > max) {
|
|
|
|
max = point.max;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var renderBox = function(point, i) {
|
|
|
|
var relativeY = function(val) {
|
|
|
|
return maxHeight - Math.round((val-min)/(max-min) * maxHeight) + padding;
|
|
|
|
};
|
|
|
|
|
|
|
|
var width = 10;
|
|
|
|
var padding = 5;
|
|
|
|
|
|
|
|
var x1 = (width + padding) * i + padding;
|
|
|
|
var x2 = x1 + width;
|
|
|
|
var minY = relativeY(point.min);
|
|
|
|
var p25Y = relativeY(point.p25);
|
|
|
|
var medianY = relativeY(point.median);
|
|
|
|
var p75Y = relativeY(point.p75);
|
|
|
|
var maxY = relativeY(point.max);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<g key={i}>
|
|
|
|
<line key="max"
|
2015-10-29 00:05:59 +00:00
|
|
|
x1={x1+2}
|
|
|
|
x2={x2-2}
|
2015-10-28 23:22:21 +00:00
|
|
|
y1={maxY}
|
|
|
|
y2={maxY}
|
|
|
|
strokeWidth={1}
|
2015-10-29 00:05:59 +00:00
|
|
|
style={{stroke: "#aaa"}} />
|
2015-10-28 23:22:21 +00:00
|
|
|
<line key="max-bar"
|
|
|
|
x1={x1+width/2}
|
|
|
|
x2={x1+width/2}
|
|
|
|
y1={maxY}
|
|
|
|
y2={p75Y}
|
2015-10-29 00:05:59 +00:00
|
|
|
strokeDasharray="3,1"
|
2015-10-28 23:22:21 +00:00
|
|
|
strokeWidth={1}
|
2015-10-29 00:05:59 +00:00
|
|
|
style={{stroke: "#ccc"}} />
|
2015-10-30 17:46:57 +00:00
|
|
|
<line key="min-bar"
|
|
|
|
x1={x1+width/2}
|
|
|
|
x2={x1+width/2}
|
|
|
|
y1={minY}
|
|
|
|
y2={p25Y}
|
|
|
|
strokeDasharray="3,1"
|
|
|
|
strokeWidth={1}
|
|
|
|
style={{stroke: "#ccc"}} />
|
2015-10-28 23:22:21 +00:00
|
|
|
<rect key="iqr"
|
|
|
|
x={x1}
|
|
|
|
y={p75Y}
|
|
|
|
width={width}
|
|
|
|
height={p25Y - p75Y}
|
|
|
|
strokeWidth={1}
|
2015-10-29 00:05:59 +00:00
|
|
|
style={{fill: "#f0f0f0", stroke: "#888"}} />
|
2015-10-28 23:22:21 +00:00
|
|
|
<line key="median"
|
|
|
|
x1={x1}
|
|
|
|
x2={x2}
|
|
|
|
y1={medianY}
|
|
|
|
y2={medianY}
|
2015-10-29 00:05:59 +00:00
|
|
|
strokeWidth={2}
|
2015-10-28 23:22:21 +00:00
|
|
|
style={{stroke: "#444"}} />
|
|
|
|
<line key="min"
|
2015-10-29 00:05:59 +00:00
|
|
|
x1={x1+2}
|
|
|
|
x2={x2-2}
|
2015-10-28 23:22:21 +00:00
|
|
|
y1={minY}
|
|
|
|
y2={minY}
|
|
|
|
strokeWidth={1}
|
2015-10-29 00:05:59 +00:00
|
|
|
style={{stroke: "#aaa"}} />
|
2015-10-28 23:22:21 +00:00
|
|
|
</g>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<div className="boxplot">
|
2015-10-31 19:55:38 +00:00
|
|
|
<svg>
|
2015-10-28 23:22:21 +00:00
|
|
|
{this.props.points.map(renderBox)}
|
|
|
|
</svg>
|
2015-10-28 19:42:43 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-29 00:35:21 +00:00
|
|
|
var LineChart = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
var points = this.props.points,
|
2015-10-31 19:55:38 +00:00
|
|
|
maxHeight = 140,
|
2015-10-29 00:35:21 +00:00
|
|
|
padding = 5,
|
|
|
|
colors = {processed: "#46f", errors: "#f64"};
|
|
|
|
|
|
|
|
var min = 0, max;
|
|
|
|
points.map(function(point) {
|
|
|
|
if (max === undefined || point.processed > max) {
|
|
|
|
max = point.processed;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var makePath = function(points, key) {
|
|
|
|
if (max === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var path = points.map(function(point, i) {
|
|
|
|
var val = point[key];
|
|
|
|
var width = 15;
|
|
|
|
var x = i * width;
|
|
|
|
var y = maxHeight - Math.round((val-min)/(max-min) * maxHeight) + padding;
|
|
|
|
|
|
|
|
if (i === 0) {
|
|
|
|
return "M"+x+","+y;
|
|
|
|
} else {
|
|
|
|
return "L"+x+","+y;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<path
|
|
|
|
d={path.join(" ")}
|
|
|
|
strokeWidth={2}
|
|
|
|
style={{stroke: colors[key], fill: "transparent"}} />
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="linechart">
|
2015-10-31 19:55:38 +00:00
|
|
|
<svg>
|
2015-10-29 00:35:21 +00:00
|
|
|
{makePath(points, "processed")}
|
|
|
|
{makePath(points, "errors")}
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-28 19:42:43 +00:00
|
|
|
ReactDOM.render(<Dashboard />, document.getElementById("app"));
|