zabbix-agent2/src/zabbix_agent/zbxkstat.c
/******************************************************************************
 *                                                                            *
 * Function: zbx_kstat_get_freemem                                            *
 *                                                                            *
 * Purpose: get free memory size                                              *
 *                                                                            *
 * Parameters: value - [OUT] the free memory size in bytes                    *
 *             error - [OUT] the error message                                *
 *                                                                            *
 * Return value: SUCCEED - the free memory size was stored in value           *
 *               FAIL - either an error occurred (error parameter is set) or  *
 *                      data was not collected yet (error parameter is left   *
 *                      unchanged)                                            *
 *                                                                            *
 ******************************************************************************/
zbx_kstat_get_freemem

Purpose: get free memory size

Parameters: value - [OUT] the free memory size in bytes
error - [OUT] the error message

Return value: SUCCEED - the free memory size was stored in value
FAIL - either an error occurred (error parameter is set) or
data was not collected yet (error parameter is left
unchanged)
zbx_kstat_get_freemem Purpose : get free memory size Parameters : value - [ OUT ] the free memory size in bytes error - [ OUT ] the error message Return value : SUCCEED - the free memory size was stored in value FAIL - either an error occurred ( error parameter is set ) or data was not collected yet ( error parameter is left unchanged )
int	zbx_kstat_get_freemem(zbx_uint64_t *value, char **error)
{
	int			ret = FAIL, last, prev;
	zbx_kstat_vminfo_t	*vminfo;
	zbx_mutex_lock(kstat_lock);
	if (NULL == collector)
	{
		*error = zbx_strdup(*error, "Collector is not started.");
		goto out;
	}
	last = collector->kstat.vminfo_index;
	prev = last ^ 1;
	vminfo = collector->kstat.vminfo;
	if (0 != vminfo[prev].updates && vminfo[prev].updates < vminfo[last].updates)
	{
		*value = (vminfo[last].freemem - vminfo[prev].freemem) /
				(vminfo[last].updates - vminfo[prev].updates) * sysconf(_SC_PAGESIZE);
		ret = SUCCEED;
	}
out:
	zbx_mutex_unlock(kstat_lock);
	return ret;
}
int zbx_kstat_get_freemem ( zbx_uint64_t * value , char * * error ) { int ret = FAIL , last , prev ; zbx_kstat_vminfo_t * vminfo ; zbx_mutex_lock ( kstat_lock ) ; if ( NULL == collector ) { * error = zbx_strdup ( * error , " " ) ; goto out ; } last = collector -> kstat . vminfo_index ; prev = last ^ 1 ; vminfo = collector -> kstat . vminfo ; if ( 0 != vminfo [ prev ] . updates && vminfo [ prev ] . updates < vminfo [ last ] . updates ) { * value = ( vminfo [ last ] . freemem - vminfo [ prev ] . freemem ) / ( vminfo [ last ] . updates - vminfo [ prev ] . updates ) * sysconf ( _SC_PAGESIZE ) ; ret = SUCCEED ; } out : zbx_mutex_unlock ( kstat_lock ) ; return ret ; }
Function: zbx_kstat_get_freemem                                            
                                                                            
 Purpose: get free memory size                                              
                                                                            
 Parameters: value - [OUT] the free memory size in bytes                    
             error - [OUT] the error message                                
                                                                            
 Return value: SUCCEED - the free memory size was stored in value           
               FAIL - either an error occurred (error parameter is set) or  
                      data was not collected yet (error parameter is left   
                      unchanged)
Function : zbx_kstat_get_freemem Purpose : get free memory size Parameters : value - [ OUT ] the free memory size in bytes error - [ OUT ] the error message Return value : SUCCEED - the free memory size was stored in value FAIL - either an error occurred ( error parameter is set ) or data was not collected yet ( error parameter is left unchanged )