Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/rc/growth

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc
#
#	growth watch the growth of a file
#
#	Does not cope with midnight properly but will recover on the
#	next update. 
#

if (~ $#* 0){
	echo usage: $0 '<file>...'
	exit 1
}

@{ while ( ~ 1 1 ){

	for ( file in $* ){
		if ( test -f $file )
			echo `{ls -lu $file} `{date}
		sleep 2
	} 
} } |
	awk  '
	BEGIN {
		num = 0;
		SPM = 60;		# sec per min
		SPH = 60 * 60;		# sec per hour

		printf("%-15s %-12s %-12s %-9s %-9s %-6s\n",
			"File", "sz", "Time", "BPS", "avBPS", "trend");
	}

	{
		file=$10;
		gsub("^.*/", "", file);

		size = $6;
		split($14, hm, ":");
		time = hm[1] * SPH + hm[2] * SPM + hm[3];

		if (num == 0){					# first time through
			otime = time;
			osize = size;
		}

		num++;						# number of records
		sum += rate;					# overall data rate
		delta = time - otime;				# time since last measure
		elap += delta;					# total elapsed time
		grow = size - osize;				# growth in size

		mean = sum / num;				# mean growth rate
		rate = (delta == 0)? 0: grow / delta;		# find data rate
		chg = (mean == 0)? 0: rate / mean; 		# change in data rate


		printf("%-15s %-12d %-12s %-9.1f %-9.1f %6.1f%%\n",
			file, size, hms(elap), rate, mean, chg * 100);

		otime = time;
		osize = size;
		orate = rate;
	}

	function hms(t,		h, m, s){

		s = t;
		h = int(s / SPH);
		s -= h * SPH;
		m = int(s / SPM);
		s -= m * SPM;

		return(sprintf("%02d:%02d:%02d", h, m, s));
	}
'



Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.