Project

General

Profile

Todo #14011 » memory-graph-updates.patch

Jim Pingle, 02/24/2023 10:33 AM

View differences:

src/etc/inc/globals.inc
82 82
	'disablehelpicon' => false,
83 83
	'disablecrashreporter' => false,
84 84
	'debug' => false,
85
	'latest_config' => '22.8',
85
	'latest_config' => '22.9',
86 86
	'minimum_ram_warning' => '101',
87 87
	'minimum_ram_warning_text' => '128 MB',
88 88
	'wan_interface_name' => 'wan',
src/etc/inc/rrd.inc
617 617
			$rrdcreate .= "DS:free:GAUGE:$memvalid:0:10000000 ";
618 618
			$rrdcreate .= "DS:cache:GAUGE:$memvalid:0:10000000 ";
619 619
			$rrdcreate .= "DS:wire:GAUGE:$memvalid:0:10000000 ";
620
			$rrdcreate .= "DS:userwire:GAUGE:$memvalid:0:10000000 ";
621
			$rrdcreate .= "DS:laundry:GAUGE:$memvalid:0:10000000 ";
622
			$rrdcreate .= "DS:buffers:GAUGE:$memvalid:0:10000000 ";
620 623
			$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
621 624
			$rrdcreate .= "RRA:MIN:0.5:5:720 ";
622 625
			$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
......
639 642
			mwexec("$rrdtool update $rrddbpath$ifname$mem N:U:U:U:U:U");
640 643
		}
641 644

  
642
		/* the Memory stats gathering function. */
643
		$rrdupdatesh .= "MEM=`$sysctl -qn vm.stats.vm.v_page_count vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count vm.stats.vm.v_free_count vm.stats.vm.v_cache_count vm.stats.vm.v_wire_count | ";
644
		$rrdupdatesh .= " $awk '{getline active;getline inactive;getline free;getline cache;getline wire;printf ";
645
		$rrdupdatesh .= "((active/$0) * 100)\":\"((inactive/$0) * 100)\":\"((free/$0) * 100)\":\"((cache/$0) * 100)\":\"(wire/$0 * 100)}'`\n";
645
		/* Memory stats gathering function. */
646
		$rrdupdatesh .= "MEM=`$sysctl -qn ";
647
		/* Total pages */
648
		$rrdupdatesh .= "vm.stats.vm.v_page_count ";
649
		/* Active pages  */
650
		$rrdupdatesh .= "vm.stats.vm.v_active_count ";
651
		/* Inactive pages */
652
		$rrdupdatesh .= "vm.stats.vm.v_inactive_count ";
653
		/* Free pages  */
654
		$rrdupdatesh .= "vm.stats.vm.v_free_count ";
655
		if (is_module_loaded('zfs.ko')) {
656
			/* If the system is using ZFS, use ARC size as "cache" (value is bytes, not pages) */
657
			$rrdupdatesh .= "kstat.zfs.misc.arcstats.size ";
658
		} else {
659
			/* If the system is using UFS, use dirhash memory as "cache" (value is bytes, not pages) */
660
			$rrdupdatesh .= "vfs.ufs.dirhash_mem ";
661
		}
662
		/* Wired pages */
663
		$rrdupdatesh .= "vm.stats.vm.v_wire_count ";
664
		/* User wired pages */
665
		$rrdupdatesh .= "vm.stats.vm.v_user_wire_count ";
666
		/* Laundy pages */
667
		$rrdupdatesh .= "vm.stats.vm.v_laundry_count ";
668
		/* UFS Buffer space (value is in bytes, not pages) */
669
		$rrdupdatesh .= "vfs.bufspace ";
670
		/* Page size for calculations */
671
		$rrdupdatesh .= "hw.pagesize ";
672
		$rrdupdatesh .= " | ";
673
		/* Start the AWK code */
674
		$rrdupdatesh .= " $awk '{";
675
		/* Assign sysctl output to named variables */
676
		$rrdupdatesh .= "getline active;getline inactive;getline free;getline cache;getline wire;getline userwire;getline laundry;getline buffers;getline pagesize;";
677
		/* Divide cache and buffer values by page size so all values are in the same units */
678
		$rrdupdatesh .= "cache=(cache/pagesize);buffers=(buffers/pagesize);";
679
		/* Start of RRD-friendly output */
680
		$rrdupdatesh .= "printf ";
681
		/* Calculate values as a percentage of total pages */
682
		/* Active pages */
683
		$rrdupdatesh .= "((active/$0) * 100)";
684
		/* Inactive pages */
685
		$rrdupdatesh .= "\":\"((inactive/$0) * 100)";
686
		/* Free pages */
687
		$rrdupdatesh .= "\":\"((free/$0) * 100)";
688
		/* Cache (previously converted to pages) */
689
		$rrdupdatesh .= "\":\"((cache/$0) * 100)";
690
		/* Wired pages less cache and buffer pages (which are included in wired pages) */
691
		$rrdupdatesh .= "\":\"((wire - (cache + buffers))/$0 * 100)";
692
		/* User wired pages */
693
		$rrdupdatesh .= "\":\"((userwire/$0) * 100)";
694
		/* Laundry pages */
695
		$rrdupdatesh .= "\":\"((laundry/$0) * 100)";
696
		/* UFS Buffer space (previously converted to pages) */
697
		$rrdupdatesh .= "\":\"((buffers/$0) * 100)";
698
		/* Finish the AWK code */
699
		$rrdupdatesh .= "}'`\n";
700
		/* Update the database with new values */
646 701
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$mem N:\${MEM}\n";
647 702

  
648 703
		/* End Memory statistics */
src/etc/inc/upgrade_config.inc
6768 6768
	}
6769 6769
}
6770 6770

  
6771
function upgrade_228_to_229() {
6772
	global $g;
6773
	/* Update System Memory RRD file with new data sources
6774
	 * https://redmine.pfsense.org/issues/14011
6775
	 */
6776
	$rrddbpath = "/var/db/rrd/";
6777
	$database = "system-memory.rrd";
6778
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
6779
	$rrdinterval = 60;
6780
	$valid = $rrdinterval * 2;
6781
	if (platform_booting()) {
6782
		echo "Migrating System Memory RRD file to new format\n";
6783
	}
6784
	mwexec("$rrdtool tune {$rrddbpath}{$database} DS:userwire:GAUGE:{$valid}:0:10000000 2>&1");
6785
	mwexec("$rrdtool tune {$rrddbpath}{$database} DS:laundry:GAUGE:{$valid}:0:10000000 2>&1");
6786
	mwexec("$rrdtool tune {$rrddbpath}{$database} DS:buffers:GAUGE:{$valid}:0:10000000 2>&1");
6787
}
6788

  
6771 6789
/*
6772 6790
 * Special function that is called independent of current config version. It's
6773 6791
 * a workaround to have config_upgrade running on older versions after next
src/usr/local/www/includes/functions.inc.php
198 198

  
199 199
function mem_usage() {
200 200
	$memUsage = "NA";
201
	$totalMem = get_single_sysctl("vm.stats.vm.v_page_count");
201
	$totalMem = (int) get_single_sysctl("vm.stats.vm.v_page_count");
202 202
	if (is_numeric($totalMem)) {
203
		$inactiveMem = get_single_sysctl("vm.stats.vm.v_inactive_count");
204
		$cachedMem = get_single_sysctl("vm.stats.vm.v_cache_count");
205
		$freeMem = get_single_sysctl("vm.stats.vm.v_free_count");
203
		/* Include inactive and laundry with free memory since they
204
		 * could be freed under pressure. */
205
		$inactiveMem = (int) get_single_sysctl("vm.stats.vm.v_inactive_count");
206
		$laundryMem = (int) get_single_sysctl("vm.stats.vm.v_laundry_count");
207
		$freeMem = (int) get_single_sysctl("vm.stats.vm.v_free_count");
206 208
		if (is_numeric($inactiveMem) &&
207
			is_numeric($cachedMem) &&
208
			is_numeric($freeMem)) {
209
			$usedMem = (int)$totalMem - ((int)$inactiveMem + (int)$cachedMem + (int)$freeMem);
209
		    is_numeric($laundryMem) &&
210
		    is_numeric($freeMem)) {
211
			$usedMem = $totalMem - ($inactiveMem + $laundryMem + $freeMem);
210 212
			$memUsage = round(($usedMem * 100) / $totalMem, 0);
211 213
		}
212 214
	}
(1-1/2)