As informações a seguir fornecem informações sobre o uso do disco RAM rapidamente, ou seja, quanta memória está comprometida com um ramdisk específico. Pode ser facilmente integrado em um conkyrc:
mkdir -pv /mnt/ramdisk/.ramdisk
DF_RESULTS_FILE=/mnt/ramdisk/.ramdisk/df_ramdisk_results.txt
df -h | grep -e /mnt/ramdisk > $DF_RESULTS_FILE
DF_RESULTS_STRING=$(cat $DF_RESULTS_FILE)
DF_RESULTS_details=($DF_RESULTS_STRING)
printf "RAM Disk Usage: %s /%s\n" ${DF_RESULTS_details[2]} ${DF_RESULTS_details[1]}
Os seguintes itens atendem a todas as minhas necessidades, conforme relatam, na verdade, todas as instâncias de uma tmpfs
mount:
#!/bin/bash
# rdu2.sh - ramdisk usage statusline statistics (version 2.2)
mkdir -pv /mnt/ramdisk/.ramdisk
# Change to /mnt/ramdisk for a specific drive
# or change it to something else or any other information
DF_MONITORED=tmpfs
DF_RESULTS_DIR=/mnt/ramdisk/.ramdisk
DF_RESULTS_FILE=$DF_RESULTS_DIR/rdu2.2_generic_results.txt
#the following lines are for people who haven't thought about doing "ps -A | grep rdu2"
#SCRIPT_PID=$(echo $$)
#printf "%d" $SCRIPT_PID > $DF_RESULTS_DIR/temp_script_pid.txt
printf "rdu2 executing to... [%s]\n" $DF_RESULTS_FILE
printf "[%s]" $DF_RESULTS_FILE > $DF_RESULTS_FILE
while [ 1 ]
do
# Adding raw numbers and translating to human-readable
# Display to screen and write to a file
df | grep -e $DF_MONITORED > $DF_RESULTS_DIR/temp_df_tmpfs.tsv
TOTAL_MEM_STRING=$(awk '{s+=$2} END {printf "%.0f", s}' $DF_RESULTS_DIR/temp_df_tmpfs.tsv | awk 'function human(x) { s=" KiB MiB GiB TiB EiB PiB YiB ZiB"; while (x>=1024 && length(s)>1) { x/=1024; s=substr(s,5) }; s=substr(s,1,4); return sprintf( "%.2f%s", x, s) } { gsub(/^[0-9]+/, human($1)); print }')
TOTAL_MEM_STRING_details=($TOTAL_MEM_STRING)
USED_MEM_STRING=$(awk '{s+=$3} END {printf "%.0f", s}' $DF_RESULTS_DIR/temp_df_tmpfs.tsv | awk 'function human(x) { s=" KiB MiB GiB TiB EiB PiB YiB ZiB"; while (x>=1024 && length(s)>1) { x/=1024; s=substr(s,5) }; s=substr(s,1,4); return sprintf( "%.2f%s", x, s) } { gsub(/^[0-9]+/, human($1)); print }')
USED_MEM_STRING_details=($USED_MEM_STRING)
printf "%8s%s%8s\r" "$USED_MEM_STRING" " /" "$TOTAL_MEM_STRING"
printf "%8s%s%8s" "$USED_MEM_STRING" " /" "$TOTAL_MEM_STRING" > $DF_RESULTS_FILE
# Typical format for a conkyrc:
# # ramdisk usage
# # NOTE: the ${tail logfile lines} is internal to conky; do not confuse with bash's tail command line program
# ${color grey}tpmfs Usage rdu2:$color ${tail /mnt/ramdisk/.ramdisk/rdu2.2_generic_results.txt 1}
sleep 1.32s
done
Chamado no boot e referenciado no conky, o segundo script contribui para a produção do seguinte texto:
tmpfs Usage (rdu2): 96.14 MiB /3,42 GiB
Os valores atualizam 'ao vivo' ao copiar um arquivo grande para um disco virtual.