-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
58 lines (43 loc) · 1.76 KB
/
server.py
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
from flask import Flask, render_template, request
from flask.logging import default_handler
import requests
import logging
import time
import config
import gpu_helper
from statistics import get_stats_df, get_time_str
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
formatter = logging.Formatter(
fmt='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
app = Flask(__name__)
app.logger.setLevel(logging.INFO)
default_handler.setFormatter(formatter)
@app.route('/')
def index():
return render_template('index.html', stats_time=get_time_str())
@app.route('/gpu_usage')
def gpu_usage():
show_all = (request.args.get('show_all', '0') == '1')
infos = {server: gpu_helper.get_remote_info(server) for server in config.servers}
return render_template('usage.html', infos=infos, show_all=show_all)
@app.route('/statistics')
def statistics():
df = get_stats_df()
columns=['Name', 'GPU Time', 'Used Power [Wh]', 'Generated CO2 [kg]', 'Trees * year to offset', 'Avg. Util [%]']
return df.to_html(index=False, table_id='stats_table', classes='tablesorter', columns=columns)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--port', type=int, default=5000, help="port to run server on")
parser.add_argument('--host', default='0.0.0.0', help="which host to listen on")
parser.add_argument('--config', help="json config file")
args = parser.parse_args()
if args.config is not None:
config.update_config(args.config)
gpu_helper.setup()
app.run(debug=True, host=args.host, port=args.port)