Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
294 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# system-dashboard | ||
Minimalist Win/OSX/Linux System Dashboard using Flask and Freeboard | ||
Minimalist Win/OSX/Linux System Dashboard using Flask and Freeboard. This tool was created extremely quickly (less than a couple hours) as a "Hello World" for both technologies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from flask import Flask | ||
from flask_cors import CORS | ||
from flask_cors import cross_origin | ||
import json | ||
import os | ||
import psutil | ||
import time | ||
|
||
app = Flask(__name__) | ||
CORS(app) # Necessary since API is running locally | ||
|
||
period = 1 | ||
|
||
# Disable Flask console messages: http://stackoverflow.com/a/18379764 | ||
import logging | ||
log = logging.getLogger('werkzeug') | ||
log.setLevel(logging.ERROR) | ||
|
||
@cross_origin() | ||
@app.route('/') | ||
def index(): | ||
|
||
disk_write_data_start = psutil.disk_io_counters(perdisk=False) | ||
io_data_start = psutil.net_io_counters() | ||
|
||
time.sleep(period) | ||
|
||
cpu_data = psutil.cpu_percent(interval=None) | ||
ram_data = psutil.virtual_memory() | ||
disk_data = psutil.disk_usage('/') | ||
disk_write_data = psutil.disk_io_counters(perdisk=False) | ||
io_data = psutil.net_io_counters() | ||
|
||
data = { | ||
'cpu': { | ||
'percent': cpu_data | ||
}, | ||
'ram': { | ||
'percent': ram_data[2], | ||
'total': ram_data[0], | ||
'used': ram_data[3] | ||
}, | ||
'disk': { | ||
'total': disk_data[0], | ||
'used': disk_data[1], | ||
'percent': disk_data[3], | ||
'read_bytes_sec': (disk_write_data[2] - disk_write_data_start[2]) \ | ||
/ period, | ||
'write_bytes_sec': (disk_write_data[3] - disk_write_data_start[3]) \ | ||
/ period | ||
}, | ||
'io': { | ||
'sent_bytes_sec': (io_data[0] - io_data_start[0]) / period, | ||
'received_bytes_sec': (io_data[1] - io_data_start[1]) / period | ||
} | ||
} | ||
|
||
return json.dumps(data) | ||
|
||
if __name__ == "__main__": | ||
print "System API up at http://localhost:5002" | ||
PORT = int(os.getenv('PORT', 5002)) | ||
app.run(port=PORT, threaded=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
{ | ||
"version": 1, | ||
"allow_edit": true, | ||
"plugins": [], | ||
"panes": [ | ||
{ | ||
"width": 1, | ||
"row": { | ||
"3": 1 | ||
}, | ||
"col": { | ||
"3": 1 | ||
}, | ||
"col_width": 1, | ||
"widgets": [ | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"size": "regular", | ||
"value": "datasources[\"Clock\"][\"time_string_value\"]", | ||
"animate": true | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "Disk", | ||
"width": 1, | ||
"row": { | ||
"3": 1 | ||
}, | ||
"col": { | ||
"3": 3 | ||
}, | ||
"col_width": 1, | ||
"widgets": [ | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"title": "Bytes Read / Sec", | ||
"size": "regular", | ||
"value": "(datasources[\"System Dashboard Flask\"][\"disk\"][\"read_bytes_sec\"] / 1000000).toFixed(3)", | ||
"sparkline": true, | ||
"animate": false, | ||
"units": "MB" | ||
} | ||
}, | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"title": "Bytes Written / Sec", | ||
"size": "regular", | ||
"value": "(datasources[\"System Dashboard Flask\"][\"disk\"][\"write_bytes_sec\"] / 1000000).toFixed(3)", | ||
"sparkline": true, | ||
"animate": false, | ||
"units": "MB" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "I/O", | ||
"width": 1, | ||
"row": { | ||
"3": 1 | ||
}, | ||
"col": { | ||
"3": 2 | ||
}, | ||
"col_width": 1, | ||
"widgets": [ | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"title": "Bytes Sent / Sec", | ||
"size": "regular", | ||
"value": "(datasources[\"System Dashboard Flask\"][\"io\"][\"sent_bytes_sec\"] / 1000000).toFixed(3)", | ||
"sparkline": true, | ||
"animate": false, | ||
"units": "MB" | ||
} | ||
}, | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"title": "Bytes Received / Sec", | ||
"size": "regular", | ||
"value": "(datasources[\"System Dashboard Flask\"][\"io\"][\"received_bytes_sec\"] / 1000000).toFixed(3)", | ||
"sparkline": true, | ||
"animate": false, | ||
"units": "MB" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "CPU", | ||
"width": 1, | ||
"row": { | ||
"3": 5 | ||
}, | ||
"col": { | ||
"3": 1 | ||
}, | ||
"col_width": 1, | ||
"widgets": [ | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"size": "big", | ||
"value": "datasources[\"System Dashboard Flask\"][\"cpu\"][\"percent\"].toFixed(1)", | ||
"sparkline": true, | ||
"animate": false, | ||
"units": "%" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "RAM", | ||
"width": 1, | ||
"row": { | ||
"3": 11 | ||
}, | ||
"col": { | ||
"3": 1 | ||
}, | ||
"col_width": 1, | ||
"widgets": [ | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"size": "big", | ||
"value": "datasources[\"System Dashboard Flask\"][\"ram\"][\"percent\"].toFixed(1)", | ||
"sparkline": true, | ||
"animate": false, | ||
"units": "%" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "Disk Usage", | ||
"width": 1, | ||
"row": { | ||
"3": 11 | ||
}, | ||
"col": { | ||
"3": 3 | ||
}, | ||
"col_width": "1", | ||
"widgets": [ | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"title": "Space Used", | ||
"size": "regular", | ||
"value": "(datasources[\"System Dashboard Flask\"][\"disk\"][\"used\"] / (1000 * 1024 * 1024)).toFixed(2)", | ||
"animate": true, | ||
"units": "GB" | ||
} | ||
}, | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"title": "Disk Total", | ||
"size": "regular", | ||
"value": "(datasources[\"System Dashboard Flask\"][\"disk\"][\"total\"] / (1000 * 1024 * 1024)).toFixed(2)", | ||
"animate": true, | ||
"units": "GB" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"width": 1, | ||
"row": { | ||
"3": 11 | ||
}, | ||
"col": { | ||
"3": 2 | ||
}, | ||
"col_width": 1, | ||
"widgets": [ | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"title": "RAM Used", | ||
"size": "regular", | ||
"value": "(datasources[\"System Dashboard Flask\"][\"ram\"][\"used\"] / (1000 * 1024 * 1024)).toFixed(2)", | ||
"sparkline": false, | ||
"animate": false, | ||
"units": "GB" | ||
} | ||
}, | ||
{ | ||
"type": "text_widget", | ||
"settings": { | ||
"title": "RAM Total", | ||
"size": "regular", | ||
"value": "(datasources[\"System Dashboard Flask\"][\"ram\"][\"total\"] / (1000 * 1024 * 1024)).toFixed(2)", | ||
"sparkline": false, | ||
"animate": true, | ||
"units": "GB" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"datasources": [ | ||
{ | ||
"name": "System Dashboard Flask", | ||
"type": "JSON", | ||
"settings": { | ||
"url": "http://127.0.0.1:5002", | ||
"use_thingproxy": false, | ||
"refresh": 1, | ||
"method": "GET" | ||
} | ||
}, | ||
{ | ||
"name": "Clock", | ||
"type": "clock", | ||
"settings": { | ||
"refresh": 1 | ||
} | ||
} | ||
], | ||
"columns": 3 | ||
} |