Newer
Older
nextcloud-monitoring-dashboard / zabbix-agent-scripts / get_storage_metrics.py
#
# @copyright Copyright (c) 2024, Pietro Marini (pmarini@rcasys.com)
#
# @license GNU AGPL version 3 or any later version
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import subprocess

import json

datadir = subprocess.check_output(["occ", "config:system:get", "datadirectory"]).strip(b"\n").decode()

total_size = subprocess.check_output(["du","-b", "-d0", datadir]).split(b"\t")[0].decode()

total_size_gb = int(total_size)/1024./1024./1024.

total_size_dict = { "total_size_gb": total_size_gb }


with open("/var/lib/zabbix/output/storage_metrics.json","w") as fl:
    
    json.dump(total_size_dict,fl)