#!/bin/bash

#
# Copyright (C) 2019 Nethesis S.r.l.
# http://www.nethesis.it - info@nethesis.it
#
# This script is part of Dante.
#
# Dante is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# Dante is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Dante.  If not, see COPYING.
#

# Root partition pie chart

data=$(df --output=used,avail / | tail -n 1)
used=$(( $(echo $data | cut -d' ' -f 1) * 1024))
avail=$(( $(echo $data | cut -d' ' -f 2) * 1024))

id=$(basename $0)
type=$(basename $0 | cut -d'-' -f2)
chartType=$(basename $0 | cut -d'-' -f3)
unit="bytes"
aggregation='snapshot'
categories='["used", "available"]'
series="[{\"name\":\"root_parition\",\"data\":[$used, $avail]}]"

echo -n "{\"type\":\"$type\",\"chartType\":\"$chartType\",\"minerId\":\"$id\",\"aggregationType\":\"$aggregation\",\"unit\":\"$unit\","
echo -n "\"series\":$series",
echo -n "\"categories\":$categories"
echo -n "}"
