Skip to content
Browse files

Add % of disk used.

  • Loading branch information...
1 parent 65c4407 commit 7f471ad37c9e6fad7787205ce399cc3ac00b2044 @onyxfish onyxfish committed Apr 18, 2012
Showing with 27 additions and 21 deletions.
  1. +12 −8 client/templates/dashboard.html
  2. +15 −13 client/views.py
View
20 client/templates/dashboard.html
@@ -21,30 +21,34 @@
<th>Disk</th>
<th>Free</th>
<th>Total</th>
+ <th>% free</th>
</tr>
</thead>
<tbody>
<tr>
<td>Root</td>
- <td>{{ root_disk_free }}</td>
- <td>{{ root_disk_total }}</td>
+ <td>{{ root_disk_free|filesizeformat }}</td>
+ <td>{{ root_disk_total|filesizeformat }}</td>
+ <td>{{ root_disk_percent_free|floatformat:1 }}</td>
</tr>
<tr>
<td>Uploads</td>
{% if upload_disk_total %}
- <td>{{ upload_disk_free }}</td>
- <td>{{ upload_disk_total }}</td>
+ <td>{{ upload_disk_free|filesizeformat }}</td>
+ <td>{{ upload_disk_total|filesizeformat }}</td>
+ <td>{{ upload_disk_percent_free|floatformat:1 }}</td>
{% else %}
- <td colspan="2">Uploads are currently stored on the root disk.</td>
+ <td colspan="3">Uploads are currently stored on the root disk.</td>
{% endif %}
</tr>
<tr>
<td>Search indices</td>
{% if indices_disk_total %}
- <td>{{ indices_disk_free }}</td>
- <td>{{ indices_disk_total }}</td>
+ <td>{{ indices_disk_free|filesizeformat }}</td>
+ <td>{{ indices_disk_total|filesizeformat }}</td>
+ <td>{{ indices_disk_percent_free|floatformat:1 }}</td>
{% else %}
- <td colspan="2">Uploads are currently stored on the root disk.</td>
+ <td colspan="3">Uploads are currently stored on the root disk.</td>
{% endif %}
</tr>
</tbody>
View
28 client/views.py
@@ -46,12 +46,6 @@ def index(request):
})
})
-def _format_size(num):
- """
- Format byte sizes as human-readable equivalents.
- """
- return "%3.1f %s" % (num / 1024.0 / 1024.0 / 1024.0, 'GB')
-
def _get_total_disk_space(p):
"""
Calculate the total disk space of the device on which a given file path resides.
@@ -77,32 +71,40 @@ def dashboard(request):
upload_disk = os.stat(settings.MEDIA_ROOT).st_dev
indices_disk = os.stat(settings.SOLR_DIRECTORY).st_dev
- root_disk_total = _format_size(_get_total_disk_space('/'))
- root_disk_free = _format_size(_get_free_disk_space('/'))
+ root_disk_total = _get_total_disk_space('/')
+ root_disk_free = _get_free_disk_space('/')
+ root_disk_percent_free = float(root_disk_free) / root_disk_total * 100
if upload_disk != root_disk:
- upload_disk_total = _format_size(_get_total_disk_space(settings.MEDIA_ROOT))
- upload_disk_free = _format_size(_get_free_disk_space(settings.MEDIA_ROOT))
+ upload_disk_total = _get_total_disk_space(settings.MEDIA_ROOT)
+ upload_disk_free = _get_free_disk_space(settings.MEDIA_ROOT)
+ upload_disk_percent_free = float(upload_disk_free) / upload_disk_total * 100
else:
upload_disk_total = None
upload_disk_free = None
+ upload_disk_percent_free = None
if indices_disk != root_disk:
- indices_disk_total = _format_size(_get_total_disk_space(settings.SOLR_DIRECTORY))
- indices_disk_free = _format_size(_get_free_disk_space(settings.SOLR_DIRECTORY))
+ indices_disk_total = _get_total_disk_space(settings.SOLR_DIRECTORY)
+ indices_disk_free = _get_free_disk_space(settings.SOLR_DIRECTORY)
+ indices_disk_percent_free = float(indices_disk_free / indices_disk_total) * 100
else:
indices_disk_total = None
indices_disk_free = None
+ indices_disk_percent_free = None
return render_to_response('dashboard.html', {
'datasets_without_descriptions': datasets_without_descriptions,
'datasets_without_categories': datasets_without_categories,
'root_disk_total': root_disk_total,
'root_disk_free': root_disk_free,
+ 'root_disk_percent_free': root_disk_percent_free,
'upload_disk_total': upload_disk_total,
'upload_disk_free': upload_disk_free,
+ 'upload_disk_percent_free': upload_disk_percent_free,
'indices_disk_total': indices_disk_total,
- 'indices_disk_free': indices_disk_free
+ 'indices_disk_free': indices_disk_free,
+ 'indices_disk_percent_free': indices_disk_percent_free
})
def jst(request):

0 comments on commit 7f471ad

Please sign in to comment.
Something went wrong with that request. Please try again.