Fix up Host drilldown page

This gives the host drilldown page awareness of the host id that it
should scope its queries to. Also makes eslint happier because assigned a
magic number.
pull/155/head
Tim Raymond 2016-09-29 16:49:58 -07:00
parent 7a78625dcb
commit a0a01cc2e4
2 changed files with 18 additions and 10 deletions

View File

@ -8,35 +8,42 @@ const RefreshingLineGraph = AutoRefresh(LineGraph);
export const HostPage = React.createClass({ export const HostPage = React.createClass({
propTypes: { propTypes: {
sources: PropTypes.arrayOf(PropTypes.shape()), source: PropTypes.shape({
links: PropTypes.shape({
proxy: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
params: PropTypes.shape({
hostID: PropTypes.string.isRequired,
}).isRequired,
}, },
render() { render() {
const autoRefreshMs = 15000; const autoRefreshMs = 15000;
const source = this.props.sources[0].links.proxy; const source = this.props.source.links.proxy;
const queries = [ const queries = [
{ {
text: `SELECT "usage_user" FROM "telegraf"."default"."cpu" WHERE time > now() - 15m`, text: `SELECT "usage_user" FROM "telegraf"."default"."cpu" WHERE host = '${this.props.params.hostID}' AND time > now() - 15m`,
name: 'CPU', name: 'CPU',
}, },
{ {
text: `SELECT "used_percent" FROM "telegraf"."default"."mem" WHERE time > now() - 15m`, text: `SELECT "used_percent" FROM "telegraf"."default"."mem" WHERE host = '${this.props.params.hostID}' AND time > now() - 15m`,
name: "Memory", name: "Memory",
}, },
{ {
text: `SELECT "load1" FROM "telegraf"."default"."system" WHERE time > now() - 15m`, text: `SELECT "load1" FROM "telegraf"."default"."system" WHERE host = '${this.props.params.hostID}' AND time > now() - 15m`,
name: "Load", name: "Load",
}, },
{ {
text: `SELECT "bytes_recv", "bytes_sent" FROM "telegraf"."default"."net" WHERE time > now() - 15m`, text: `SELECT "bytes_recv", "bytes_sent" FROM "telegraf"."default"."net" WHERE host = '${this.props.params.hostID}' AND time > now() - 15m`,
name: "Network", name: "Network",
}, },
{ {
text: `SELECT "io_time" FROM "telegraf"."default"."diskio" WHERE time > now() - 15m`, text: `SELECT "io_time" FROM "telegraf"."default"."diskio" WHERE host = '${this.props.params.hostID}' AND time > now() - 15m`,
name: "Disk IO", name: "Disk IO",
}, },
{ {
text: `SELECT "used_percent" FROM "telegraf"."default"."disk" WHERE time > now() - 15m`, text: `SELECT "used_percent" FROM "telegraf"."default"."disk" WHERE host = '${this.props.params.hostID}' AND time > now() - 15m`,
name: "Disk usage", name: "Disk usage",
}, },
]; ];

View File

@ -30,17 +30,18 @@ export const HostsPage = React.createClass({
db: 'telegraf', db: 'telegraf',
}).then((resp) => { }).then((resp) => {
const hosts = {}; const hosts = {};
const precision = 100;
resp.data.results[0].series.forEach((s) => { resp.data.results[0].series.forEach((s) => {
const meanIndex = s.columns.findIndex((col) => col === 'mean'); const meanIndex = s.columns.findIndex((col) => col === 'mean');
hosts[s.tags.host] = { hosts[s.tags.host] = {
name: s.tags.host, name: s.tags.host,
cpu: (Math.round(s.values[0][meanIndex] * 100) / 100).toFixed(2), cpu: (Math.round(s.values[0][meanIndex] * precision) / precision).toFixed(2),
}; };
}); });
resp.data.results[1].series.forEach((s) => { resp.data.results[1].series.forEach((s) => {
const meanIndex = s.columns.findIndex((col) => col === 'mean'); const meanIndex = s.columns.findIndex((col) => col === 'mean');
hosts[s.tags.host].load = (Math.round(s.values[0][meanIndex] * 100) / 100).toFixed(2); hosts[s.tags.host].load = (Math.round(s.values[0][meanIndex] * precision) / precision).toFixed(2);
}); });
this.setState({ this.setState({