Skip to content

Commit

Permalink
.......... [DEV-2324] refactored perfstat and listener
Browse files Browse the repository at this point in the history
  • Loading branch information
arimdjonokszabbix committed Aug 17, 2023
1 parent 985c806 commit 92adcc3
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 88 deletions.
4 changes: 2 additions & 2 deletions build/win32/project/Makefile_agent
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ OBJS = \
..\..\..\src\libs\zbxsysinfo\common\stats.o \
..\..\..\src\libs\zbxsysinfo\simple\ntp.o \
..\..\..\src\libs\zbxsysinfo\simple\simple.o \
..\..\..\src\libs\zbxsysinfo\win32\perfstat\perfstat.o \
..\..\..\src\libs\zbxsysinfo\win32\cpu.o \
..\..\..\src\libs\zbxsysinfo\win32\diskio.o \
..\..\..\src\libs\zbxsysinfo\win32\diskspace.o \
Expand All @@ -122,10 +123,9 @@ OBJS = \
..\..\..\src\zabbix_agent\eventlog\eventlog.o \
..\..\..\src\zabbix_agent\eventlog\process_eventslog.o \
..\..\..\src\zabbix_agent\eventlog\process_eventslog6.o \
..\..\..\src\zabbix_agent\listener.o \
..\..\..\src\zabbix_agent\listener\listener.o \
..\..\..\src\zabbix_agent\logfiles\persistent_state.o \
..\..\..\src\zabbix_agent\logfiles\logfiles.o \
..\..\..\src\zabbix_agent\perfstat.o \
..\..\..\src\zabbix_agent\zabbix_agentd.o \
..\..\..\src\zabbix_agent\zbxconf.o \
..\..\..\src\libs\zbxregexp\zbxregexp.o \
Expand Down
6 changes: 6 additions & 0 deletions build/win32/project/Makefile_targets.inc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ $(RESOURCE_RES): $(RESOURCE_RC) $(RESOURCE_H) $(DESC_H)
{..\..\..\src\libs\zbxsysinfo\win32}.c{..\..\..\src\libs\zbxsysinfo\win32}.o:
$(CC) $? /Fo"$@" $(CFLAGS)

{..\..\..\src\libs\zbxsysinfo\win32\perfstat}.c{..\..\..\src\libs\zbxsysinfo\win32\perfstat}.o:
$(CC) $? /Fo"$@" $(CFLAGS)

{..\..\..\src\libs\zbxsysinfo\win32}.cpp{..\..\..\src\libs\zbxsysinfo\win32}.o:
$(CC) $? /Fo"$@" $(CPPFLAGS)

Expand All @@ -132,6 +135,9 @@ $(RESOURCE_RES): $(RESOURCE_RC) $(RESOURCE_H) $(DESC_H)
{..\..\..\src\zabbix_agent\eventlog}.c{..\..\..\src\zabbix_agent\eventlog}.o:
$(CC) $? /Fo"$@" $(CFLAGS)

{..\..\..\src\zabbix_agent\listener}.c{..\..\..\src\zabbix_agent\listener}.o:
$(CC) $? /Fo"$@" $(CFLAGS)

{..\..\..\src\zabbix_agent\logfiles}.c{..\..\..\src\zabbix_agent\logfiles}.o:
$(CC) $? /Fo"$@" $(CFLAGS)

Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,7 @@ AC_CONFIG_FILES([
src/zabbix_agent/Makefile
src/zabbix_agent/logfiles/Makefile
src/zabbix_agent/active_checks/Makefile
src/zabbix_agent/listener/Makefile
src/zabbix_get/Makefile
src/zabbix_java/Makefile
src/zabbix_js/Makefile
Expand Down
18 changes: 18 additions & 0 deletions include/zbxsysinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,22 @@ ZBX_THREAD_ENTRY(collector_thread, args);
int zbx_init_collector_data(char **error);
void zbx_free_collector_data(void);

#if defined(_WINDOWS)
/* perfstat */
#include "zbxwin32.h"
zbx_perf_counter_data_t *zbx_add_perf_counter(const char *name, const char *counterpath, int interval,
zbx_perf_counter_lang_t lang, char **error);
void remove_perf_counter(zbx_perf_counter_data_t *counter);

typedef enum
{
ZBX_SINGLE_THREADED,
ZBX_MULTI_THREADED
}
zbx_threadedness_t;

int zbx_init_perf_collector(zbx_threadedness_t threadedness, char **error);
void zbx_free_perf_collector(void);
#endif

#endif /* ZABBIX_ZBXSYSINFO_H */
8 changes: 4 additions & 4 deletions src/libs/zbxsysinfo/common/cpustat.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "stats.h"
#ifdef _WINDOWS
# include "perfstat.h"
# include "../win32/perfstat/perfstat.h"
# include "../win32/win32_cpu.h"
# include <strsafe.h> /* StringCchPrintf */
#endif
Expand Down Expand Up @@ -172,7 +172,7 @@ int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
if (ERROR_SUCCESS != zbx_PdhMakeCounterPath(__func__, &cpe, counterPath))
goto clean;

if (NULL == (pcpus->cpu_counter[idx] = add_perf_counter(NULL, counterPath,
if (NULL == (pcpus->cpu_counter[idx] = zbx_add_perf_counter(NULL, counterPath,
ZBX_MAX_COLLECTOR_PERIOD, PERF_COUNTER_LANG_DEFAULT, &error)))
{
goto clean;
Expand Down Expand Up @@ -220,7 +220,7 @@ int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
goto clean;

if (NULL == (pcpus->cpu_counter[gidx * cpus_per_group + idx] =
add_perf_counter(NULL, counterPath, ZBX_MAX_COLLECTOR_PERIOD,
zbx_add_perf_counter(NULL, counterPath, ZBX_MAX_COLLECTOR_PERIOD,
PERF_COUNTER_LANG_DEFAULT, &error)))
{
goto clean;
Expand All @@ -236,7 +236,7 @@ int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
if (ERROR_SUCCESS != zbx_PdhMakeCounterPath(__func__, &cpe, counterPath))
goto clean;

if (NULL == (pcpus->queue_counter = add_perf_counter(NULL, counterPath, ZBX_MAX_COLLECTOR_PERIOD,
if (NULL == (pcpus->queue_counter = zbx_add_perf_counter(NULL, counterPath, ZBX_MAX_COLLECTOR_PERIOD,
PERF_COUNTER_LANG_DEFAULT, &error)))
{
goto clean;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/zbxsysinfo/common/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#ifdef _WINDOWS
# include "zbxwinservice.h"
# include "perfstat.h"
# include "../win32/perfstat/perfstat.h"
/* defined in sysinfo lib */
extern int get_cpu_num_win32(void);
#else
Expand Down
2 changes: 1 addition & 1 deletion src/libs/zbxsysinfo/win32/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "win32_cpu.h"

#include "../common/stats.h"
#include "perfstat.h"
#include "perfstat/perfstat.h"

/* shortcut to avoid extra verbosity */
typedef PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX PSYS_LPI_EX;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/zbxsysinfo/win32/pdhmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "zbxalgo.h"
#include "zbxlog.h"

#include "perfstat.h"
#include "perfstat/perfstat.h"

int user_perf_counter(AGENT_REQUEST *request, AGENT_RESULT *result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "zbxstr.h"

#define OBJECT_CACHE_REFRESH_INTERVAL 60
#define NAMES_UPDATE_INTERVAL 60

struct object_name_ref
{
Expand Down Expand Up @@ -74,11 +73,11 @@ static void deactivate_perf_counter(zbx_perf_counter_data_t *counter)

/******************************************************************************
* *
* Comments: if the specified counter exists or the new one is successfully *
* added, a pointer to that counter is returned, NULL otherwise *
* Comments: If the specified counter exists or the new one is successfully *
* added, a pointer to that counter is returned, NULL otherwise. *
* *
******************************************************************************/
zbx_perf_counter_data_t *add_perf_counter(const char *name, const char *counterpath, int interval,
zbx_perf_counter_data_t *zbx_add_perf_counter(const char *name, const char *counterpath, int interval,
zbx_perf_counter_lang_t lang, char **error)
{
zbx_perf_counter_data_t *cptr = NULL;
Expand Down Expand Up @@ -163,11 +162,10 @@ zbx_perf_counter_data_t *add_perf_counter(const char *name, const char *counterp

/******************************************************************************
* *
* Purpose: extends the performance counter buffer to store the new data *
* interval *
* Purpose: extends performance counter buffer to store new data interval *
* *
* Parameters: result - [IN] the performance counter *
* interval - [IN] the new data collection interval in seconds *
* Parameters: counter - [IN] *
* interval - [IN] new data collection interval in seconds *
* *
******************************************************************************/
static void extend_perf_counter_interval(zbx_perf_counter_data_t *counter, int interval)
Expand All @@ -180,13 +178,12 @@ static void extend_perf_counter_interval(zbx_perf_counter_data_t *counter, int i
/* move the data to the end to keep the ring buffer intact */
if (counter->value_current < counter->value_count)
{
int i;
double *src, *dst;

src = &counter->value_array[counter->interval - 1];
dst = &counter->value_array[interval - 1];

for (i = 0; i < counter->value_count - counter->value_current; i++)
for (int i = 0; i < counter->value_count - counter->value_current; i++)
*dst-- = *src--;
}

Expand All @@ -195,9 +192,7 @@ static void extend_perf_counter_interval(zbx_perf_counter_data_t *counter, int i

static void free_object_names(void)
{
int i;

for (i = 0; i < object_num; i++)
for (int i = 0; i < object_num; i++)
{
zbx_free(object_names[i].eng_name);
zbx_free(object_names[i].loc_name);
Expand All @@ -209,8 +204,8 @@ static void free_object_names(void)

/******************************************************************************
* *
* Purpose: obtains PDH object localized names and associates them with *
* English names, to be used by perf_instance_en.discovery *
* Purpose: Obtains PDH object localized names and associates them with *
* English names, to be used by perf_instance_en.discovery. *
* *
* Return value: SUCCEED/FAIL *
* *
Expand All @@ -226,12 +221,13 @@ static int set_object_names(void)
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);

LOCK_PERFCOUNTERS;

#define NAMES_UPDATE_INTERVAL 60
if (ppsd.lastupdate_names + NAMES_UPDATE_INTERVAL >= time(NULL))
{
ret = SUCCEED;
goto out;
}
#undef NAMES_UPDATE_INTERVAL

if (ppsd.lastrefresh_objects + OBJECT_CACHE_REFRESH_INTERVAL > time(NULL))
refresh = FALSE;
Expand Down Expand Up @@ -335,8 +331,8 @@ static int set_object_names(void)

/******************************************************************************
* *
* Comments: counter is removed from the collector and *
* the memory is freed - do not use it again *
* Comments: Counter is removed from the collector and *
* the memory is freed - do not use it again. *
* *
******************************************************************************/
void remove_perf_counter(zbx_perf_counter_data_t *counter)
Expand Down Expand Up @@ -392,8 +388,8 @@ static void free_perf_counter_list(void)

/******************************************************************************
* *
* Comments: must be called only for PERF_COUNTER_ACTIVE counters, *
* interval must be less than or equal to counter->interval *
* Comments: Must be called only for PERF_COUNTER_ACTIVE counters, *
* interval must be less than or equal to counter->interval. *
* *
******************************************************************************/
static double compute_average_value(zbx_perf_counter_data_t *counter, int interval)
Expand All @@ -418,7 +414,7 @@ static double compute_average_value(zbx_perf_counter_data_t *counter, int interv
return sum / (double)count;
}

int init_perf_collector(zbx_threadedness_t threadedness, char **error)
int zbx_init_perf_collector(zbx_threadedness_t threadedness, char **error)
{
int ret = FAIL;

Expand Down Expand Up @@ -463,7 +459,7 @@ int init_perf_collector(zbx_threadedness_t threadedness, char **error)
return ret;
}

void free_perf_collector(void)
void zbx_free_perf_collector(void)
{
zbx_perf_counter_data_t *cptr;

Expand Down Expand Up @@ -621,13 +617,13 @@ void collect_perfstat(void)
* *
* Purpose: gets average named performance counter value *
* *
* Parameters: name - [IN] the performance counter name *
* value - [OUT] the calculated value *
* error - [OUT] the error message, it is not always produced *
* when FAIL is returned. It is a caller responsibility *
* Parameters: name - [IN] performance counter name *
* value - [OUT] calculated value *
* error - [OUT] Error message, it is not always produced *
* when FAIL is returned. It is a caller's responsibility *
* to check if the error message is not NULL. *
* *
* Returns: SUCCEED - the value was retrieved successfully *
* Returns: SUCCEED - value was retrieved successfully *
* FAIL - otherwise *
* *
* Comments: The value is retrieved from collector (if it has been requested *
Expand Down Expand Up @@ -698,13 +694,13 @@ int get_perf_counter_value_by_name(const char *name, double *value, char **error
* *
* Purpose: gets average performance counter value *
* *
* Parameters: counterpath - [IN] the performance counter path *
* interval - [IN] the data collection interval in seconds *
* Parameters: counterpath - [IN] performance counter path *
* interval - [IN] data collection interval in seconds *
* lang - [IN] counterpath language (default or English) *
* value - [OUT] the calculated value *
* error - [OUT] the error message *
* value - [OUT] calculated value *
* error - [OUT] error message *
* *
* Returns: SUCCEED - the value was retrieved successfully *
* Returns: SUCCEED - value was retrieved successfully *
* FAIL - otherwise *
* *
* Comments: The value is retrieved from collector (if it has been requested *
Expand Down Expand Up @@ -748,7 +744,7 @@ int get_perf_counter_value_by_path(const char *counterpath, int interval, zbx_pe

/* if the requested counter is not already being monitored - start monitoring */
if (NULL == perfs)
perfs = add_perf_counter(NULL, counterpath, interval, lang, error);
perfs = zbx_add_perf_counter(NULL, counterpath, interval, lang, error);
out:
UNLOCK_PERFCOUNTERS;

Expand All @@ -766,14 +762,14 @@ int get_perf_counter_value_by_path(const char *counterpath, int interval, zbx_pe

/******************************************************************************
* *
* Purpose: gets average value of the specified performance counter interval *
* Purpose: gets average value of specified performance counter interval *
* *
* Parameters: counter - [IN] the performance counter *
* interval - [IN] the data collection interval in seconds *
* value - [OUT] the calculated value *
* error - [OUT] the error message *
* Parameters: counter - [IN] performance counter *
* interval - [IN] data collection interval in seconds *
* value - [OUT] calculated value *
* error - [OUT] error message *
* *
* Returns: SUCCEED - the value was retrieved successfully *
* Returns: SUCCEED - value was retrieved successfully *
* FAIL - otherwise *
* *
******************************************************************************/
Expand Down Expand Up @@ -837,14 +833,13 @@ int refresh_object_cache(void)
static wchar_t *get_object_name(char *eng_name)
{
wchar_t *loc_name = NULL;
int i;
size_t len;

LOCK_PERFCOUNTERS;

len = strlen(eng_name);

for (i = 0; i < object_num; i++)
for (int i = 0; i < object_num; i++)
{
if (NULL != object_names[i].eng_name && len == strlen(object_names[i].eng_name) &&
0 == zbx_strncasecmp(object_names[i].eng_name, eng_name, len))
Expand All @@ -865,11 +860,9 @@ static wchar_t *get_object_name(char *eng_name)

/******************************************************************************
* *
* Purpose: get localized name of the object *
* *
* Parameters: eng_name - [IN] english name *
* Purpose: gets localized name of object *
* *
* Returns: localized name of the object *
* Parameters: eng_name - [IN] *
* *
******************************************************************************/
wchar_t *get_object_name_local(char *eng_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@

#include "zbxwin32.h"

zbx_perf_counter_data_t *add_perf_counter(const char *name, const char *counterpath, int interval,
zbx_perf_counter_lang_t lang, char **error);
void remove_perf_counter(zbx_perf_counter_data_t *counter);

typedef enum
{
ZBX_SINGLE_THREADED,
ZBX_MULTI_THREADED
}
zbx_threadedness_t;

int init_perf_collector(zbx_threadedness_t threadedness, char **error);
void free_perf_collector(void);
void collect_perfstat(void);

int get_perf_counter_value_by_name(const char *name, double *value, char **error);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/zbxwin32/perfmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ static int validate_object_counter(DWORD object, DWORD counter)
* Return value: SUCCEED/FAIL *
* *
* Comments: This function should be normally called during agent *
* initialization from init_perf_collector(). *
* initialization from zbx_init_perf_collector(). *
* *
******************************************************************************/
int zbx_init_builtin_counter_indexes(void)
Expand Down
1 change: 0 additions & 1 deletion src/libs/zbxwinservice/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "zbxstr.h"
#include "cfg.h"
#include "zbxlog.h"
#include "zbxconf.h"

#include <strsafe.h> /* StringCchPrintf */

Expand Down
Loading

0 comments on commit 92adcc3

Please sign in to comment.