- generalize elixire adapter into http adapter - fix ping adapter not sending a tuple - add ServiceWorker.process_work to insert results into the database
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import React, { Component } from 'react';
|
|
|
|
import Service from './Service.js';
|
|
import './App.css';
|
|
|
|
// const ENDPOINT = 'https://elstatus.stayathomeserver.club/api/status'
|
|
const ENDPOINT = 'http://localhost:8069/api/status'
|
|
|
|
export default class App extends Component {
|
|
state = {
|
|
loading: true,
|
|
error: null,
|
|
metrics: null,
|
|
};
|
|
|
|
componentDidMount() {
|
|
fetch(ENDPOINT)
|
|
.then((resp) => resp.json())
|
|
.then((data) => {
|
|
this.setState({ metrics: data, loading: false });
|
|
})
|
|
.catch((error) => {
|
|
this.setState({ error: error.toString() });
|
|
})
|
|
}
|
|
|
|
render() {
|
|
const metrics = !this.state.metrics ? null : (
|
|
<div className="services">
|
|
{Object.entries(this.state.metrics.status)
|
|
.map(([name, info]) =>
|
|
<Service name={name} key={name}
|
|
graph={this.state.metrics.graph[name]}
|
|
{...info}
|
|
/>)
|
|
}
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<div className="dashboard">
|
|
<h1>elstatus</h1>
|
|
{this.state.loading ? <div>Loading metrics...</div> : null}
|
|
{this.state.error ? <div>Error: {this.state.error}</div> : null}
|
|
{metrics}
|
|
</div>
|
|
);
|
|
}
|
|
}
|