How to see each user's data size total

Hello,

I am a newbie administrator of NC13 since 1 week ago.
I installed in CentOS7 with apache2.4 and PHP7.1.
I am looking for about the subject function. But I can’t.
Is there any menu or configuration about the function.
I want to easily check the diskspace size that each users using currently.
Or I had better write script that manages same solition ??

There are two options for NC13:

  1. as admin user
  • go to the “Users” menu (where you all your users)
  • check the quota column
  • see the little blue bar indicating the percentage of used storage for a rough overview
  • hover with the mouse over these fields to see the used space in X-bytes
    grafik
  1. use the User Usage Report app (works only via command line)
    https://apps.nextcloud.com/apps/user_usage_report
    sudo -u http php /var/www/nextcloud/occ usage-report:generate

Option 2 even works for NC12.

Schmu san,

Thank you for your kindly answer.
I can easily check the size.
And I will try Report app.
I already downloaded and untgzed, but I don’t know much about instaling custom appli or PHP.
So I will read documents.

1 Like

Schmu san,

I alredy installed usage-report by activating in appli page.
And get reports by my intervaled cron schedule.

“???”,“2018-03-07T06:23:31+00:00”,-2,1346137229,88,2,6,1
"???",“2018-03-07T06:23:31+00:00”,11811160064,"",0,0,0
"???",“2018-03-07T06:23:31+00:00”,-2,7148235,12,0,0,0
"???",“2018-03-07T06:23:31+00:00”,-2,71117787,15,0,0,0

Hi Tanaka san,

Great to here that. So you receive all the data you wanted or is still something missing?

I wrote a little script for myself, to make the reports a bit easier to read, maybe you find it useful, too.

Edit: Oh, I just noticed that the app delivers negative values as quota for you. While I have specifically defined quotas and I don’t have negative values, I didn’t wrote any line to handle them. Please take care of that. Maybe I can add some lines later.

#!/bin/bash

##########################################################
# Please modify the following two paths! This is the path 
# where the report (csv file) will be saved to.
##########################################################

TEMP_REPORT="/mnt/reports/temp_`date +%Y-%m-%d`_usage.csv"
REPORT="/mnt/reports/`date +%Y-%m-%d`_usage.csv"


##########################################################
##########################################################


##########################################################
# From here on, no changes are necessary. 
##########################################################

divider=1048576 # for Megabyte
divider2=1073741824 # for Gigabyte
divider3=1099511627776 # for Terabyte

sum_home=0
sum_used=0
sum_files=0
sum_shares=0
sum_new=0


echo '"User","Quota","Space used","Number of Files","Number of Shares","Newly created files","Downloaded/Viewed"' > $REPORT

sudo -u http php /var/www/nextcloud/occ usage-report:generate > $TEMP_REPORT

IFS=','


while read LINE
do
        read -a ARRAY <<< ${LINE}

        ##########################################################
        # The app has an issue and provides a string
		# for the quotas of 20 GB. I'm working around that here
        ##########################################################

        if [[ ${ARRAY[2]} == "\"20 GB\"" ]]
        then
                ARRAY[2]=$((20 * 1024 * 1024 * 1024))
        fi


        #########################################################
        # sum up columns to get a better overview
        #########################################################
        sum_home=$(($sum_home + ${ARRAY[2]}))
        sum_used=$(($sum_used + ${ARRAY[3]}))
        sum_files=$(($sum_files + ${ARRAY[4]}))
        sum_shares=$(($sum_shares + ${ARRAY[5]}))
        sum_new=$(($sum_new + ${ARRAY[6]}))


        ##########################################################
        # making quota more readable 
        ##########################################################

        if [[ $((${ARRAY[2]} / $divider2)) == 0 ]]
        then
                ARRAY[2]=`calc ${ARRAY[2]} / $divider`
                Unit="MB"
        else
                ARRAY[2]=`calc ${ARRAY[2]} / $divider2`
                Unit="GB"
        fi

        ##########################################################
        # making Used Space more readable
        ##########################################################
        if [[ ${ARRAY[3]} > 1024 ]]
        then
                if [[ $((${ARRAY[3]} / $divider2)) == 0 ]]
                then
                        ARRAY[3]=`calc ${ARRAY[3]} / $divider`
                        ARRAY[3]=`echo ${ARRAY[3]} | sed 's/\~//g'`
                        Unit2="MB"
                else
                        ARRAY[3]=`calc ${ARRAY[3]} / $divider2`
                        ARRAY[3]=`echo ${ARRAY[3]} | sed 's/\~//g'`
                        Unit2="GB"
                fi
        else
                Unit2="KB"
        fi


#       printf '%s,' "${ARRAY[@]}" >> $REPORT

printf '%s,"%d %s","%.2f %s",%d,%d,%d,%d\n' "${ARRAY[0]}" "${ARRAY[2]}" "$Unit" "${ARRAY[3]}" "$Unit2" "${ARRAY[4]}" "${ARRAY[5]}" "${ARRAY[6]}" "${ARRAY[7]}" >> $REPORT

done < ${TEMP_REPORT}


ratio=`calc "$sum_used / $sum_home * 100"`
ratio=`echo $ratio | sed 's/\~//g'`


if [[ $(($sum_home / $divider3)) == 0 ]]
then
        sum_home=`calc $sum_home / $divider2`
        sum_home=`echo $sum_home | sed 's/\~//g'`
        Unit="GB"
else
        sum_home=`calc $sum_home / $divider3`
        sum_home=`echo $sum_home | sed 's/\~//g'`
        Unit="TB"
fi

if [[ $(($sum_used / $divider2)) == 0 ]]
then
        sum_used=`calc $sum_used / $divider`
        sum_used=`echo $sum_used | sed 's/\~//g'`
        Unit2="MB"
else
        sum_used=`calc $sum_used / $divider2`
        sum_used=`echo $sum_used | sed 's/\~//g'`
        Unit2="GB"
fi

percent="%"

printf '#######################,########,##############,##############,############,########################,##################\n' >> $REPORT
printf 'Summe,"%.2f %s","%.2f %s",%d,%d,%d,,\n' "$sum_home" "$Unit" "$sum_used" "$Unit2" "$sum_files" "$sum_shares" "$sum_new" >> $REPORT
printf 'Ratio (used/available),"%.2f %s",,,,,,\n' "$ratio" "$percent" >> $REPORT

rm $TEMP_REPORT
1 Like

Schmu san,

Thank you for providing the code.

If necessary, I will use it.
I have just started, so I am satisfied with the requirements as below.

I also write my code today. and working well.
I add result records to sqlite table intervaled by crontab schedule.

[ Log Table ]

sqlite> .schema log_usage_nextcloud
CREATE TABLE log_usage_nextcloud (
id integer primary key,

uid text,
tm timestamp,
sz_b integer,
dssz_b integer,
cnt_fhs integer,
cnt_fsc integer,
cnt_fcr integer,
cnt_fdv
, nm_site text, tm_add timestamp);
CREATE INDEX log_usage_nextcloud_tm_add on log_usage_nextcloud (tm_add);
CREATE INDEX log_usage_nextcloud_uid on log_usage_nextcloud (uid);

[ Shell ]

#!/bin/sh

#
# NextCloud target site usage-report add to sqlite table
# $1 site name
#

############## const #################

SQL_LEFT="INSERT INTO log_usage_nextcloud (uid, tm, sz_b, dssz_b,cnt_fhs, cnt_fsc, cnt_fcr, cnt_fdv, nm_site, tm_add) VALUES ("
SQL_TXTFILENAME=/home/sqlite/sql/tmp_ncusage.sql

#####################################

cd /home/ApacheDoc/$1

## usage repoert command ##
result=sudo -u apache php occ usage-report:generate

allSQL="“
tmpSQL=”"
# loop command result #
for row in ${result}; do
#echo ${row}

tmpSQL=${SQL_LEFT}${row}",’$1’, datetime(datetime(), ‘localtime’));"
# add \n ??? #
tmpSQL=echo -e "${tmpSQL}"

allSQL=${allSQL}${tmpSQL}
echo ${tmpSQL}

done

echo "— Generated SQL —"
echo ${allSQL}

echo “— To read file —“
echo ${allSQL} | sed -e 's/””/0/g’ -e “s/,/,0,/g” -e ‘s/;/;\n/g’ > ${SQL_TXTFILENAME}
cat ${SQL_TXTFILENAME}

sqlite3 /home/sqlite/logs < ${SQL_TXTFILENAME}

Schmu san,

Thank you for providing the code.

If necessary, I will use it.
I have just started, so I am satisfied with the requirements as below.

I also write my code today. and working well.
I add result records to sqlite table intervaled by crontab schedule.

[ Log Table ]

sqlite> .schema log_usage_nextcloud
CREATE TABLE log_usage_nextcloud (
id integer primary key,

uid text,
tm timestamp,
sz_b integer,
dssz_b integer,
cnt_fhs integer,
cnt_fsc integer,
cnt_fcr integer,
cnt_fdv
, nm_site text, tm_add timestamp);
CREATE INDEX log_usage_nextcloud_tm_add on log_usage_nextcloud (tm_add);
CREATE INDEX log_usage_nextcloud_uid on log_usage_nextcloud (uid);

[ Shell ]

#!/bin/sh

# NextCloud target site usage-report add to sqlite table

# $1 site name

############## const #################

SQL_LEFT="INSERT INTO log_usage_nextcloud (uid, tm, sz_b, dssz_b,cnt_fhs, cnt_fsc, cnt_fcr, cnt_fdv, nm_site, tm_add) VALUES ("
SQL_TXTFILENAME=/home/sqlite/sql/tmp_ncusage.sql

#####################################

cd /home/ApacheDoc/$1

## usage repoert command

result= sudo -u apache php occ usage-report:generate

allSQL="“
tmpSQL=”"

# loop command result

for row in ${result}; do
#echo ${row}

tmpSQL=${SQL_LEFT}${row}",’$1’, datetime(datetime(), ‘localtime’));"

# add \n ???

tmpSQL= echo -e "${tmpSQL}"

allSQL=${allSQL}${tmpSQL}
echo ${tmpSQL}

done

echo "— Generated SQL —"
echo ${allSQL}

echo “— To read file —“
echo ${allSQL} | sed -e 's/””/0/g’ -e “s/,/,0,/g” -e ‘s/;/;\n/g’ > ${SQL_TXTFILENAME}
cat ${SQL_TXTFILENAME}

sqlite3 /home/sqlite/logs < ${SQL_TXTFILENAME}

1 Like