zabbix-agent2/src/zabbix_agent/cpustat.c
/* array of pointers to "cpu_stat" elements in kstat chain */
array of pointers to "cpu_stat" elements in kstat chain
array of pointers to " cpu_stat " elements in kstat chain
static int	refresh_kstat(ZBX_CPUS_STAT_DATA *pcpus)
{
	static int	cpu_over_count_prev = 0;
	int		cpu_over_count = 0, i, inserted;
	kid_t		id;
	kstat_t		*k;
	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
	for (i = 0; i < pcpus->count; i++)
		(*ksp)[i] = NULL;
	if (-1 == (id = kstat_chain_update(kc)))
	{
		zabbix_log(LOG_LEVEL_ERR, "%s: kstat_chain_update() failed", __func__);
		return FAIL;
	}
	if (0 != id)
		kc_id = id;
	for (k = kc->kc_chain; NULL != k; k = k->ks_next)	
	{
		if (0 == strcmp("cpu_stat", k->ks_module))
		{
			inserted = 0;
			for (i = 1; i <= pcpus->count; i++)	
			{
				if (pcpus->cpu[i].cpu_num == k->ks_instance)	
				{
					(*ksp)[i - 1] = k;
					inserted = 1;
					break;
				}
				if (ZBX_CPUNUM_UNDEF == pcpus->cpu[i].cpu_num)
				{
					pcpus->cpu[i].cpu_num = k->ks_instance;
					(*ksp)[i - 1] = k;
					inserted = 1;
					break;
				}
			}
			if (0 == inserted)	
				cpu_over_count++;
		}
	}
	if (0 < cpu_over_count)
	{
		if (cpu_over_count_prev < cpu_over_count)
		{
			zabbix_log(LOG_LEVEL_WARNING, "%d new processor(s) added. Restart Zabbix agentd to enable"
					" collecting new data.", cpu_over_count - cpu_over_count_prev);
			cpu_over_count_prev = cpu_over_count;
		}
	}
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
	return SUCCEED;
}
static int refresh_kstat ( ZBX_CPUS_STAT_DATA * pcpus ) { static int cpu_over_count_prev = 0 ; int cpu_over_count = 0 , i , inserted ; kid_t id ; kstat_t * k ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; for ( i = 0 ; i < pcpus -> count ; i ++ ) ( * ksp ) [ i ] = NULL ; if ( -1 == ( id = kstat_chain_update ( kc ) ) ) { zabbix_log ( LOG_LEVEL_ERR , " " , __func__ ) ; return FAIL ; } if ( 0 != id ) kc_id = id ; for ( k = kc -> kc_chain ; NULL != k ; k = k -> ks_next ) { if ( 0 == strcmp ( " " , k -> ks_module ) ) { inserted = 0 ; for ( i = 1 ; i <= pcpus -> count ; i ++ ) { if ( pcpus -> cpu [ i ] . cpu_num == k -> ks_instance ) { ( * ksp ) [ i - 1 ] = k ; inserted = 1 ; break ; } if ( ZBX_CPUNUM_UNDEF == pcpus -> cpu [ i ] . cpu_num ) { pcpus -> cpu [ i ] . cpu_num = k -> ks_instance ; ( * ksp ) [ i - 1 ] = k ; inserted = 1 ; break ; } } if ( 0 == inserted ) cpu_over_count ++ ; } } if ( 0 < cpu_over_count ) { if ( cpu_over_count_prev < cpu_over_count ) { zabbix_log ( LOG_LEVEL_WARNING , " " " " , cpu_over_count - cpu_over_count_prev ) ; cpu_over_count_prev = cpu_over_count ; } } zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; return SUCCEED ; }
array of pointers to "cpu_stat" elements in kstat chain
array of pointers to " cpu_stat " elements in kstat chain
/* kstat_chain_update() can return:							*/ /*   - -1 (error),									*/ /*   -  a new kstat chain ID (chain successfully updated),				*/ /*   -  0 (kstat chain was up-to-date). We ignore this case to make refresh_kstat()	*/ /*        usable for first-time initialization as the kstat chain is up-to-date after	*/ /*        kstat_open().									*/ /* traverse all kstat chain */ /* search in our array of ZBX_SINGLE_CPU_STAT_DATAs */ /* CPU instance found */ /* free slot found, most likely first-time initialization */ /* new CPU added, no place to keep its data */