Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Jul 2005 15:08:00 GMT
From:      soc-victor <soc-victor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 80349 for review
Message-ID:  <200507161508.j6GF80gS003579@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=80349

Change 80349 by soc-victor@soc-victor_82.76.158.176 on 2005/07/16 15:07:54

	Added some VM entries for hrStorageTable. Should be changed to be
	based on libmemestat - ASAP.

Affected files ...

.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#5 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#7 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c#4 edit

Differences ...

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#5 (text+ko) ====

@@ -149,7 +149,7 @@
 			case LEAF_hrSystemDate: {
 				u_char s_date_time[11];
 				int s_date_time_len = -1;
-				if((s_date_time_len = OS_getSystemDate(s_date_time)) < 0){
+				if((s_date_time_len = OS_getSystemDate(s_date_time)) < 0) {
 					return (SNMP_ERR_GENERR);
 				}
 				return (string_get(value, s_date_time, s_date_time_len));
@@ -350,8 +350,8 @@
 	
 		/*first time, do the sysctl*/
 		
-		struct timeval  kernel_boot_timestamp={0,0};
-		int mib[2]={CTL_KERN,KERN_BOOTTIME};
+		struct timeval  kernel_boot_timestamp={ 0, 0 };
+		int mib[2]={ CTL_KERN, KERN_BOOTTIME };
 		size_t len = sizeof(kernel_boot_timestamp);
 		
 		if(sysctl(mib, 2, &kernel_boot_timestamp, &len, NULL, 0) == -1) {
@@ -498,14 +498,14 @@
 int OS_getSystemMaxProcesses(void) {
 	if( hrState_g.max_proc == 0 ) {
 	
-	        int mib[2] = {CTL_KERN, KERN_MAXPROC};
+	        int mib[2] = { CTL_KERN, KERN_MAXPROC };
         	size_t len = 0;
         	len = sizeof(hrState_g.max_proc);
         	if(sysctl(mib, 2, &hrState_g.max_proc, &len, NULL, 0) == -1) {
 			syslog(LOG_ERR, "sysctl KERN_MAXPROC failed: %m ");
 			return (-1); /*error*/
 	   	}
-		HR_DPRINTF((stderr, "Got kernel maxporc: %d\n",hrState_g.max_proc));
+		HR_DPRINTF((stderr, "Got kernel maxporc: %d\n", hrState_g.max_proc));
 	
 	}
 	return (hrState_g.max_proc);

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#7 (text+ko) ====

@@ -44,6 +44,7 @@
 #include <sys/ucred.h>	/*for getfsstat*/
 #include <sys/mount.h>	/*for getfsstat*/
 
+#include <sys/vmmeter.h> 
 
 /*a debug macro*/
 #ifndef NDEBUG
@@ -115,10 +116,11 @@
 	struct 
 	storage_tbl	hr_storage_tbl;	   /*the head of the list with table's entries */
 	uint64_t 	hr_tick;
-	struct kvm_swap *swap_devs;	   /*for kvm_getswapinfo*/
+	struct kvm_swap *swap_devs;	   /*for kvm_getswapinfo, malloc'd*/
 	size_t		swap_devs_len;     /*idem */ 
-	struct statfs	*fs_buf;	   /*for getfsstat*/
+	struct statfs	*fs_buf;	   /*for getfsstat, malloc'd*/
 	size_t		fs_buf_count;	   /*idem*/	
+	struct vmtotal	mem_stats;
 	uint32_t 	next_hrStorage_index; /*next int availabe for indexing the hrStorageTable*/
 	time_t		hrStorage_tbl_age; 
 	

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c#4 (text+ko) ====

@@ -40,14 +40,10 @@
 #include <string.h>
 #include <err.h>
 #include <unistd.h> /*for getpagesize()*/
+#include <vm/vm_param.h>
 
 
 
-static
-void hrStorage_get_vm_v(void){
-	/*FIX ME*/
-	HR_DPRINTF((stderr, "WARNING: hrStorageTable vm not implmeneted yet.\n "));
-}
 
 
 static
@@ -138,7 +134,67 @@
 	return (NULL);
 }
 
+/*
+ * Very silly implementation for VM info. 
+ * Should be changed to use libmemestat API 
+ * (Robert N M Watson has just created, not yet 
+ * available for public for the time being)
+ * FIX ME
+ */
+
 static
+void hrStorage_get_vm_v(void) {
+	/*FIX ME*/
+	int mib[2] = { CTL_VM, VM_TOTAL };
+	int len = sizeof(hrState_g.mem_stats);
+	int page_size_bytes;
+	struct hrStorageTblEntry *entry = NULL;
+	if( sysctl(mib, 2, &hrState_g.mem_stats, &len, NULL, 0) < 0 ) {
+		syslog(LOG_ERR, "%s: sysctl( { CTL_VM, VM_METER } ) failed: %m ", __func__ );	
+		assert(0);
+		return;
+	}
+	
+	page_size_bytes = getpagesize();
+	
+
+	
+	/*Real Memory Metrics*/
+	entry = hrStorageTblEntry_find_by_name("Real Memory Metrics");
+	if( entry == NULL ) {
+		entry =  hrStorageTblEntry_create("Real Memory Metrics");
+	}
+	assert(entry != NULL);
+	if( entry == NULL) return; /*I'm out of luck now, maybe next time*/
+	
+	entry->flags |= HR_STORAGE_FOUND;
+	entry->type = (struct asn_oid)OIDX_hrStorageRam;
+	entry->allocationUnits = page_size_bytes;
+	entry->size = hrState_g.mem_stats.t_rm;
+	entry->used = hrState_g.mem_stats.t_arm; /*ACTIVE is not USED - FIX ME */
+	entry->allocationFailures = 0;						
+
+	
+
+	/*Shared Real Memory Metrics*/
+	entry = hrStorageTblEntry_find_by_name("Shared Real Memory Metrics");
+	if( entry == NULL ) {
+		entry =  hrStorageTblEntry_create("Shared Real Memory Metrics");
+	}
+	assert(entry != NULL);
+	if( entry == NULL) return; /*I'm out of luck now, maybe next time*/
+	
+	entry->flags |= HR_STORAGE_FOUND;
+	entry->type = (struct asn_oid)OIDX_hrStorageRam;
+	entry->allocationUnits = page_size_bytes;
+	entry->size = hrState_g.mem_stats.t_rmshr;
+	entry->used = hrState_g.mem_stats.t_armshr; /*ACTIVE is not USED - FIX ME */
+	entry->allocationFailures = 0;						
+	
+}
+
+
+static
 void hrStorage_get_swap_v(void) {
         int nswapdev = 0;
 	int len  = sizeof(nswapdev);
@@ -350,7 +406,8 @@
 	hrState_g.fs_buf = NULL;
 	hrState_g.fs_buf_count = 0;
 
-		
+	memset( &hrState_g.mem_stats, 0, sizeof(hrState_g.mem_stats) );
+			
 	hrState_g.next_hrStorage_index  = 1;
 	
 	STAILQ_INIT(&hrState_g.storage_name_map);
@@ -449,7 +506,7 @@
 /*
 	refresh entries here?!	
 */
-	if ( (time(NULL) - hrState_g.hrStorage_tbl_age) > 7 ) {
+	if ( (time(NULL) - hrState_g.hrStorage_tbl_age) > HR_STORAGE_TBL_REFRESH ) {
 		HR_DPRINTF((stderr, "%s: need refresh\n ",__func__));
 		refresh_hrStorage_tbl_v();
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507161508.j6GF80gS003579>