Welcome to mirror list, hosted at ThFree Co, Russian Federation.

zabbix_stats_server.c « stats « zabbix_server « src - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 39c9a7b6a9b72071efff5856c7f734936f7f9d5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/

#include "zabbix_stats.h"

#include "zbxcommon.h"
#include "zbxcacheconfig.h"
#include "zbxcachevalue.h"
#include "zbxlld.h"
#include "log.h"
#include "zbxtrends.h"
#include "zbxha.h"
#include "zbxcomms.h"

/******************************************************************************
 *                                                                            *
 * Purpose: get program type (server) specific internal statistics            *
 *                                                                            *
 * Parameters: json       - [IN/OUT] the json data                            *
 *             zbx_config - [IN] server config                                *
 *                                                                            *
 * Comments: This function is used to gather server specific internal         *
 *           statistics.                                                      *
 *                                                                            *
 ******************************************************************************/
void	zbx_zabbix_stats_ext_get(struct zbx_json *json, const zbx_config_comms_args_t *zbx_config)
{
	zbx_vc_stats_t		vc_stats;
	zbx_uint64_t		queue_size;
	char			*value, *error = NULL;
	zbx_tfc_stats_t		tcache_stats;

	ZBX_UNUSED(zbx_config);

	/* zabbix[lld_queue] */
	if (SUCCEED == zbx_lld_get_queue_size(&queue_size, &error))
	{
		zbx_json_adduint64(json, "lld_queue", queue_size);
	}
	else
	{
		zabbix_log(LOG_LEVEL_WARNING, "cannot get LLD queue size: %s", error);
		zbx_free(error);
	}

	/* zabbix[triggers] */
	zbx_json_adduint64(json, "triggers", DCget_trigger_count());

	/* zabbix[vcache,...] */
	if (SUCCEED == zbx_vc_get_statistics(&vc_stats))
	{
		zbx_json_addobject(json, "vcache");

		zbx_json_addobject(json, "buffer");
		zbx_json_adduint64(json, "total", vc_stats.total_size);
		zbx_json_adduint64(json, "free", vc_stats.free_size);
		zbx_json_addfloat(json, "pfree", (double)vc_stats.free_size / vc_stats.total_size * 100);
		zbx_json_adduint64(json, "used", vc_stats.total_size - vc_stats.free_size);
		zbx_json_addfloat(json, "pused", (double)(vc_stats.total_size - vc_stats.free_size) /
				vc_stats.total_size * 100);
		zbx_json_close(json);

		zbx_json_addobject(json, "cache");
		zbx_json_adduint64(json, "requests", vc_stats.hits + vc_stats.misses);
		zbx_json_adduint64(json, "hits", vc_stats.hits);
		zbx_json_adduint64(json, "misses", vc_stats.misses);
		zbx_json_addint64(json, "mode", vc_stats.mode);
		zbx_json_close(json);

		zbx_json_close(json);
	}

	/* zabbix[tcache,cache,<parameters>] */
	if (SUCCEED == zbx_tfc_get_stats(&tcache_stats, NULL))
	{
		zbx_uint64_t	total;

		zbx_json_addobject(json, "tcache");

		total = tcache_stats.hits + tcache_stats.misses;
		zbx_json_adduint64(json, "hits", tcache_stats.hits);
		zbx_json_adduint64(json, "misses", tcache_stats.misses);
		zbx_json_adduint64(json, "all", total);
		zbx_json_addfloat(json, "phits", (0 == total ? 0 : (double)tcache_stats.hits / total * 100));
		zbx_json_addfloat(json, "pmisses", (0 == total ? 0 : (double)tcache_stats.misses / total * 100));

		total = tcache_stats.items_num + tcache_stats.requests_num;
		zbx_json_adduint64(json, "items", tcache_stats.items_num);
		zbx_json_adduint64(json, "requests", tcache_stats.requests_num);
		zbx_json_addfloat(json, "pitems", (0 == total ? 0 : (double)tcache_stats.items_num / total * 100));

		zbx_json_close(json);
	}

	if (SUCCEED == zbx_ha_get_nodes(&value, &error))
	{
		zbx_json_addraw(json, "ha", value);
		zbx_free(value);
	}
	else
	{
		zabbix_log(LOG_LEVEL_WARNING, "cannot get HA node data: %s", error);
		zbx_free(error);
	}

	if (SUCCEED == zbx_proxy_discovery_get(&value, &error))
	{
		zbx_json_addraw(json, "proxy", value);
		zbx_free(value);
	}
	else
	{
		zabbix_log(LOG_LEVEL_WARNING, "cannot get proxy data: %s", error);
		zbx_free(error);
	}

	zbx_json_close(json);
}