update service latency metric upon ws data

This commit is contained in:
slice 2018-07-13 12:29:46 -07:00
parent 7ec0ff79f8
commit 155f96c218
No known key found for this signature in database
GPG Key ID: 1508C19D7436A26D
1 changed files with 12 additions and 14 deletions

View File

@ -51,18 +51,23 @@ export default class App extends Component {
const [, name] = channel.split(':');
log('updating from channel:', channel);
const { metrics } = this.state;
const graph = metrics.graph[name].slice(1);
const newGraph = [data, ...graph];
log('adding data:', data);
this.setState((prevState, _props) => {
const clone = Object.assign({}, prevState.metrics);
clone.graph[name] = newGraph;
this.setState(({ metrics: oldMetrics }, _props) => {
const newMetrics = { ...oldMetrics };
newMetrics.graph[name] = newGraph;
const [, latency] = data;
newMetrics.status[name].latency = latency;
return {
metrics: clone,
metrics: newMetrics,
};
});
}
@ -128,19 +133,12 @@ export default class App extends Component {
return (
<div className="dashboard">
<h1>
elstatus
</h1>
<h1>elstatus</h1>
{this.state.loading ? (
<div>
Loading metrics...
</div>
<div>Loading metrics...</div>
) : null}
{this.state.error ? (
<div>
Error:
{this.state.error}
</div>
<div>Error: {this.state.error}</div>
) : null}
{metrics}
</div>