From 3de787d4570124f8bb833ed68975e20fc969c5a5 Mon Sep 17 00:00:00 2001 From: Jade McGough Date: Fri, 11 Nov 2016 02:49:14 -0800 Subject: [PATCH] provide a default group by time for host page --- canned/cpu.json | 2 +- canned/disk.json | 2 +- canned/docker.json | 4 ++-- canned/load.json | 2 +- canned/mem.json | 2 +- ui/src/hosts/components/LayoutRenderer.js | 10 +++++++--- ui/src/hosts/containers/HostPage.js | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/canned/cpu.json b/canned/cpu.json index 8be4344fa6..fd52ff290f 100644 --- a/canned/cpu.json +++ b/canned/cpu.json @@ -12,7 +12,7 @@ "name": "CPU Usage", "queries": [ { - "query": "SELECT \"usage_user\" FROM \"telegraf\"..\"cpu\"", + "query": "SELECT mean(\"usage_user\") FROM \"telegraf\"..\"cpu\"", "db": "telegraf", "rp": "autogen", "groupbys": [], diff --git a/canned/disk.json b/canned/disk.json index 3de871f70f..f90b66c54a 100644 --- a/canned/disk.json +++ b/canned/disk.json @@ -12,7 +12,7 @@ "name": "Disk used %", "queries": [ { - "query": "select used_percent from disk", + "query": "select mean(used_percent) from disk", "db": "telegraf", "rp": "autogen", "groupbys": [ diff --git a/canned/docker.json b/canned/docker.json index c4729b630f..d4c9439241 100644 --- a/canned/docker.json +++ b/canned/docker.json @@ -10,7 +10,7 @@ "i": "4c79cefb-5152-410c-9b88-74f9bff7ef22", "name": "Docker - Container CPU", "queries": [{ - "query": "SELECT \"usage_percent\" FROM \"docker_container_cpu\"", + "query": "SELECT mean(\"usage_percent\") FROM \"docker_container_cpu\"", "db": "telegraf", "rp": "autogen", "groupbys": ["\"container_name\""], @@ -25,7 +25,7 @@ "i": "4c79cefb-5152-410c-9b88-74f9bff7ef00", "name": "Docker - Container Memory", "queries": [{ - "query": "SELECT \"usage\" FROM \"docker_container_mem\"", + "query": "SELECT mean(\"usage\") FROM \"docker_container_mem\"", "db": "telegraf", "rp": "autogen", "groupbys": ["\"container_name\""], diff --git a/canned/load.json b/canned/load.json index e914a85620..9fc439bc1e 100644 --- a/canned/load.json +++ b/canned/load.json @@ -12,7 +12,7 @@ "name": "System Load", "queries": [ { - "query": "SELECT \"load1\" FROM \"telegraf\"..\"system\"", + "query": "SELECT mean(\"load1\") FROM \"telegraf\"..\"system\"", "db": "telegraf", "rp": "autogen", "groupbys": [], diff --git a/canned/mem.json b/canned/mem.json index cf77379057..03411d89de 100644 --- a/canned/mem.json +++ b/canned/mem.json @@ -12,7 +12,7 @@ "name": "Memory bytes used", "queries": [ { - "query": "SELECT \"used\", \"available\" FROM \"telegraf\"..\"mem\"", + "query": "SELECT mean(\"used\"), mean(\"available\") FROM \"telegraf\"..\"mem\"", "db": "telegraf", "rp": "autogen", "groupbys": [], diff --git a/ui/src/hosts/components/LayoutRenderer.js b/ui/src/hosts/components/LayoutRenderer.js index 515371334e..4c6675b820 100644 --- a/ui/src/hosts/components/LayoutRenderer.js +++ b/ui/src/hosts/components/LayoutRenderer.js @@ -8,7 +8,10 @@ const RefreshingLineGraph = AutoRefresh(LineGraph); export const LayoutRenderer = React.createClass({ propTypes: { - timeRange: PropTypes.string.isRequired, + timeRange: PropTypes.shape({ + defaultGroupBy: PropTypes.string.isRequired, + queryValue: PropTypes.string.isRequired, + }).isRequired, cells: PropTypes.arrayOf( PropTypes.shape({ queries: PropTypes.arrayOf( @@ -45,12 +48,13 @@ export const LayoutRenderer = React.createClass({ return this.props.cells.map((cell) => { const qs = cell.queries.map((q) => { let text = q.text; - text += ` where \"host\" = '${host}' and time > ${timeRange}`; + text += ` where \"host\" = '${host}' and time > ${timeRange.queryValue}`; if (q.wheres && q.wheres.length > 0) { text += ` and ${q.wheres.join(' and ')}`; } + text += ` group by time(${timeRange.defaultGroupBy})`; if (q.groupbys && q.groupbys.length > 0) { - text += ` group by ${q.groupbys.join(',')}`; + text += `,${q.groupbys.join(',')}`; } return Object.assign({}, q, { diff --git a/ui/src/hosts/containers/HostPage.js b/ui/src/hosts/containers/HostPage.js index 090a78a17e..14ac38b2f2 100644 --- a/ui/src/hosts/containers/HostPage.js +++ b/ui/src/hosts/containers/HostPage.js @@ -77,7 +77,7 @@ export const HostPage = React.createClass({ return (