Sorry, this page isn't available.
The link you followed may be broken, or the page may have been removed.
@@ -153,8 +82,7 @@ ReactDOM.render(
-
-
+
,
diff --git a/js/components/Agent.jsx b/js/components/Agent.jsx
new file mode 100644
index 0000000..88557e7
--- /dev/null
+++ b/js/components/Agent.jsx
@@ -0,0 +1,269 @@
+import React from 'react'
+import { APIserver } from './../app'
+
+export class Agent extends React.Component {
+ constructor(props) {
+ super(props);
+ this.loadDataFromServer = this.loadDataFromServer.bind(this);
+ this.state = {
+ data: [],
+ }
+ }
+ loadDataFromServer() {
+ let url = APIserver+'/agents/'+this.props.params.uid;
+ $.ajax({
+ url: url,
+ dataType: 'json',
+ cache: false,
+ success: function(data) {
+ this.setState({data: data});
+ }.bind(this),
+ error: function(xhr, status, err) {
+ console.error(url, status, err.toString());
+ }.bind(this),
+ })
+ }
+ componentDidMount() {
+ this.loadDataFromServer();
+ this.intervalID = setInterval(this.loadDataFromServer, 5000);
+ }
+ componentWillUnmount() {
+ clearInterval(this.intervalID);
+ }
+ render() {
+ return (
+
+ )
+ }
+}
+
+const AgentDetails = (props) => {
+ return (
+
+
{props.data.host_name}
+ {' '}
+
+
+ )
+}
+
+const AgentStatus = (props) => {
+ const baseStyle = {
+ padding: '0.4rem',
+ borderRadius: '0.2rem',
+ margin: '0.2rem',
+ textTransform: 'uppercase',
+ fontWeight: 600,
+ }
+ const styles = {
+ online: {
+ ...baseStyle,
+ color:'#fff',
+ backgroundColor:'#88cc88',
+ },
+ offline: {
+ ...baseStyle,
+ color:'#626466',
+ backgroundColor:'#f5f5f5',
+ },
+ }
+ return (
+
{props.status}
+ )
+}
+
+class AgentCharts extends React.Component {
+ constructor(props) {
+ super(props);
+ this.loadDataFromServer = this.loadDataFromServer.bind(this);
+ this.state = {
+ data: [],
+ }
+ }
+ loadDataFromServer() {
+ $.ajax({
+ url: APIserver+'/events?uid='+this.props.uid+'&policy_name=default_system_data',
+ dataType: 'json',
+ cache: false,
+ success: function(data) {
+ this.setState({data: data});
+ }.bind(this),
+ error: function(xhr, status, err) {
+ console.error(this.props.url, status, err.toString());
+ }.bind(this),
+ })
+ }
+ componentDidMount() {
+ this.loadDataFromServer();
+ this.intervalID = setInterval(this.loadDataFromServer, this.props.pollInterval);
+ }
+ componentWillUnmount() {
+ clearInterval(this.intervalID);
+ }
+ render() {
+ return (
+
+
+
+
+ )
+ }
+}
+
+class CPUChart extends React.Component {
+ constructor(props) {
+ super(props);
+ this._renderChart = this._renderChart.bind(this);
+ }
+ _renderChart(d) {
+ let x = ['x'];
+ let cpu = ['cpu'];
+ if (d !== null) {
+ for (let i = 0; i < d.length; i++) {
+ x[i+1] = new Date(d[i].Time);
+ cpu[i+1] = d[i].Data.system.cpu.userspace;
+ }
+ }
+ this.chart = c3.generate({
+ size: {
+ // in pixels
+ height: 150,
+ },
+ data: {
+ x: 'x',
+ columns: [x, cpu],
+ types:{
+ cpu: 'area-spline',
+ },
+ },
+ point: {
+ show: false,
+ },
+ axis: {
+ y: {
+ padding: {
+ top: 0,
+ bottom: 0,
+ },
+ tick: {
+ count: 5,
+ },
+ max: 100,
+ min: 0,
+ },
+ x: {
+ type: 'timeseries',
+ tick: {
+ format: '%I:%M:%S', // format string is also available for timeseries data
+ },
+ },
+ },
+ legend: {
+ show: false,
+ },
+ bindto: '#cpu-chart',
+ });
+ }
+ componentDidMount() {
+ this._renderChart(this.props.data);
+ }
+ componentWillReceiveProps(newProps) {
+ this._renderChart(newProps.data);
+ // this.chart.load(newProps.data); // TODO: need to pass modified data to c3
+ }
+ render() {
+ const baseStyle = {
+ margin: '0.6rem 0',
+ }
+ return (
+
+ )
+ }
+}
+
+class RAMChart extends React.Component {
+ constructor(props) {
+ super(props);
+ }
+ _renderChart(d) {
+ let x = ['x'];
+ let ram = ['ram'];
+ if (d !== null) {
+ for (let i = 0; i < d.length; i++) {
+ x[i+1] = new Date(d[i].Time);
+ let m = d[i].Data.system.memory;
+ let used = m.used-m.cached-m.buffers;
+ let total = m.total;
+ let p = used/total * 100;
+ ram[i+1] = p.toFixed(2);
+ }
+ }
+ this.chart = c3.generate({
+ size: {
+ // in pixels
+ height: 150,
+ },
+ data: {
+ x: 'x',
+ columns:[x, ram],
+ types:{
+ ram: 'area-spline',
+ },
+ },
+ point: {
+ show: false,
+ },
+ axis: {
+ y: {
+ padding: {
+ top: 0,
+ bottom: 0,
+ },
+ tick: {
+ count: 5,
+ },
+ max: 100,
+ min: 0,
+ },
+ x: {
+ type: 'timeseries',
+ tick: {
+ format: '%I:%M:%S', // format string is also available for timeseries data
+ },
+ },
+ },
+ legend: {
+ show: false,
+ },
+ color: {
+ pattern: ['#ff7f0e'],
+ },
+ bindto: '#ram-chart',
+ });
+ }
+ componentDidMount() {
+ this._renderChart(this.props.data);
+ }
+ componentWillReceiveProps(newProps) {
+ this._renderChart(newProps.data);
+ // this.chart.load(newProps.data); // TODO: need to pass modified data to c3
+ }
+ render() {
+ const baseStyle = {
+ margin: '0.6rem 0',
+ }
+ return (
+
+ )
+ }
+}
diff --git a/js/components/FilterableAgentTable.jsx b/js/components/FilterableAgentTable.jsx
index e2333d8..f9c1e28 100644
--- a/js/components/FilterableAgentTable.jsx
+++ b/js/components/FilterableAgentTable.jsx
@@ -1,6 +1,7 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { Link } from 'react-router'
+import { APIserver } from './../app'
export class FilterableAgentTable extends React.Component {
constructor(props) {
@@ -18,7 +19,7 @@ export class FilterableAgentTable extends React.Component {
}
render() {
return (
-
+
AGENTS
-
-
-
{' '}
- Only show OFFLINE agents
+ Only show offline agents
@@ -80,53 +77,154 @@ class AgentSearchBar extends React.Component {
}
}
-class AgentTable extends React.Component {
- render() {
- var rows = [];
- this.props.agents.forEach(
- (agent) => {
- if ((agent.host_name.toLowerCase().indexOf(this.props.filterText.toLowerCase()) === -1) || ((agent.status == 'online') && this.props.offlineOnly)) {
- return
- }
- rows.push( )
+const AgentGrid = (props) => {
+ let rows = [];
+ props.agents.forEach(
+ (agent) => {
+ if ((agent.host_name.toLowerCase().indexOf(props.filterText.toLowerCase()) === -1) || ((agent.status == 'online') && props.offlineOnly)) {
+ return
}
- );
- return (
-
-
-
- Host
- Status
-
-
- {rows}
-
- )
- }
+ rows.push( )
+ }
+ );
+ return (
+
+ {rows}
+
+ )
}
-class AgentRow extends React.Component {
+class AgentBox extends React.Component {
render() {
- var agentLink = '/agents/'+this.props.agent.uid;
- var styles = {
+ let agentLink = '/agents/'+this.props.agent.uid;
+ const baseStyle = {
+ padding: '0.4rem',
+ borderRadius: '0.2rem',
+ margin: '0.2rem',
+ }
+ const styles = {
online: {
- padding: '0.4rem',
- color:'#fff',
- backgroundColor:'#6cc644',
- borderRadius: '0.2rem',
+ ...baseStyle,
+ color:'#004400',
+ backgroundColor:'#88cc88',
},
offline: {
- padding: '0.4rem',
- color:'#fff',
- backgroundColor:'#d32f2f',
- borderRadius: '0.2rem',
+ ...baseStyle,
+ color:'#626466',
+ backgroundColor:'#f5f5f5',
+ },
+ hostname: {
+ fontWeight: '700',
+ width:'100%',
+ borderRadius:'0.2rem',
},
};
return(
-
- {this.props.agent.host_name}
- {(this.props.agent.status === 'online')?ONLINE :OFFLINE }
-
+
+
+
{this.props.agent.host_name}
+
+
+
)
}
}
+
+class SummarizedSystemData extends React.Component {
+ constructor(props) {
+ super(props);
+ this.loadDataFromServer = this.loadDataFromServer.bind(this);
+ this.state = {
+ data: [],
+ }
+ }
+ loadDataFromServer() {
+ $.ajax({
+ url: APIserver+'/events?uid='+this.props.uid+'&policy_name=default_system_data',
+ dataType: 'json',
+ cache: false,
+ success: function(data) {
+ this.setState({data: data});
+ }.bind(this),
+ error: function(xhr, status, err) {
+ console.error(this.props.url, status, err.toString());
+ }.bind(this),
+ })
+ }
+ componentDidMount() {
+ this.loadDataFromServer();
+ this.intervalID = setInterval(this.loadDataFromServer, this.props.pollInterval);
+ }
+ componentWillUnmount() {
+ clearInterval(this.intervalID);
+ }
+ render() {
+ return (
+
+
+
+
+
+ )
+ }
+}
+
+const RAMData = (props) => {
+ if (props.status === 'offline' ||props.data === null || props.data.length === 0) {
+ return RAM NA
+ } else {
+ let m = props.data[props.data.length-1].Data.system.memory;
+ // We are not counting cached and buffer memory in used memory.
+ // htop does the same thing.
+ // check http://askubuntu.com/a/369589 and http://www.linuxatemyram.com/
+ // TODO: Should we move this logic to the API?
+ let used = m.used-m.cached-m.buffers;
+ let total = m.total;
+ let p = used/total * 100;
+ return RAM {p.toFixed(2)} %
+ }
+}
+
+const CPUData = (props) => {
+ if (props.status === 'offline' ||props.data === null || props.data.length === 0) {
+ return CPU NA
+ } else {
+ let c = props.data[props.data.length-1].Data.system.cpu;
+ return CPU {c.userspace.toFixed(2)} %
+ }
+}
+
+const DiskData = (props) => {
+ if (props.status === 'offline' ||props.data === null || props.data.length === 0) {
+ return (
+
+
+ Disk NA
+
+
+ )
+ } else {
+ let d = props.data[props.data.length-1].Data.system.disk;
+ var rows = [];
+ for (let k in d) {
+ if (!d.hasOwnProperty(k)) {
+ continue;
+ }
+ rows.push()
+ }
+ return (
+
+ {rows}
+
+ )
+ }
+}
+
+const DiskPartitionData = (props) => {
+ let p = props.data.percentage_used
+ return (
+
+ {props.name} {p.slice(0,p.length-1)} %
+
+ )
+}
diff --git a/package.json b/package.json
index 9642b5b..84f724c 100644
--- a/package.json
+++ b/package.json
@@ -19,19 +19,20 @@
},
"homepage": "https://github.com/codeignition/muzzle#readme",
"dependencies": {
- "react": "^0.14.0",
+ "history": "^1.12.5",
+ "react": "^0.14.2",
"react-dom": "^0.14.0",
- "react-router": "^1.0.0-rc2"
+ "react-router": "^1.0.0-rc4"
},
"devDependencies": {
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"css-loader": "^0.19.0",
- "eslint": "^1.6.0",
+ "eslint": "^1.7.3",
"eslint-loader": "^1.0.0",
- "eslint-plugin-react": "^3.4.2",
+ "eslint-plugin-react": "^3.6.3",
"style-loader": "^0.12.4",
"webpack": "^1.12.2",
- "webpack-dev-server": "^1.12.0"
+ "webpack-dev-server": "^1.12.1"
}
}
diff --git a/webpack.config.js b/webpack.config.js
index 4ef203e..d54c025 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,5 +1,5 @@
module.exports = {
- entry: './js/app.jsx',
+ entry: ['./js/app.jsx'],
output: {
filename: './js/bundle.js'
},