Commit 90daeec8 authored by Leo Iannacone's avatar Leo Iannacone

add disk usage function

parent 6fa988bd
...@@ -90,6 +90,15 @@ config.debomatic.excluded_files = [ ...@@ -90,6 +90,15 @@ config.debomatic.excluded_files = [
"json" "json"
] ]
###
List of subdirectories in distributions to show in disk usage
###
config.debomatic.disk_usage_subdirs = [
"aptcache"
"pool"
"chroot"
]
### ###
The routes, that are the pages urls The routes, that are the pages urls
### ###
......
fs = require('fs') fs = require('fs')
glob = require('glob') glob = require('glob')
exec = require('child_process').exec
config = require('./config') config = require('./config')
utils = require('./utils') utils = require('./utils')
...@@ -13,7 +14,7 @@ get_all_packages = (cb) -> ...@@ -13,7 +14,7 @@ get_all_packages = (cb) ->
glob "#{config.debomatic.path}/*/pool/*/*.json", {}, (err, files) -> glob "#{config.debomatic.path}/*/pool/*/*.json", {}, (err, files) ->
if err? if err?
utils.errors_handler "history:get_all_packages", err utils.errors_handler "stats:get_all_packages", err
return return
packages = [] packages = []
for f in files for f in files
...@@ -30,4 +31,41 @@ get_all_packages = (cb) -> ...@@ -30,4 +31,41 @@ get_all_packages = (cb) ->
cb(packages) cb(packages)
get_disk_usage = (cb) ->
exec "du -d 2 #{config.debomatic.path}", (error, stdout, stderr) ->
if error?
utils.errors_handler "stats:get_disk_usage", err
return
if stderr?
utils.errors_handler "disk usage error: ", stderr
result = {}
for line in stdout.split('\n')
continue if line == ''
info = line.replace(/\t+/g,' ').split(' ')
size = info[0]
dirs = info[1].replace("#{config.debomatic.path}", '').split('/')
# case total size for debomatic incoming
if dirs.length <= 1
result['size'] = size
continue
distribution = dirs[1]
if not result[distribution]?
result[distribution] = {}
# case total size for distribution
if dirs.length == 2
result[distribution]['size'] = size
continue
# case size for distribution/subdir
subdir = dirs[2]
subdir = "chroot" if distribution == subdir
if subdir in config.debomatic.disk_usage_subdirs
result[distribution][subdir] = size
cb(result)
module.exports.get_all_packages = get_all_packages module.exports.get_all_packages = get_all_packages
module.exports.get_disk_usage = get_disk_usage
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment