summaryrefslogtreecommitdiff
path: root/app/client/system/system.component.js
blob: 00c53959952e46cfc0beadf14c647dbd26778f23 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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'
import * as taskActions from '../task/task.actions'

const cpu_test_task = {
  id: 1073,
  activity: 'train',
  library: 'test',
  dataset: 'test',
  epochs: 1,
  opt: {}
}
const gpu_test_task = {

}

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'>
          <div className='column'>
            <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.system.run('nvidia-smi')}>nvidia-smi</button>
              </Param>
              <Param title='List processes'>
                <button onClick={() => actions.system.run('ps')}>ps</button>
              </Param>
              <Param title='List users'>
                <button onClick={() => actions.system.run('w')}>w</button>
              </Param>
              <Param title='Disk free space'>
                <button onClick={() => actions.system.run('df')}>df</button>
              </Param>
            </Group>
            <Group title="Test">
              <Param title='CPU Test Task'>
                <button onClick={() => actions.task.start_task(cpu_test_task)}>Start</button>
                <button onClick={() => actions.task.stop_task(cpu_test_task)}>Stop</button>
              </Param>
              <Param title='GPU Test Task'>
                <button onClick={() => actions.task.start_task(gpu_test_task)}>Start</button>
                <button onClick={() => actions.task.stop_task(gpu_test_task)}>Stop</button>
              </Param>
            </Group>
          </div>
          {this.renderCommandOutput()}
        </div>
      </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: {
    system: bindActionCreators(systemActions, dispatch),
    task: bindActionCreators(taskActions, dispatch),
  },
})

export default connect(mapStateToProps, mapDispatchToProps)(System)