diff options
author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-03-12 15:24:16 +0000 |
---|---|---|
committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-03-12 15:24:16 +0000 |
commit | 883163bc42892ffe0885e94b701ef9da4da3cf70 (patch) | |
tree | d9b8592102201e0396de3807a223d5b87c72f1bd /src/zabbix_agent | |
parent | e929cc4053168b46b81475715e98230eed01badc (diff) | |
download | zabbix-883163bc42892ffe0885e94b701ef9da4da3cf70.tar.gz zabbix-883163bc42892ffe0885e94b701ef9da4da3cf70.tar.xz zabbix-883163bc42892ffe0885e94b701ef9da4da3cf70.zip |
- fixed system.cpu.util[] (Eugene)
- improved configuration script (Eugene)
- fixed floats values (Eugene)
- developed agent result convertion (Eugene)
- more fixes
- TODO: WinXX agent \!\!\!
git-svn-id: svn://svn.zabbix.com/trunk@3886 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_agent')
-rw-r--r-- | src/zabbix_agent/Makefile.am | 18 | ||||
-rw-r--r-- | src/zabbix_agent/cpustat.c | 368 | ||||
-rw-r--r-- | src/zabbix_agent/cpustat.h | 44 | ||||
-rw-r--r-- | src/zabbix_agent/diskdevices.c | 36 | ||||
-rw-r--r-- | src/zabbix_agent/diskdevices.h | 16 | ||||
-rw-r--r-- | src/zabbix_agent/interfaces.c | 20 | ||||
-rw-r--r-- | src/zabbix_agent/interfaces.h | 8 | ||||
-rw-r--r-- | src/zabbix_agent/listener.c | 28 | ||||
-rw-r--r-- | src/zabbix_agent/stats.c | 7 | ||||
-rw-r--r-- | src/zabbix_agent/stats.h | 1 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agent.c | 2 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agentd.c | 25 | ||||
-rw-r--r-- | src/zabbix_agent/zbxconf.c | 7 |
13 files changed, 299 insertions, 281 deletions
diff --git a/src/zabbix_agent/Makefile.am b/src/zabbix_agent/Makefile.am index 87af71a2..c5b2fe43 100644 --- a/src/zabbix_agent/Makefile.am +++ b/src/zabbix_agent/Makefile.am @@ -1,8 +1,10 @@ ## Process this file with automake to produce Makefile.in agents_ldadd = \ - $(top_srcdir)/src/libs/zbxsysinfo/libzbxsysinfo.a \ - $(top_srcdir)/src/libs/zbxsysinfo/$(ARCH)/libzbxsysinfo2.a \ + $(top_srcdir)/src/libs/zbxsysinfo/libzbxagentsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/$(ARCH)/libspecsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ $(top_srcdir)/src/libs/zbxnix/libzbxnix.a \ @@ -17,14 +19,14 @@ bin_PROGRAMS = \ zabbix_agent_SOURCES = \ zabbix_agent.c zabbix_agent.h \ + stats.c stats.h \ + cpustat.c cpustat.h \ + diskdevices.c diskdevices.h \ + interfaces.c interfaces.h \ zbxconf.c zbxconf.h zabbix_agent_LDADD = $(agents_ldadd) -zabbix_agent_CPPFLAGS = $(LDAP_CPPFLAGS) - -zabbix_agent_LDFLAGS = $(LDAP_LDFLAGS) - zabbix_agentd_SOURCES = \ active.c active.h \ stats.c stats.h \ @@ -39,6 +41,4 @@ zabbix_agentd_SOURCES = \ zabbix_agentd_LDADD = $(agents_ldadd) -zabbix_agentd_CPPFLAGS = -DZABBIX_DAEMON $(LDAP_CPPFLAGS) - -zabbix_agentd_LDFLAGS = $(LDAP_LDFLAGS) +zabbix_agentd_CPPFLAGS = -DZABBIX_DAEMON diff --git a/src/zabbix_agent/cpustat.c b/src/zabbix_agent/cpustat.c index 74a248c0..c5ebd9b1 100644 --- a/src/zabbix_agent/cpustat.c +++ b/src/zabbix_agent/cpustat.c @@ -23,28 +23,7 @@ #include "log.h" #ifdef _WINDOWS - #include "perfmon.h" - -#else /* not _WINDOWS */ - - static int get_cpustat( - int *now, - float *cpu_user, - float *cpu_system, - float *cpu_nice, - float *cpu_idle - ); - - static void apply_cpustat( - ZBX_CPUS_STAT_DATA *pcpus, - int now, - float cpu_user, - float cpu_system, - float cpu_nice, - float cpu_idle - ); - #endif /* _WINDOWS */ @@ -193,6 +172,191 @@ void close_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus) } +#if !defined(_WINDOWS) + +static int get_cpustat(int *now,zbx_uint64_t *cpu_user,zbx_uint64_t *cpu_system,zbx_uint64_t *cpu_nice,zbx_uint64_t *cpu_idle) +{ + #if defined(HAVE_PROC_STAT) + + FILE *file; + char line[MAX_STRING_LEN]; + + #elif defined(HAVE_SYS_PSTAT_H) /* not HAVE_PROC_STAT */ + + struct pst_dynamic stats; + + #else /* not HAVE_SYS_PSTAT_H */ + + return 1; + + #endif /* HAVE_PROC_STAT */ + + *now = time(NULL); + + #if defined(HAVE_PROC_STAT) + + if(NULL == (file = fopen("/proc/stat","r") )) + { + zbx_error("Cannot open [%s] [%s]\n","/proc/stat", strerror(errno)); + return 1; + } + + *cpu_user = *cpu_nice = *cpu_system = *cpu_idle = -1; + + while(fgets(line,1024,file) != NULL) + { + if(strstr(line,"cpu ") == NULL) continue; + + sscanf(line, "cpu " ZBX_FS_UI64 " " ZBX_FS_UI64 " " ZBX_FS_UI64 " " ZBX_FS_UI64, cpu_user, cpu_nice, cpu_system, cpu_idle); + break; + } + zbx_fclose(file); + + if(*cpu_user < 0) + return 1; + + #elif defined(HAVE_SYS_PSTAT_H) /* HAVE_PROC_STAT */ + + pstat_getdynamic(&stats, sizeof( struct pst_dynamic ), 1, 0 ); + *cpu_user = (zbx_uint64_t)stats.psd_cpu_time[CP_USER]; + *cpu_nice = (zbx_uint64_t)stats.psd_cpu_time[CP_NICE]; + *cpu_system = (zbx_uint64_t)stats.psd_cpu_time[CP_SYS]; + *cpu_idle = (zbx_uint64_t)stats.psd_cpu_time[CP_IDLE]; + + #endif /* HAVE_SYS_PSTAT_H */ + return 0; +} + + +static void apply_cpustat( + ZBX_CPUS_STAT_DATA *pcpus, + int now, + zbx_uint64_t cpu_user, + zbx_uint64_t cpu_system, + zbx_uint64_t cpu_nice, + zbx_uint64_t cpu_idle + ) +{ + register int i = 0; + + int time = 0, + time1 = 0, + time5 = 0, + time15 = 0; + + zbx_uint64_t + idle, + idle1, + idle5, + idle15, + user, + user1, + user5, + user15, + system, + system1, + system5, + system15, + nice, + nice1, + nice5, + nice15, + all, + all1, + all5, + all15; + + + for(i=0; i < MAX_CPU_HISTORY; i++) + { + if(pcpus->clock[i] < now - MAX_CPU_HISTORY) + { + pcpus->clock[i] = now; + + user = pcpus->h_user[i] = cpu_user; + system = pcpus->h_system[i] = cpu_system; + nice = pcpus->h_nice[i] = cpu_nice; + idle = pcpus->h_idle[i] = cpu_idle; + + all = cpu_idle + cpu_user + cpu_nice + cpu_system; + break; + } + } + + time = time1 = time5 = time15 = now+1; + + for(i=0; i < MAX_CPU_HISTORY; i++) + { + if(0 == pcpus->clock[i]) continue; + + if(pcpus->clock[i] == now) + { + idle = pcpus->h_idle[i]; + user = pcpus->h_user[i]; + nice = pcpus->h_nice[i]; + system = pcpus->h_system[i]; + all = idle + user + nice + system; + } + + if((pcpus->clock[i] >= (now - 60)) && (time1 > pcpus->clock[i])) + { + time1 = pcpus->clock[i]; + idle1 = pcpus->h_idle[i]; + user1 = pcpus->h_user[i]; + nice1 = pcpus->h_nice[i]; + system1 = pcpus->h_system[i]; + all1 = idle1 + user1 + nice1 + system1; + } + if((pcpus->clock[i] >= (now - (5*60))) && (time5 > pcpus->clock[i])) + { + time5 = pcpus->clock[i]; + idle5 = pcpus->h_idle[i]; + user5 = pcpus->h_user[i]; + nice5 = pcpus->h_nice[i]; + system5 = pcpus->h_system[i]; + all5 = idle5 + user5 + nice5 + system5; + } + if((pcpus->clock[i] >= (now - (15*60))) && (time15 > pcpus->clock[i])) + { + time15 = pcpus->clock[i]; + idle15 = pcpus->h_idle[i]; + user15 = pcpus->h_user[i]; + nice15 = pcpus->h_nice[i]; + system15 = pcpus->h_system[i]; + all15 = idle15 + user15 + nice15 + system15; + } + } + +#define CALC_CPU_LOAD(type, time) \ + if((type) - (type ## time) > 0 && (all) - (all ## time) > 0) \ + { \ + pcpus->type ## time = 100. * ((double)((type) - (type ## time)))/ \ + ((double)((all) - (all ## time))); \ + } \ + else \ + { \ + pcpus->type ## time = 0.; \ + } + + CALC_CPU_LOAD(idle, 1); + CALC_CPU_LOAD(idle, 5); + CALC_CPU_LOAD(idle, 15); + + CALC_CPU_LOAD(user, 1); + CALC_CPU_LOAD(user, 5); + CALC_CPU_LOAD(user, 15); + + CALC_CPU_LOAD(nice, 1); + CALC_CPU_LOAD(nice, 5); + CALC_CPU_LOAD(nice, 15); + + CALC_CPU_LOAD(system, 1); + CALC_CPU_LOAD(system, 5); + CALC_CPU_LOAD(system, 15); +} + +#endif /* not _WINDOWS */ + void collect_cpustat(ZBX_CPUS_STAT_DATA *pcpus) { #ifdef _WINDOWS @@ -306,7 +470,7 @@ void collect_cpustat(ZBX_CPUS_STAT_DATA *pcpus) #else /* not _WINDOWS */ int now = 0; - float cpu_user, cpu_nice, cpu_system, cpu_idle; + zbx_uint64_t cpu_user, cpu_nice, cpu_system, cpu_idle; if(0 != get_cpustat(&now, &cpu_user, &cpu_system, &cpu_nice, &cpu_idle)) @@ -316,163 +480,3 @@ void collect_cpustat(ZBX_CPUS_STAT_DATA *pcpus) #endif /* _WINDOWS */ } - -#if !defined(_WINDOWS) - -static int get_cpustat(int *now,float *cpu_user,float *cpu_system,float *cpu_nice,float *cpu_idle) -{ - #if defined(HAVE_PROC_STAT) - - FILE *file; - char line[MAX_STRING_LEN]; - - #elif defined(HAVE_SYS_PSTAT_H) /* not HAVE_PROC_STAT */ - - struct pst_dynamic stats; - - #else /* not HAVE_SYS_PSTAT_H */ - - return 1; - - #endif /* HAVE_PROC_STAT */ - - *now = time(NULL); - - #if defined(HAVE_PROC_STAT) - - if(NULL == (file = fopen("/proc/stat","r") )) - { - zbx_error("Cannot open [%s] [%s]\n","/proc/stat", strerror(errno)); - return 1; - } - - *cpu_user = *cpu_nice = *cpu_system = *cpu_idle = -1; - - while(fgets(line,1024,file) != NULL) - { - if(strstr(line,"cpu ") == NULL) continue; - - sscanf(line, "cpu %f %f %f %f", cpu_user, cpu_nice, cpu_system, cpu_idle); - break; - } - zbx_fclose(file); - - if(*cpu_user < 0) - return 1; - - #elif defined(HAVE_SYS_PSTAT_H) /* HAVE_PROC_STAT */ - - pstat_getdynamic(&stats, sizeof( struct pst_dynamic ), 1, 0 ); - *cpu_user = (float)stats.psd_cpu_time[CP_USER]; - *cpu_nice = (float)stats.psd_cpu_time[CP_NICE]; - *cpu_system = (float)stats.psd_cpu_time[CP_SYS]; - *cpu_idle = (float)stats.psd_cpu_time[CP_IDLE]; - - #endif /* HAVE_SYS_PSTAT_H */ - return 0; -} - - -#define CALC_CPU_LOAD(now_val, tim_val, now_all_val, tim_all_val) \ - if((now_val) - (tim_val) > 0 && (now_all_val) - (tim_all_val) > 0) \ - { \ - tim_val = 100 * (float)((now_val) - (tim_val)/(now_all_val) - (tim_all_val)); \ - } \ - else \ - { \ - tim_val = 0; \ - } - -static void apply_cpustat( - ZBX_CPUS_STAT_DATA *pcpus, - int now, - float cpu_user, - float cpu_system, - float cpu_nice, - float cpu_idle - ) -{ - int i = 0, - time = 0, - time1 = 0, - time5 = 0, - time15 = 0; - - for(i=0; i < MAX_CPU_HISTORY; i++) - { - if(pcpus->clock[i] < now - MAX_CPU_HISTORY) - { - pcpus->clock[i] = now; - - pcpus->user = pcpus->h_user[i] = cpu_user; - pcpus->system = pcpus->h_system[i] = cpu_system; - pcpus->nice = pcpus->h_nice[i] = cpu_nice; - pcpus->idle = pcpus->h_idle[i] = cpu_idle; - - pcpus->all = cpu_idle + cpu_user + cpu_nice + cpu_system; - break; - } - } - - time = time1 = time5 = time15 = now+1; - - for(i=0; i < MAX_CPU_HISTORY; i++) - { - if(0 == pcpus->clock[i]) continue; - - if(pcpus->clock[i] == now) - { - pcpus->idle = pcpus->h_idle[i]; - pcpus->user = pcpus->h_user[i]; - pcpus->nice = pcpus->h_nice[i]; - pcpus->system = pcpus->h_system[i]; - pcpus->all = pcpus->idle + pcpus->user + pcpus->nice + pcpus->system; - } - - if((pcpus->clock[i] >= (now - 60)) && (time1 > pcpus->clock[i])) - { - time1 = pcpus->clock[i]; - pcpus->idle1 = pcpus->h_idle[i]; - pcpus->user1 = pcpus->h_user[i]; - pcpus->nice1 = pcpus->h_nice[i]; - pcpus->system1 = pcpus->h_system[i]; - pcpus->all1 = pcpus->idle1 + pcpus->user1 + pcpus->nice1 + pcpus->system1; - } - if((pcpus->clock[i] >= (now - (5*60))) && (time5 > pcpus->clock[i])) - { - time5 = pcpus->clock[i]; - pcpus->idle5 = pcpus->h_idle[i]; - pcpus->user5 = pcpus->h_user[i]; - pcpus->nice5 = pcpus->h_nice[i]; - pcpus->system5 = pcpus->h_system[i]; - pcpus->all5 = pcpus->idle5 + pcpus->user5 + pcpus->nice5 + pcpus->system5; - } - if((pcpus->clock[i] >= (now - (15*60))) && (time15 > pcpus->clock[i])) - { - time15 = pcpus->clock[i]; - pcpus->idle15 = pcpus->h_idle[i]; - pcpus->user15 = pcpus->h_user[i]; - pcpus->nice15 = pcpus->h_nice[i]; - pcpus->system15 = pcpus->h_system[i]; - pcpus->all15 = pcpus->idle15 + pcpus->user15 + pcpus->nice15 + pcpus->system15; - } - } - - CALC_CPU_LOAD(pcpus->idle, pcpus->idle1, pcpus->all, pcpus->all1); - CALC_CPU_LOAD(pcpus->idle, pcpus->idle5, pcpus->all, pcpus->all5); - CALC_CPU_LOAD(pcpus->idle, pcpus->idle15, pcpus->all, pcpus->all15); - - CALC_CPU_LOAD(pcpus->user, pcpus->user1, pcpus->all, pcpus->all1); - CALC_CPU_LOAD(pcpus->user, pcpus->user5, pcpus->all, pcpus->all5); - CALC_CPU_LOAD(pcpus->user, pcpus->user15, pcpus->all, pcpus->all15); - - CALC_CPU_LOAD(pcpus->nice, pcpus->nice1, pcpus->all, pcpus->all1); - CALC_CPU_LOAD(pcpus->nice, pcpus->nice5, pcpus->all, pcpus->all5); - CALC_CPU_LOAD(pcpus->nice, pcpus->nice15, pcpus->all, pcpus->all15); - - CALC_CPU_LOAD(pcpus->system, pcpus->system1, pcpus->all, pcpus->all1); - CALC_CPU_LOAD(pcpus->system, pcpus->system5, pcpus->all, pcpus->all5); - CALC_CPU_LOAD(pcpus->system, pcpus->system15, pcpus->all, pcpus->all15); -} - -#endif /* not _WINDOWS */ diff --git a/src/zabbix_agent/cpustat.h b/src/zabbix_agent/cpustat.h index 6a00496c..a23602c9 100644 --- a/src/zabbix_agent/cpustat.h +++ b/src/zabbix_agent/cpustat.h @@ -63,32 +63,26 @@ typedef struct s_cpus_stat_data { + /* private */ int clock[MAX_CPU_HISTORY]; - float h_user[MAX_CPU_HISTORY]; - float h_system[MAX_CPU_HISTORY]; - float h_nice[MAX_CPU_HISTORY]; - float h_idle[MAX_CPU_HISTORY]; - - float idle; - float idle1; - float idle5; - float idle15; - float user; - float user1; - float user5; - float user15; - float system; - float system1; - float system5; - float system15; - float nice; - float nice1; - float nice5; - float nice15; - float all; - float all1; - float all5; - float all15; + zbx_uint64_t h_user[MAX_CPU_HISTORY]; + zbx_uint64_t h_system[MAX_CPU_HISTORY]; + zbx_uint64_t h_nice[MAX_CPU_HISTORY]; + zbx_uint64_t h_idle[MAX_CPU_HISTORY]; + + /* public */ + double idle1; + double idle5; + double idle15; + double user1; + double user5; + double user15; + double system1; + double system5; + double system15; + double nice1; + double nice5; + double nice15; } ZBX_CPUS_STAT_DATA; diff --git a/src/zabbix_agent/diskdevices.c b/src/zabbix_agent/diskdevices.c index eb60ef8f..74351c66 100644 --- a/src/zabbix_agent/diskdevices.c +++ b/src/zabbix_agent/diskdevices.c @@ -238,10 +238,10 @@ void report_stats_diskdevices(FILE *file, int now) * [2] - avg5 * [3] - avg15 */ - float read_io_ops[4]; - float blks_read[4]; - float write_io_ops[4]; - float blks_write[4]; + double read_io_ops[4]; + double blks_read[4]; + double write_io_ops[4]; + double blks_write[4]; int i,j; @@ -321,7 +321,7 @@ void report_stats_diskdevices(FILE *file, int now) if((read_io_ops[0]!=0)&&(read_io_ops[1]!=0)) { - fprintf(file,"disk_read_ops1[%s] %f\n", diskdevices[i].device, (float)((read_io_ops[0]-read_io_ops[1])/(now-time1))); + fprintf(file,"disk_read_ops1[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((read_io_ops[0]-read_io_ops[1])/(now-time1))); } else { @@ -329,7 +329,7 @@ void report_stats_diskdevices(FILE *file, int now) } if((read_io_ops[0]!=0)&&(read_io_ops[2]!=0)) { - fprintf(file,"disk_read_ops5[%s] %f\n", diskdevices[i].device, (float)((read_io_ops[0]-read_io_ops[2])/(now-time5))); + fprintf(file,"disk_read_ops5[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((read_io_ops[0]-read_io_ops[2])/(now-time5))); } else { @@ -337,7 +337,7 @@ void report_stats_diskdevices(FILE *file, int now) } if((read_io_ops[0]!=0)&&(read_io_ops[3]!=0)) { - fprintf(file,"disk_read_ops15[%s] %f\n", diskdevices[i].device, (float)((read_io_ops[0]-read_io_ops[3])/(now-time15))); + fprintf(file,"disk_read_ops15[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((read_io_ops[0]-read_io_ops[3])/(now-time15))); } else { @@ -346,7 +346,7 @@ void report_stats_diskdevices(FILE *file, int now) if((blks_read[0]!=0)&&(blks_read[1]!=0)) { - fprintf(file,"disk_read_blks1[%s] %f\n", diskdevices[i].device, (float)((blks_read[0]-blks_read[1])/(now-time1))); + fprintf(file,"disk_read_blks1[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((blks_read[0]-blks_read[1])/(now-time1))); } else { @@ -354,7 +354,7 @@ void report_stats_diskdevices(FILE *file, int now) } if((blks_read[0]!=0)&&(blks_read[2]!=0)) { - fprintf(file,"disk_read_blks5[%s] %f\n", diskdevices[i].device, (float)((blks_read[0]-blks_read[2])/(now-time5))); + fprintf(file,"disk_read_blks5[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((blks_read[0]-blks_read[2])/(now-time5))); } else { @@ -362,7 +362,7 @@ void report_stats_diskdevices(FILE *file, int now) } if((blks_read[0]!=0)&&(blks_read[3]!=0)) { - fprintf(file,"disk_read_blks15[%s] %f\n", diskdevices[i].device, (float)((blks_read[0]-blks_read[3])/(now-time15))); + fprintf(file,"disk_read_blks15[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((blks_read[0]-blks_read[3])/(now-time15))); } else { @@ -371,7 +371,7 @@ void report_stats_diskdevices(FILE *file, int now) if((write_io_ops[0]!=0)&&(write_io_ops[1]!=0)) { - fprintf(file,"disk_write_ops1[%s] %f\n", diskdevices[i].device, (float)((write_io_ops[0]-write_io_ops[1])/(now-time1))); + fprintf(file,"disk_write_ops1[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((write_io_ops[0]-write_io_ops[1])/(now-time1))); } else { @@ -379,7 +379,7 @@ void report_stats_diskdevices(FILE *file, int now) } if((write_io_ops[0]!=0)&&(write_io_ops[2]!=0)) { - fprintf(file,"disk_write_ops5[%s] %f\n", diskdevices[i].device, (float)((write_io_ops[0]-write_io_ops[2])/(now-time5))); + fprintf(file,"disk_write_ops5[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((write_io_ops[0]-write_io_ops[2])/(now-time5))); } else { @@ -387,7 +387,7 @@ void report_stats_diskdevices(FILE *file, int now) } if((write_io_ops[0]!=0)&&(write_io_ops[3]!=0)) { - fprintf(file,"disk_write_ops15[%s] %f\n", diskdevices[i].device, (float)((write_io_ops[0]-write_io_ops[3])/(now-time15))); + fprintf(file,"disk_write_ops15[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((write_io_ops[0]-write_io_ops[3])/(now-time15))); } else { @@ -396,7 +396,7 @@ void report_stats_diskdevices(FILE *file, int now) if((blks_write[0]!=0)&&(blks_write[1]!=0)) { - fprintf(file,"disk_write_blks1[%s] %f\n", diskdevices[i].device, (float)((blks_write[0]-blks_write[1])/(now-time1))); + fprintf(file,"disk_write_blks1[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((blks_write[0]-blks_write[1])/(now-time1))); } else { @@ -404,7 +404,7 @@ void report_stats_diskdevices(FILE *file, int now) } if((blks_write[0]!=0)&&(blks_write[2]!=0)) { - fprintf(file,"disk_write_blks5[%s] %f\n", diskdevices[i].device, (float)((blks_write[0]-blks_write[2])/(now-time5))); + fprintf(file,"disk_write_blks5[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((blks_write[0]-blks_write[2])/(now-time5))); } else { @@ -412,7 +412,7 @@ void report_stats_diskdevices(FILE *file, int now) } if((blks_write[0]!=0)&&(blks_write[3]!=0)) { - fprintf(file,"disk_write_blks15[%s] %f\n", diskdevices[i].device, (float)((blks_write[0]-blks_write[3])/(now-time15))); + fprintf(file,"disk_write_blks15[%s] " ZBX_FS_DBL "\n", diskdevices[i].device, (double)((blks_write[0]-blks_write[3])/(now-time15))); } else { @@ -424,11 +424,11 @@ void report_stats_diskdevices(FILE *file, int now) } -void add_values_diskdevices(int now,int major,int diskno,float read_io_ops,float blks_read,float write_io_ops,float blks_write) +void add_values_diskdevices(int now,int major,int diskno,double read_io_ops,double blks_read,double write_io_ops,double blks_write) { int i,j; -/* printf("Add_values [%s] [%f] [%f]\n",interface,value_sent,value_received);*/ +/* printf("Add_values [%s] [" ZBX_FS_DBL "] [" ZBX_FS_DBL "]\n",interface,value_sent,value_received);*/ for(i=0;i<MAX_DISKDEVICES;i++) { diff --git a/src/zabbix_agent/diskdevices.h b/src/zabbix_agent/diskdevices.h index 404c66b5..961b3656 100644 --- a/src/zabbix_agent/diskdevices.h +++ b/src/zabbix_agent/diskdevices.h @@ -29,10 +29,10 @@ typedef struct c_single_diskdevice_data int major; int diskno; int clock[60*15]; - float read_io_ops[60*15]; - float blks_read[60*15]; - float write_io_ops[60*15]; - float blks_write[60*15]; + double read_io_ops[60*15]; + double blks_read[60*15]; + double write_io_ops[60*15]; + double blks_write[60*15]; } ZBX_SINGLE_DISKDEVICE_DATA; typedef struct c_diskdevices_data @@ -52,10 +52,10 @@ DISKDEVICE int major; int diskno; int clock[60*15]; - float read_io_ops[60*15]; - float blks_read[60*15]; - float write_io_ops[60*15]; - float blks_write[60*15]; + double read_io_ops[60*15]; + double blks_read[60*15]; + double write_io_ops[60*15]; + double blks_write[60*15]; }; void collect_stats_diskdevices(FILE *outfile); diff --git a/src/zabbix_agent/interfaces.c b/src/zabbix_agent/interfaces.c index eb34a43c..83855278 100644 --- a/src/zabbix_agent/interfaces.c +++ b/src/zabbix_agent/interfaces.c @@ -152,7 +152,7 @@ void report_stats_interfaces(FILE *file, int now) time1=0, time5=0, time15=0; - float + double sent=0, sent1=0, sent5=0, @@ -227,7 +227,7 @@ void report_stats_interfaces(FILE *file, int now) } if((sent!=0)&&(sent1!=0)) { - fprintf(file,"netloadout1[%s] %f\n", interfaces[i].interface, (float)((sent-sent1)/(now-time1))); + fprintf(file,"netloadout1[%s] " ZBX_FS_DBL "\n", interfaces[i].interface, (double)((sent-sent1)/(now-time1))); } else { @@ -235,7 +235,7 @@ void report_stats_interfaces(FILE *file, int now) } if((sent!=0)&&(sent5!=0)) { - fprintf(file,"netloadout5[%s] %f\n", interfaces[i].interface, (float)((sent-sent5)/(now-time5))); + fprintf(file,"netloadout5[%s] " ZBX_FS_DBL "\n", interfaces[i].interface, (double)((sent-sent5)/(now-time5))); } else { @@ -243,7 +243,7 @@ void report_stats_interfaces(FILE *file, int now) } if((sent!=0)&&(sent15!=0)) { - fprintf(file,"netloadout15[%s] %f\n", interfaces[i].interface, (float)((sent-sent15)/(now-time15))); + fprintf(file,"netloadout15[%s] " ZBX_FS_DBL "\n", interfaces[i].interface, (double)((sent-sent15)/(now-time15))); } else { @@ -251,7 +251,7 @@ void report_stats_interfaces(FILE *file, int now) } if((received!=0)&&(received1!=0)) { - fprintf(file,"netloadin1[%s] %f\n", interfaces[i].interface, (float)((received-received1)/(now-time1))); + fprintf(file,"netloadin1[%s] " ZBX_FS_DBL "\n", interfaces[i].interface, (double)((received-received1)/(now-time1))); } else { @@ -259,7 +259,7 @@ void report_stats_interfaces(FILE *file, int now) } if((received!=0)&&(received5!=0)) { - fprintf(file,"netloadin5[%s] %f\n", interfaces[i].interface, (float)((received-received5)/(now-time5))); + fprintf(file,"netloadin5[%s] " ZBX_FS_DBL "\n", interfaces[i].interface, (double)((received-received5)/(now-time5))); } else { @@ -267,7 +267,7 @@ void report_stats_interfaces(FILE *file, int now) } if((received!=0)&&(received15!=0)) { - fprintf(file,"netloadin15[%s] %f\n", interfaces[i].interface, (float)((received-received15)/(now-time15))); + fprintf(file,"netloadin15[%s] " ZBX_FS_DBL "\n", interfaces[i].interface, (double)((received-received15)/(now-time15))); } else { @@ -278,13 +278,13 @@ void report_stats_interfaces(FILE *file, int now) } -void add_values_interfaces(int now,char *interface,float value_sent,float value_received) +void add_values_interfaces(int now,char *interface,double value_sent,double value_received) { int i,j; int bounced; -/* printf("Add_values [%s] [%f] [%f]\n",interface,value_sent,value_received);*/ +/* printf("Add_values [%s] [" ZBX_FS_DBL "] [" ZBX_FS_DBL "]\n",interface,value_sent,value_received);*/ for(i=0;i<MAX_INTERFACE;i++) { @@ -341,7 +341,7 @@ void collect_stats_interfaces(FILE *outfile) int i1,j1; char interface[MAX_STRING_LEN]; int now; - float received=0,sent; + double received=0,sent; /* Must be static */ static int initialised=0; diff --git a/src/zabbix_agent/interfaces.h b/src/zabbix_agent/interfaces.h index 0b72074f..fa2867ff 100644 --- a/src/zabbix_agent/interfaces.h +++ b/src/zabbix_agent/interfaces.h @@ -27,8 +27,8 @@ typedef struct s_single_interface_data { char *name; int clock[60*15]; - float sent[60*15]; - float received[60*15]; + double sent[60*15]; + double received[60*15]; } ZBX_SINGLE_INTERFACE_DATA; typedef struct s_interfaces_data @@ -46,8 +46,8 @@ INTERFACE { char *interface; int clock[60*15]; - float sent[60*15]; - float received[60*15]; + double sent[60*15]; + double received[60*15]; }; void collect_stats_interfaces(FILE *outfile); diff --git a/src/zabbix_agent/listener.c b/src/zabbix_agent/listener.c index 47ad9455..4f0071e3 100644 --- a/src/zabbix_agent/listener.c +++ b/src/zabbix_agent/listener.c @@ -36,14 +36,14 @@ static void process_listener(ZBX_SOCKET sock) { + register char *p; + AGENT_RESULT result; char command[MAX_STRING_LEN]; - char value[MAX_STRING_LEN]; + char **value = NULL; int ret = 0; - init_result(&result); - memset(&command, 0, MAX_STRING_LEN); ret = zbx_sock_read(sock, (void *)command, MAX_STRING_LEN, CONFIG_TIMEOUT); @@ -59,24 +59,24 @@ static void process_listener(ZBX_SOCKET sock) return; } - /*command[ret-2] = '\0'; *//* remove '\r\n' sumbols from recived command (_WINDOWS) !!!TODO!!! correct win32 agent !!!TODO!!! */ - command[ret-1] = '\0'; /* remove '\n' sumbols from recived command (LINUX) !!!TODO!!! */ + for(p = &command[ret - 1]; p >= &command[0] && ('\0' == *p || '\r' == *p || '\n' == *p); p--) *p = '\0'; /* rtrim(\r\n) */ zabbix_log(LOG_LEVEL_DEBUG, "Requested [%s]", command); - process(command, 0, &result); + init_result(&result); - if(result.type & AR_DOUBLE) zbx_snprintf(value, sizeof(value), "%f", result.dbl); - else if(result.type & AR_UINT64) zbx_snprintf(value, sizeof(value), ZBX_FS_UI64, result.ui64); - else if(result.type & AR_STRING) zbx_snprintf(value, sizeof(value), "%s", result.str); - else if(result.type & AR_TEXT) zbx_snprintf(value, sizeof(value), "%s", result.text); - else if(result.type & AR_MESSAGE) zbx_snprintf(value, sizeof(value), "%s", result.msg); + process(command, 0, &result); - free_result(&result); + if( NULL == (value = GET_TEXT_RESULT(&result)) ) + value = GET_MSG_RESULT(&result); - zabbix_log(LOG_LEVEL_DEBUG, "Sending back [%s]", value); + if(value) + { + zabbix_log(LOG_LEVEL_DEBUG, "Sending back [%s]", *value); + ret = zbx_sock_write(sock, *value, (int)strlen(*value)); + } - ret = zbx_sock_write(sock, value, (int)strlen(value)); + free_result(&result); if(ret == SOCKET_ERROR) { diff --git a/src/zabbix_agent/stats.c b/src/zabbix_agent/stats.c index 883df153..c158e382 100644 --- a/src/zabbix_agent/stats.c +++ b/src/zabbix_agent/stats.c @@ -30,11 +30,11 @@ #include "log.h" #include "cfg.h" -#if defined(ZABBIX_SERVICE) +#if defined(_WINDOWS) # include "service.h" -#elif defined(ZABBIX_DAEMON) /* ZABBIX_SERVICE */ +#else # include "daemon.h" -#endif /* ZABBIX_DAEMON */ +#endif /* _WINDOWS */ ZBX_COLLECTOR_DATA *collector = NULL; @@ -194,4 +194,3 @@ ZBX_THREAD_ENTRY(collector_thread, args) zbx_tread_exit(0); } - diff --git a/src/zabbix_agent/stats.h b/src/zabbix_agent/stats.h index e49cf9b6..d750e704 100644 --- a/src/zabbix_agent/stats.h +++ b/src/zabbix_agent/stats.h @@ -34,7 +34,6 @@ typedef struct s_collector_data extern ZBX_COLLECTOR_DATA *collector; - ZBX_THREAD_ENTRY(collector_thread, pSemColectorStarted); void init_collector_data(void); diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c index e115a889..9e4a699b 100644 --- a/src/zabbix_agent/zabbix_agent.c +++ b/src/zabbix_agent/zabbix_agent.c @@ -200,7 +200,7 @@ int main(int argc, char **argv) process(s, 0, &result); if(result.type & AR_DOUBLE) - zbx_snprintf(value, sizeof(value), "%f", result.dbl); + zbx_snprintf(value, sizeof(value), ZBX_FS_DBL, result.dbl); else if(result.type & AR_UINT64) zbx_snprintf(value, sizeof(value), ZBX_FS_UI64, result.ui64); else if(result.type & AR_STRING) diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c index 3abf07b0..e76fab38 100644 --- a/src/zabbix_agent/zabbix_agentd.c +++ b/src/zabbix_agent/zabbix_agentd.c @@ -238,7 +238,9 @@ static ZBX_SOCKET tcp_listen(void) if (bind(sock,(struct sockaddr *)&serv_addr,sizeof(ZBX_SOCKADDR)) == SOCKET_ERROR) { zabbix_log(LOG_LEVEL_CRIT, "Cannot bind to port %u for server %s. Error [%s]. Another zabbix_agentd already running ?", - CONFIG_LISTEN_PORT, CONFIG_LISTEN_IP, strerror_from_system(zbx_sock_last_error())); + CONFIG_LISTEN_PORT, + CONFIG_LISTEN_IP ? CONFIG_LISTEN_IP : "[ANY]", + strerror_from_system(zbx_sock_last_error())); exit(1); } @@ -432,11 +434,30 @@ int main(int argc, char **argv) #else /* ZABBIX_TEST */ -#include "messages.h" +#if defined(_WINDOWS) +# include "messages.h" +#endif /* _WINDOWS */ int main() { #if ON + AGENT_RESULT result; + + SET_UI64_RESULT(&result, 123456789123456789123456789ull); + printf("UI: '" ZBX_FS_UI64 "'\n", result.ui64); + + printf("UI_TO_DBL: '" ZBX_FS_DBL "'\n", *GET_DBL_RESULT(&result)); + + UNSET_RESULT_EXCLUDING(&result, AR_UINT64); + printf("UI_TO_STR: '%s'\n", *GET_STR_RESULT(&result)); + + UNSET_RESULT_EXCLUDING(&result, AR_UINT64); + printf("UI_TO_TEXT: '%s'\n", *GET_TEXT_RESULT(&result)); + + UNSET_RESULT_EXCLUDING(&result, AR_UINT64); + printf("UI_TO_UI64: '" ZBX_FS_UI64 "'\n", *GET_UI64_RESULT(&result)); + +#elif OFF int res, val; if(FAIL == zbx_sock_init()) diff --git a/src/zabbix_agent/zbxconf.c b/src/zabbix_agent/zbxconf.c index a74acf7d..7ad90182 100644 --- a/src/zabbix_agent/zbxconf.c +++ b/src/zabbix_agent/zbxconf.c @@ -99,7 +99,8 @@ void load_config(int exit_on_error) {0} }; - AGENT_RESULT result; + AGENT_RESULT result; + char **value = NULL; memset(&result, 0, sizeof(AGENT_RESULT)); @@ -121,9 +122,9 @@ void load_config(int exit_on_error) { if(SUCCEED == process("system.hostname", 0, &result)) { - if(result.type & AR_STRING) + if( NULL != (value = GET_STR_RESULT(&result)) ) { - CONFIG_HOSTNAME = strdup(result.str); + CONFIG_HOSTNAME = strdup(*value); } } free_result(&result); |