-
-
Notifications
You must be signed in to change notification settings - Fork 952
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #552 from pierotofy/bughunt
Bug Fixes, Diagnostic Plugin
- Loading branch information
Showing
10 changed files
with
223 additions
and
13 deletions.
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
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
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
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
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 @@ | ||
from .plugin import * |
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,13 @@ | ||
{ | ||
"name": "Diagnostic", | ||
"webodmMinVersion": "0.6.2", | ||
"description": "description", | ||
"version": "0.1.0", | ||
"author": "Piero Toffanin", | ||
"email": "[email protected]", | ||
"repository": "https://github.com/OpenDroneMap/WebODM", | ||
"tags": ["diagnostic"], | ||
"homepage": "https://github.com/OpenDroneMap/WebODM", | ||
"experimental": false, | ||
"deprecated": false | ||
} |
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,69 @@ | ||
from app.plugins import PluginBase, Menu, MountPoint | ||
from django.shortcuts import render | ||
from django.contrib.auth.decorators import login_required | ||
|
||
import json, shutil | ||
|
||
def get_memory_stats(): | ||
""" | ||
Get node total memory and memory usage (Linux only) | ||
https://stackoverflow.com/questions/17718449/determine-free-ram-in-python | ||
""" | ||
try: | ||
with open('/proc/meminfo', 'r') as mem: | ||
ret = {} | ||
tmp = 0 | ||
for i in mem: | ||
sline = i.split() | ||
if str(sline[0]) == 'MemTotal:': | ||
ret['total'] = int(sline[1]) | ||
elif str(sline[0]) in ('MemFree:', 'Buffers:', 'Cached:'): | ||
tmp += int(sline[1]) | ||
ret['free'] = tmp | ||
ret['used'] = int(ret['total']) - int(ret['free']) | ||
|
||
ret['total'] *= 1024 | ||
ret['free'] *= 1024 | ||
ret['used'] *= 1024 | ||
return ret | ||
except: | ||
return {} | ||
|
||
|
||
class Plugin(PluginBase): | ||
def main_menu(self): | ||
return [Menu("Diagnostic", self.public_url(""), "fa fa-pie-chart fa-fw")] | ||
|
||
def app_mount_points(self): | ||
@login_required | ||
def diagnostic(request): | ||
# Load version number | ||
with open('./package.json') as f: | ||
package = json.load(f) | ||
version = package['version'] | ||
|
||
# Disk space | ||
total_disk_space, used_disk_space, free_disk_space = shutil.disk_usage('./') | ||
|
||
template_args = { | ||
'title': 'Diagnostic', | ||
'version': version, | ||
'total_disk_space': total_disk_space, | ||
'used_disk_space': used_disk_space, | ||
'free_disk_space': free_disk_space | ||
} | ||
|
||
# Memory (Linux only) | ||
memory_stats = get_memory_stats() | ||
if 'free' in memory_stats: | ||
template_args['free_memory'] = memory_stats['free'] | ||
template_args['used_memory'] = memory_stats['used'] | ||
template_args['total_memory'] = memory_stats['total'] | ||
|
||
return render(request, self.template_path("diagnostic.html"), template_args) | ||
|
||
return [ | ||
MountPoint('$', diagnostic) | ||
] | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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,100 @@ | ||
{% extends "app/plugins/templates/base.html" %} | ||
|
||
{% block content %} | ||
<script src="./Chart.min.js"></script> | ||
<h2>Diagnostic Information</h2> | ||
|
||
<p><b>App Version:</b> {{ version }}</p> | ||
|
||
<div class="row text-center"> | ||
<div class="col-md-4 col-sm-12"> | ||
<h4>Storage Space</h4> | ||
<div style="width: 80%; margin-left: 10%;"> | ||
<canvas id="diskChart" width="200" height="200" style="margin-bottom: 12px;"></canvas> | ||
</div> | ||
<p><b>Free:</b> {{ free_disk_space|filesizeformat }} | | ||
<b>Used:</b> {{ used_disk_space|filesizeformat }} | | ||
<b>Total:</b> {{ total_disk_space|filesizeformat }}</p> | ||
</div> | ||
<div class="col-md-4 col-sm-12"> | ||
{% if total_memory %} | ||
<h4>Memory</h4> | ||
<div style="width: 80%; margin-left: 10%;"> | ||
<canvas id="memoryChart" width="200" height="200" style="margin-bottom: 12px;"></canvas> | ||
</div> | ||
<p><b>Free:</b> {{ free_memory|filesizeformat }} | | ||
<b>Used:</b> {{ used_memory|filesizeformat }} | | ||
<b>Total:</b> {{ total_memory|filesizeformat }}</p> | ||
{% endif %} | ||
</div> | ||
</div> | ||
|
||
<hr/> | ||
<div style="margin-top: 20px;"><strong>Note!</strong> These values might be relative to the virtualization environment in which the application is running, not necessarely the values of the your machine. See instructions for <a href="http://stackoverflow.com/a/39720010">MacOS</a> and <a href="https://docs.docker.com/docker-for-windows/#advanced">Windows</a> for changing these values in a docker setup.</div> | ||
|
||
<script> | ||
(function(){ | ||
var ctx = document.getElementById('diskChart').getContext('2d'); | ||
var labels = { | ||
'Used': '{{ used_disk_space|filesizeformat }}', | ||
'Free': '{{ free_disk_space|filesizeformat }}' | ||
}; | ||
var chart = new Chart(ctx, { | ||
type: 'doughnut', | ||
data: { | ||
labels: ["Used", "Free"], | ||
datasets: [{ | ||
label: "Disk Space", | ||
backgroundColor:[ | ||
"rgb(255, 99, 132)", | ||
"rgb(54, 162, 235)" | ||
], | ||
data: [ {{ used_disk_space }}, {{ free_disk_space }} ], | ||
}] | ||
}, | ||
options: { | ||
tooltips: { | ||
callbacks: { | ||
label: function(tooltipItem, data) { | ||
return labels[data.labels[tooltipItem.index]]; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
})(); | ||
|
||
{% if total_memory %} | ||
(function(){ | ||
var ctx = document.getElementById('memoryChart').getContext('2d'); | ||
var labels = { | ||
'Used': '{{ used_memory|filesizeformat }}', | ||
'Free': '{{ free_memory|filesizeformat }}' | ||
}; | ||
var chart = new Chart(ctx, { | ||
type: 'doughnut', | ||
data: { | ||
labels: ["Used", "Free"], | ||
datasets: [{ | ||
label: "Disk Space", | ||
backgroundColor:[ | ||
"rgb(255, 99, 132)", | ||
"rgb(54, 162, 235)" | ||
], | ||
data: [ {{ used_memory }}, {{ free_memory }} ], | ||
}] | ||
}, | ||
options: { | ||
tooltips: { | ||
callbacks: { | ||
label: function(tooltipItem, data) { | ||
return labels[data.labels[tooltipItem.index]]; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
})(); | ||
{% endif %} | ||
</script> | ||
{% endblock %} |
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