I just upgraded from collectd-5.4.2 to 5.5.0 on my mac and the cpu plugin 
stopped working.  The error in the log was "cpu plugin: processor_info returned 
only 4 elements..”.

The complaint is correct, osx only reports 4 cpu states: user, nice, system and 
idle.  Version 5.4.2 correctly handles this, but 5.5.0 is broken.

The code in cpu.c is incorrectly expecting the processor_info system call to 
return the wrong number of states (COLLECTD_CPU_STATE_MAX vs CPU_STATE_MAX).  
It’s also expecting the indexes into the array to match it’s internal indexes 
(COLLECTD_CPU_STATE_USER vs CPU_STATE_USER, COLLECTD_CPU_STATE_NICE vs 
CPU_STATE_NICE, etc.).

I’ve made the following changes to make it work on osx, but I’m not sure if 
this breaks it on any other platform:

*** collectd-5.5.0.orig/src/cpu.c       Tue Mar 10 10:14:45 2015
--- collectd-5.5.0/src/cpu.c    Fri May 29 11:04:56 2015
***************
*** 582,597 ****
                        continue;
                }
  
!               if (cpu_info_len < COLLECTD_CPU_STATE_MAX)
                {
                        ERROR ("cpu plugin: processor_info returned only %i 
elements..", cpu_info_len);
                        continue;
                }
  
!               cpu_stage (cpu, COLLECTD_CPU_STATE_USER,   (derive_t) 
cpu_info.cpu_ticks[COLLECTD_CPU_STATE_USER],   now);
!               cpu_stage (cpu, COLLECTD_CPU_STATE_NICE,   (derive_t) 
cpu_info.cpu_ticks[COLLECTD_CPU_STATE_NICE],   now);
!               cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) 
cpu_info.cpu_ticks[COLLECTD_CPU_STATE_SYSTEM], now);
!               cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE,   (derive_t) 
cpu_info.cpu_ticks[COLLECTD_CPU_STATE_IDLE],   now);
        }
  /* }}} #endif PROCESSOR_CPU_LOAD_INFO */
  
--- 582,597 ----
                        continue;
                }
  
!               if (cpu_info_len < CPU_STATE_MAX)
                {
                        ERROR ("cpu plugin: processor_info returned only %i 
elements..", cpu_info_len);
                        continue;
                }
  
!               cpu_stage (cpu, COLLECTD_CPU_STATE_USER,   (derive_t) 
cpu_info.cpu_ticks[CPU_STATE_USER],   now);
!               cpu_stage (cpu, COLLECTD_CPU_STATE_NICE,   (derive_t) 
cpu_info.cpu_ticks[CPU_STATE_NICE],   now);
!               cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) 
cpu_info.cpu_ticks[CPU_STATE_SYSTEM], now);
!               cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE,   (derive_t) 
cpu_info.cpu_ticks[CPU_STATE_IDLE],   now);
        }
  /* }}} #endif PROCESSOR_CPU_LOAD_INFO */


_______________________________________________
collectd mailing list
collectd@verplant.org
http://mailman.verplant.org/listinfo/collectd

Reply via email to