diff --git a/ui/src/hosts/apis/index.js b/ui/src/hosts/apis/index.js index 584ca4b5a7..8cef7d3a8e 100644 --- a/ui/src/hosts/apis/index.js +++ b/ui/src/hosts/apis/index.js @@ -2,15 +2,19 @@ import {proxy} from 'utils/queryUrlGenerator' import AJAX from 'utils/ajax' import _ from 'lodash' -export function getCpuAndLoadForHosts(proxyLink, telegrafDB) { +export function getCpuAndLoadForHosts( + proxyLink, + telegrafDB, + uptimeInverval = '1m' +) { return proxy({ source: proxyLink, query: `SELECT mean("usage_user") FROM cpu WHERE "cpu" = 'cpu-total' AND time > now() - 10m GROUP BY host; SELECT mean("load1") FROM "system" WHERE time > now() - 10m GROUP BY host; - SELECT non_negative_derivative(mean(uptime)) AS deltaUptime FROM "system" WHERE time > now() - 10m GROUP BY host, time(1m) fill(0); + SELECT non_negative_derivative(mean(uptime)) AS deltaUptime FROM "system" WHERE time > now() - 10m GROUP BY host, time(${uptimeInverval}) fill(0); SELECT mean("Percent_Processor_Time") FROM win_cpu WHERE time > now() - 10m GROUP BY host; SELECT mean("Processor_Queue_Length") FROM win_system WHERE time > now() - 10s GROUP BY host; - SELECT non_negative_derivative(mean("System_Up_Time")) AS winDeltaUptime FROM win_system WHERE time > now() - 10m GROUP BY host, time(1m) fill(0); + SELECT non_negative_derivative(mean("System_Up_Time")) AS winDeltaUptime FROM win_system WHERE time > now() - 10m GROUP BY host, time(${uptimeInverval}) fill(0); SHOW TAG VALUES WITH KEY = "host";`, db: telegrafDB, }).then(resp => { diff --git a/ui/src/hosts/containers/HostsPage.js b/ui/src/hosts/containers/HostsPage.js index b08e324448..50783bc6ea 100644 --- a/ui/src/hosts/containers/HostsPage.js +++ b/ui/src/hosts/containers/HostsPage.js @@ -5,6 +5,7 @@ import HostsTable from 'src/hosts/components/HostsTable' import SourceIndicator from 'shared/components/SourceIndicator' import {getCpuAndLoadForHosts, getLayouts, getAppsForHosts} from '../apis' +import {getEnv} from 'src/shared/apis/env' class HostsPage extends Component { constructor(props) { @@ -17,10 +18,13 @@ class HostsPage extends Component { } } - componentDidMount() { - const {source, addFlashMessage} = this.props + async componentDidMount() { + const {source: {links, telegraf}, addFlashMessage} = this.props + + const {data: {telegrafSystemInterval}} = await getEnv(links.env) + Promise.all([ - getCpuAndLoadForHosts(source.links.proxy, source.telegraf), + getCpuAndLoadForHosts(links.proxy, telegraf, telegrafSystemInterval), getLayouts(), new Promise(resolve => { this.setState({hostsLoading: true}) @@ -32,7 +36,7 @@ class HostsPage extends Component { hosts, hostsLoading: false, }) - getAppsForHosts(source.links.proxy, hosts, layouts, source.telegraf) + getAppsForHosts(links.proxy, hosts, layouts, telegraf) .then(newHosts => { this.setState({ hosts: newHosts, @@ -57,7 +61,7 @@ class HostsPage extends Component { }) // TODO: this isn't reachable at the moment, because getCpuAndLoadForHosts doesn't fail when it should. // (like with a bogus proxy link). We should provide better messaging to the user in this catch after that's fixed. - console.error(reason) // eslint-disable-line no-console + console.error(reason) }) } diff --git a/ui/src/shared/apis/env.js b/ui/src/shared/apis/env.js new file mode 100644 index 0000000000..96210773f7 --- /dev/null +++ b/ui/src/shared/apis/env.js @@ -0,0 +1,13 @@ +import AJAX from 'src/utils/ajax' + +export const getEnv = async url => { + try { + return await AJAX({ + method: 'GET', + url, + }) + } catch (error) { + console.error(error) + throw error + } +}