summaryrefslogtreecommitdiff
path: root/app/client/system/system.component.js
blob: 7428c220bedb6c3e3893fb4b35a7c1e06e43ed6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import Group from '../common/group.component'
import Param from '../common/param.component'

import * as systemActions from './system.actions'

class System extends Component {
  constructor(props){
    super()
  }
  render(){
    const { site, server, relay, rpc, actions } = this.props
    return (
      <div className='system'>
        <div className='heading'>
          <h2>{site.name} System</h2>
        </div>

        <div className='row params'>
          <Group title="Status">
            <Param title='Server'>{server.status}</Param>
            {server.error &&
              <Param title='Server error'>{server.error.message}</Param>
            }
            <Param title='Relay'>{relay.status}</Param>
            <Param title='RPC'>{rpc.status}</Param>
            <Param title='CPU'>{rpc.cpu_cmd}</Param>
            <Param title='GPU'>{rpc.gpu_cmd}</Param>
            <Param title='Current Task'>train samplernn</Param>
          </Group>
          <Group title="Diagnostics">
            <Param title='Check GPU'>
              <button onClick={() => actions.run('nvidia-smi')}>nvidia-smi</button>
            </Param>
            <Param title='List processes'>
              <button onClick={() => actions.run('ps')}>ps</button>
            </Param>
            <Param title='List users'>
              <button onClick={() => actions.run('w')}>w</button>
            </Param>
          </Group>
        </div>
        {this.renderCommandOutput()}
      </div>
    )
  }
  renderCommandOutput(){
    const { cmd } = this.props
    let output
    if (cmd.loading) {
      output = 'Loading: ' + cmd.name
    }
    else if (cmd.loaded) {
      if (cmd.error) {
        output = 'Error: ' + cmd.name + '\n\n' + JSON.stringify(cmd.error, null, 2)
      } else {
        output = cmd.stdout
        if (cmd.stderr) {
          output += '\n\n_________________________________\n\n'
          output += cmd.stderr
        }
      }
    }
    return (
      <div>
        <div className='screen'>{output}</div>
      </div>
    )
  }
}
const mapStateToProps = state => ({
  ...state.system
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: bindActionCreators(systemActions, dispatch)
})

export default connect(mapStateToProps, mapDispatchToProps)(System)