From a0a01cc2e48f068d19c944e0c72e45af2ab2efe1 Mon Sep 17 00:00:00 2001 From: Tim Raymond Date: Thu, 29 Sep 2016 16:49:58 -0700 Subject: [PATCH] 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. --- ui/src/hosts/containers/HostPage.js | 23 +++++++++++++++-------- ui/src/hosts/containers/HostsPage.js | 5 +++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ui/src/hosts/containers/HostPage.js b/ui/src/hosts/containers/HostPage.js index 4e16ec897..b88508a89 100644 --- a/ui/src/hosts/containers/HostPage.js +++ b/ui/src/hosts/containers/HostPage.js @@ -8,35 +8,42 @@ const RefreshingLineGraph = AutoRefresh(LineGraph); export const HostPage = React.createClass({ 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() { const autoRefreshMs = 15000; - const source = this.props.sources[0].links.proxy; + const source = this.props.source.links.proxy; 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', }, { - 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", }, { - 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", }, { - 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", }, { - 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", }, { - 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", }, ]; diff --git a/ui/src/hosts/containers/HostsPage.js b/ui/src/hosts/containers/HostsPage.js index bc39d4172..57fad907d 100644 --- a/ui/src/hosts/containers/HostsPage.js +++ b/ui/src/hosts/containers/HostsPage.js @@ -30,17 +30,18 @@ export const HostsPage = React.createClass({ db: 'telegraf', }).then((resp) => { const hosts = {}; + const precision = 100; resp.data.results[0].series.forEach((s) => { const meanIndex = s.columns.findIndex((col) => col === 'mean'); hosts[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) => { 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({