Add environment variables and links to chronograf
parent
2151413ece
commit
575fcaaeff
|
@ -2,19 +2,19 @@ import {proxy} from 'utils/queryUrlGenerator'
|
||||||
import AJAX from 'utils/ajax'
|
import AJAX from 'utils/ajax'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
export function getCpuAndLoadForHosts(
|
export const getCpuAndLoadForHosts = (
|
||||||
proxyLink,
|
proxyLink,
|
||||||
telegrafDB,
|
telegrafDB,
|
||||||
uptimeInverval = '1m'
|
telegrafSystemInterval
|
||||||
) {
|
) => {
|
||||||
return proxy({
|
return proxy({
|
||||||
source: proxyLink,
|
source: proxyLink,
|
||||||
query: `SELECT mean("usage_user") FROM cpu WHERE "cpu" = 'cpu-total' AND time > now() - 10m GROUP BY host;
|
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 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(${uptimeInverval}) fill(0);
|
SELECT non_negative_derivative(mean(uptime)) AS deltaUptime FROM "system" WHERE time > now() - 10m GROUP BY host, time(${telegrafSystemInterval}) fill(0);
|
||||||
SELECT mean("Percent_Processor_Time") FROM win_cpu WHERE time > now() - 10m GROUP BY host;
|
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 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(${uptimeInverval}) fill(0);
|
SELECT non_negative_derivative(mean("System_Up_Time")) AS winDeltaUptime FROM win_system WHERE time > now() - 10m GROUP BY host, time(${telegrafSystemInterval}) fill(0);
|
||||||
SHOW TAG VALUES WITH KEY = "host";`,
|
SHOW TAG VALUES WITH KEY = "host";`,
|
||||||
db: telegrafDB,
|
db: telegrafDB,
|
||||||
}).then(resp => {
|
}).then(resp => {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React, {PropTypes, Component} from 'react'
|
import React, {PropTypes, Component} from 'react'
|
||||||
|
import {connect} from 'react-redux'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
import HostsTable from 'src/hosts/components/HostsTable'
|
import HostsTable from 'src/hosts/components/HostsTable'
|
||||||
|
@ -19,12 +20,16 @@ class HostsPage extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const {source: {links, telegraf}, addFlashMessage} = this.props
|
const {source, links, addFlashMessage} = this.props
|
||||||
|
|
||||||
const {data: {telegrafSystemInterval}} = await getEnv(links.env)
|
const {telegrafSystemInterval} = await getEnv(links.environment)
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
getCpuAndLoadForHosts(links.proxy, telegraf, telegrafSystemInterval),
|
getCpuAndLoadForHosts(
|
||||||
|
source.links.proxy,
|
||||||
|
source.telegraf,
|
||||||
|
telegrafSystemInterval
|
||||||
|
),
|
||||||
getLayouts(),
|
getLayouts(),
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
this.setState({hostsLoading: true})
|
this.setState({hostsLoading: true})
|
||||||
|
@ -36,7 +41,7 @@ class HostsPage extends Component {
|
||||||
hosts,
|
hosts,
|
||||||
hostsLoading: false,
|
hostsLoading: false,
|
||||||
})
|
})
|
||||||
getAppsForHosts(links.proxy, hosts, layouts, telegraf)
|
getAppsForHosts(source.links.proxy, hosts, layouts, source.telegraf)
|
||||||
.then(newHosts => {
|
.then(newHosts => {
|
||||||
this.setState({
|
this.setState({
|
||||||
hosts: newHosts,
|
hosts: newHosts,
|
||||||
|
@ -101,6 +106,12 @@ class HostsPage extends Component {
|
||||||
|
|
||||||
const {func, shape, string} = PropTypes
|
const {func, shape, string} = PropTypes
|
||||||
|
|
||||||
|
const mapStateToProps = ({links}) => {
|
||||||
|
return {
|
||||||
|
links,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HostsPage.propTypes = {
|
HostsPage.propTypes = {
|
||||||
source: shape({
|
source: shape({
|
||||||
id: string.isRequired,
|
id: string.isRequired,
|
||||||
|
@ -111,7 +122,10 @@ HostsPage.propTypes = {
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
telegraf: string.isRequired,
|
telegraf: string.isRequired,
|
||||||
}),
|
}),
|
||||||
|
links: shape({
|
||||||
|
environment: string.isRequired,
|
||||||
|
}),
|
||||||
addFlashMessage: func,
|
addFlashMessage: func,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default HostsPage
|
export default connect(mapStateToProps, null)(HostsPage)
|
||||||
|
|
|
@ -61,13 +61,15 @@ export const getMeAsync = ({shouldResetMe = false} = {}) => async dispatch => {
|
||||||
const {
|
const {
|
||||||
data: me,
|
data: me,
|
||||||
auth,
|
auth,
|
||||||
logoutLink,
|
|
||||||
external,
|
|
||||||
users,
|
users,
|
||||||
organizations,
|
|
||||||
meLink,
|
meLink,
|
||||||
config,
|
config,
|
||||||
|
external,
|
||||||
|
logoutLink,
|
||||||
|
organizations,
|
||||||
|
environment,
|
||||||
} = await getMeAJAX()
|
} = await getMeAJAX()
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
meGetCompleted({
|
meGetCompleted({
|
||||||
me,
|
me,
|
||||||
|
@ -75,8 +77,16 @@ export const getMeAsync = ({shouldResetMe = false} = {}) => async dispatch => {
|
||||||
logoutLink,
|
logoutLink,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
linksReceived({external, users, organizations, me: meLink, config})
|
linksReceived({
|
||||||
|
external,
|
||||||
|
users,
|
||||||
|
organizations,
|
||||||
|
me: meLink,
|
||||||
|
config,
|
||||||
|
environment,
|
||||||
|
})
|
||||||
) // TODO: put this before meGetCompleted... though for some reason it doesn't fire the first time then
|
) // TODO: put this before meGetCompleted... though for some reason it doesn't fire the first time then
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(meGetFailed())
|
dispatch(meGetFailed())
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
import AJAX from 'src/utils/ajax'
|
import AJAX from 'src/utils/ajax'
|
||||||
|
|
||||||
|
const DEFAULT_ENVS = {
|
||||||
|
telegrafSystemInterval: '1m',
|
||||||
|
}
|
||||||
|
|
||||||
export const getEnv = async url => {
|
export const getEnv = async url => {
|
||||||
try {
|
try {
|
||||||
return await AJAX({
|
const {data} = await AJAX({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url,
|
url,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error('Error retreieving envs: ', error)
|
||||||
throw error
|
return DEFAULT_ENVS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,9 @@ const generateResponseWithLinks = (response, newLinks) => {
|
||||||
organizations,
|
organizations,
|
||||||
me: meLink,
|
me: meLink,
|
||||||
config,
|
config,
|
||||||
|
environment,
|
||||||
} = newLinks
|
} = newLinks
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...response,
|
...response,
|
||||||
auth: {links: auth},
|
auth: {links: auth},
|
||||||
|
@ -28,6 +30,7 @@ const generateResponseWithLinks = (response, newLinks) => {
|
||||||
organizations,
|
organizations,
|
||||||
meLink,
|
meLink,
|
||||||
config,
|
config,
|
||||||
|
environment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue