Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the function of init_selfmon_collector function in zabbix

Shulou Source: shulou.com Published: 2022-06-01 18:15:41 10月02日 Update

This article is to share with you about the role of the init_selfmon_collector function in zabbix, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Zbx_free_config ()

Init_database_cache ()

Init_configuration_cache (); / / put the configuration into cache

Init_selfmon_collector (); / / initial process monitoring collection

Void init_selfmon_collector (void)

{

Const char * _ _ function_name = "init_selfmon_collector"

Size_t sz, sz_array, sz_ process[ZBX _ PROCESS_TYPE_COUNT], sz_total

Key_t shm_key

Char * p

Clock_t ticks

Struct tms buf

Unsigned char proc_type

Int proc_num, process_forks

Zabbix_log (LOG_LEVEL_DEBUG, "In% s ()", _ _ function_name)

Sz_total = sz = sizeof (zbx_selfmon_collector_t)

Sz_total + = sz_array = sizeof (zbx_stat_process_t *) * ZBX_PROCESS_TYPE_COUNT

For (proc_type = 0; ZBX_PROCESS_TYPE_COUNT > proc_type; proc_type++)

Sz_total + = sz_ process [proc _ type] = sizeof (zbx_stat_process_t) * get_process_type_forks (proc_type)

Zabbix_log (LOG_LEVEL_DEBUG, "% s () size:" ZBX_FS_SIZE_T, _ _ function_name, (zbx_fs_size_t) sz_total)

If (- 1 = (shm_key = zbx_ftok (CONFIG_FILE, ZBX_IPC_SELFMON_ID)

{

Zabbix_log (LOG_LEVEL_CRIT, "cannot create IPC key for a self-monitoring collector")

Exit (EXIT_FAILURE)

}

If (FAIL = = zbx_mutex_create_force (& sm_lock, ZBX_MUTEX_SELFMON))

{

Zbx_error ("unable to create mutex for a self-monitoring collector")

Exit (EXIT_FAILURE)

}

If (- 1 = (shm_id = zbx_shmget (shm_key, sz_total)

{

Zabbix_log (LOG_LEVEL_CRIT, "cannot allocate shared memory for a self-monitoring collector")

Exit (EXIT_FAILURE)

}

If ((void *) (- 1) = (p = shmat (shm_id, NULL, 0)

{

Zabbix_log (LOG_LEVEL_CRIT, "cannot attach shared memory for a self-monitoring collector:% s"

Zbx_strerror (errno))

Exit (EXIT_FAILURE)

}

Collector = (zbx_selfmon_collector_t *) p; p + = sz

Collector- > process = (zbx_stat_process_t * *) p; p + = sz_array

Ticks = times (& buf)

For (proc_type = 0; ZBX_PROCESS_TYPE_COUNT > proc_type; proc_type++)

{

Collector- > process [proc _ type] = (zbx_stat_process_t *) p; p + = sz_ process [proc _ type]

Memset (collector- > process [proc _ type], 0, sz_ process [proc _ type])

Process_forks = get_process_type_forks (proc_type)

For (proc_num = 0; proc_num)

< process_forks; proc_num++) { collector->

Process [proc _ type] [proc_num] .last _ ticks = ticks

Collector- > process [proc _ type] [proc_num] .last _ state = ZBX_PROCESS_STATE_BUSY

}

}

Zabbix_log (LOG_LEVEL_DEBUG, "End of% s () collector:%p", _ _ function_name, collector)

}

These are the functions of the init_selfmon_collector function in zabbix. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Function function more knowledge article practical that is work meeting article look knowledge point cache industry details information information channel follow process part channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL Shulou Tech Info Xiaomi Shulou Information