Skip to content

Commit

Permalink
api & ui: database & data disk usage in dashboard (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
andre8244 committed Jun 3, 2020
1 parent bbd6989 commit a1fcf3a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
5 changes: 4 additions & 1 deletion api/read
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ else
channels=$(_query "select count(*) from channels where deleteat = 0")
posts=$(_query "select count(*) from posts where deleteat = 0")

database_usage=$(su - postgres -c "scl enable rh-postgresql94 -- psql -q -A -t --port=55432 -c 'SELECT pg_database_size('\''mattermost'\'');'")
data_usage=$(/usr/bin/du -s /var/lib/nethserver/mattermost | cut -f1)

prop=$(/sbin/e-smith/config getjson mattermost)
printf '{"status": { "users": "%s", "teams": "%s", "channels": "%s", "posts": "%s" },"configuration":%s}' "$users" "$teams" "$channels" "$posts" "$prop"
printf '{"status": { "users": "%s", "teams": "%s", "channels": "%s", "posts": "%s", "database-usage": "%s", "data-usage": "%s" },"configuration":%s}' "$users" "$teams" "$channels" "$posts" "$database_usage" "$data_usage" "$prop"
fi

6 changes: 5 additions & 1 deletion ui/i18n/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
"teams": "Teams",
"channels": "Channels",
"posts": "Posts",
"open_app": "Open app"
"open_app": "Open app",
"statistics": "Statistics",
"disk_usage": "Disk usage",
"database": "Database",
"data": "Data"
}
33 changes: 32 additions & 1 deletion ui/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,35 @@ $(document).on("nethserver-loaded", function () {
$(this).text(_($(this).attr('i18n')))
});
/* */
})
})

function byteFormat(size) {
var result;

switch (true) {
case size === null || size === "" || isNaN(size):
result = "-";
break;

case size >= 0 && size < 1024:
result = size + " B";
break;

case size >= 1024 && size < Math.pow(1024, 2):
result = Math.round(size / 1024 * 100) / 100 + " K";
break;

case size >= Math.pow(1024, 2) && size < Math.pow(1024, 3):
result = Math.round(size / Math.pow(1024, 2) * 100) / 100 + " M";
break;

case size >= Math.pow(1024, 3) && size < Math.pow(1024, 4):
result = Math.round(size / Math.pow(1024, 3) * 100) / 100 + " G";
break;

default:
result = Math.round(size / Math.pow(1024, 4) * 100) / 100 + " T";
}

return result;
}
25 changes: 24 additions & 1 deletion ui/views/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ <h2 i18n="dashboard">Mattermost dashboard</h2>

<div id="loader" class="spinner spinner-lg"></div>
<div id="content">
<h3 i18n="statistics"></h3>
<div class="stats-container card-pf-utilization-details">
<span class="card-pf-utilization-card-details-count" id="stats-users">0</span>
<span class="card-pf-utilization-card-details-description">
Expand All @@ -27,6 +28,20 @@ <h2 i18n="dashboard">Mattermost dashboard</h2>
</span>
</div>

<h3 i18n="disk_usage"></h3>
<div class="stats-container card-pf-utilization-details">
<span class="card-pf-utilization-card-details-count" id="stats-database-usage">0</span>
<span class="card-pf-utilization-card-details-description">
<span class="card-pf-utilization-card-details-line-2 stats-text" i18n="database"></span>
</span>
</div>
<div class="stats-container card-pf-utilization-details">
<span class="card-pf-utilization-card-details-count" id="stats-data-usage">0</span>
<span class="card-pf-utilization-card-details-description">
<span class="card-pf-utilization-card-details-line-2 stats-text" i18n="data"></span>
</span>
</div>

<a id="link" target="_blank" href="" class="btn btn-primary btn-lg open-app" i18n="open_app"></a>
</div>

Expand All @@ -48,8 +63,16 @@ <h2 i18n="dashboard">Mattermost dashboard</h2>
success = JSON.parse(success);

var status = success.status;
var statusText;

for (var s in status) {
$('#stats-' + s).text(status[s] || 0)
if (s === 'database-usage' || s === 'data-usage') {
// format byte size
statusText = byteFormat(status[s]);
} else {
statusText = status[s];
}
$('#stats-' + s).text(statusText || 0)
}

if (success.configuration.props.status == 'enabled' && success.configuration.props.VirtualHost.length > 0) {
Expand Down

0 comments on commit a1fcf3a

Please sign in to comment.