1 /*
2 ** Zabbix
3 ** Copyright (C) 2001-2021 Zabbix SIA
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **/
19
20 #include "common.h"
21 #include "daemon.h"
22 #include "zbxself.h"
23 #include "log.h"
24 #include "selfmon.h"
25
26 extern unsigned char process_type, program_type;
27 extern int server_num, process_num;
28
ZBX_THREAD_ENTRY(selfmon_thread,args)29 ZBX_THREAD_ENTRY(selfmon_thread, args)
30 {
31 double sec;
32
33 process_type = ((zbx_thread_args_t *)args)->process_type;
34 server_num = ((zbx_thread_args_t *)args)->server_num;
35 process_num = ((zbx_thread_args_t *)args)->process_num;
36
37 zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
38 server_num, get_process_type_string(process_type), process_num);
39
40 update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
41
42 while (ZBX_IS_RUNNING())
43 {
44 sec = zbx_time();
45 zbx_update_env(sec);
46
47 zbx_setproctitle("%s [processing data]", get_process_type_string(process_type));
48
49 collect_selfmon_stats();
50 sec = zbx_time() - sec;
51
52 zbx_setproctitle("%s [processed data in " ZBX_FS_DBL " sec, idle 1 sec]",
53 get_process_type_string(process_type), sec);
54
55 zbx_sleep_loop(ZBX_SELFMON_DELAY);
56 }
57
58 zbx_setproctitle("%s #%d [terminated]", get_process_type_string(process_type), process_num);
59
60 while (1)
61 zbx_sleep(SEC_PER_MIN);
62 }
63