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 #ifndef ZABBIX_PROCSTAT_H
21 #define ZABBIX_PROCSTAT_H
22 
23 #ifdef ZBX_PROCSTAT_COLLECTOR
24 
25 #define ZBX_PROCSTAT_CPU_USER			0x01
26 #define ZBX_PROCSTAT_CPU_SYSTEM			0x02
27 #define ZBX_PROCSTAT_CPU_TOTAL			(ZBX_PROCSTAT_CPU_USER | ZBX_PROCSTAT_CPU_SYSTEM)
28 
29 #define ZBX_PROCSTAT_FLAGS_ZONE_CURRENT		0
30 #define ZBX_PROCSTAT_FLAGS_ZONE_ALL		1
31 
32 /* process cpu utilization data */
33 typedef struct
34 {
35 	pid_t		pid;
36 
37 	/* errno error code */
38 	int		error;
39 
40 	zbx_uint64_t	utime;
41 	zbx_uint64_t	stime;
42 
43 	/* process start time, used to validate if the old */
44 	/* snapshot data belongs to the same process       */
45 	zbx_uint64_t	starttime;
46 }
47 zbx_procstat_util_t;
48 
49 void	zbx_procstat_init(void);
50 void	zbx_procstat_destroy(void);
51 int	zbx_procstat_collector_started(void);
52 int	zbx_procstat_get_util(const char *procname, const char *username, const char *cmdline, zbx_uint64_t flags,
53 		int period, int type, double *value, char **errmsg);
54 void	zbx_procstat_collect(void);
55 
56 /* external functions used by procstat collector */
57 int	zbx_proc_get_processes(zbx_vector_ptr_t *processes, unsigned int flags);
58 void	zbx_proc_get_matching_pids(const zbx_vector_ptr_t *processes, const char *procname, const char *username,
59 		const char *cmdline, zbx_uint64_t flags, zbx_vector_uint64_t *pids);
60 void	zbx_proc_get_process_stats(zbx_procstat_util_t *procs, int procs_num);
61 void	zbx_proc_free_processes(zbx_vector_ptr_t *processes);
62 
63 #endif	/* ZBX_PROCSTAT_COLLECTOR */
64 
65 #endif	/* ZABBIX_PROCSTAT_H */
66