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 "zbxjson.h"
22 #include "dbcache.h"
23 #include "valuecache.h"
24 #include "preproc.h"
25 #include "zbxlld.h"
26 #include "log.h"
27 
28 #include "zabbix_stats.h"
29 
30 /******************************************************************************
31  *                                                                            *
32  * Function: zbx_get_zabbix_stats_ext                                         *
33  *                                                                            *
34  * Purpose: get program type (server) specific internal statistics            *
35  *                                                                            *
36  * Parameters: param1  - [IN/OUT] the json data                               *
37  *                                                                            *
38  * Comments: This function is used to gather server specific internal         *
39  *           statistics.                                                      *
40  *                                                                            *
41  ******************************************************************************/
zbx_get_zabbix_stats_ext(struct zbx_json * json)42 void	zbx_get_zabbix_stats_ext(struct zbx_json *json)
43 {
44 	zbx_vc_stats_t	vc_stats;
45 	zbx_uint64_t	queue_size;
46 	char		*error = NULL;
47 
48 	/* zabbix[lld_queue] */
49 	if (SUCCEED == zbx_lld_get_queue_size(&queue_size, &error))
50 	{
51 		zbx_json_adduint64(json, "lld_queue", queue_size);
52 	}
53 	else
54 	{
55 		zabbix_log(LOG_LEVEL_WARNING, "cannot get LLD queue size: %s", error);
56 		zbx_free(error);
57 	}
58 
59 	/* zabbix[triggers] */
60 	zbx_json_adduint64(json, "triggers", DCget_trigger_count());
61 
62 	/* zabbix[vcache,...] */
63 	if (SUCCEED == zbx_vc_get_statistics(&vc_stats))
64 	{
65 		zbx_json_addobject(json, "vcache");
66 
67 		zbx_json_addobject(json, "buffer");
68 		zbx_json_adduint64(json, "total", vc_stats.total_size);
69 		zbx_json_adduint64(json, "free", vc_stats.free_size);
70 		zbx_json_addfloat(json, "pfree", (double)vc_stats.free_size / vc_stats.total_size * 100);
71 		zbx_json_adduint64(json, "used", vc_stats.total_size - vc_stats.free_size);
72 		zbx_json_addfloat(json, "pused", (double)(vc_stats.total_size - vc_stats.free_size) /
73 				vc_stats.total_size * 100);
74 		zbx_json_close(json);
75 
76 		zbx_json_addobject(json, "cache");
77 		zbx_json_adduint64(json, "requests", vc_stats.hits + vc_stats.misses);
78 		zbx_json_adduint64(json, "hits", vc_stats.hits);
79 		zbx_json_adduint64(json, "misses", vc_stats.misses);
80 		zbx_json_adduint64(json, "mode", vc_stats.mode);
81 		zbx_json_close(json);
82 
83 		zbx_json_close(json);
84 	}
85 }
86