Ad Widget

Collapse

PATCH: CPU util on FreeBSD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brick
    Junior Member
    • Nov 2006
    • 8

    #1

    PATCH: CPU util on FreeBSD

    Hello! Here is a patch which allow use cpu.util in FreeBSD

    +++ src/zabbix_agent/cpustat.c
    @@ -297,7 +297,12 @@
    #elif defined(HAVE_SYS_PSTAT_H) /* HAVE_PROC_STAT */

    struct pst_dynamic stats;
    -
    +
    +#elif defined(HAVE_SYS_SYSCTL_H) /* HAVE_SYS_SYSCTL_H */
    +
    + static long cp_time[5];
    + size_t nlen = sizeof(cp_time);
    +
    #else /* HAVE_SYS_PSTAT_H */

    return;
    @@ -340,7 +345,20 @@
    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];
    -
    +
    +#elif defined(HAVE_SYS_SYSCTL_H) /* HAVE_SYS_SYSCTL_H */
    +
    + if (sysctlbyname("kern.cp_time", &cp_time, &nlen, NULL, 0) == -1)
    + return;
    +
    + if (nlen != sizeof(cp_time))
    + return;
    +
    + cpu_user = (float)cp_time[0];
    + cpu_nice = (float)cp_time[1];
    + cpu_system = (float)cp_time[2];
    + cpu_idle = (float)cp_time[4];
    +
    #endif /* HAVE_SYS_PSTAT_H */

    add_values_cpustat(now,cpu_user, cpu_system, cpu_nice, cpu_idle);
  • jmb
    Junior Member
    • Jul 2007
    • 14

    #2
    Thanks

    Here is the updated patch against 1.4.1
    --- src/zabbix_agent/cpustat.c.ori Thu Aug 2 23:16:31 2007
    +++ src/zabbix_agent/cpustat.c Thu Aug 2 23:52:18 2007
    @@ -184,6 +184,11 @@
    #elif defined(HAVE_SYS_PSTAT_H) /* not HAVE_PROC_STAT */

    struct pst_dynamic stats;
    +
    + #elif defined(HAVE_SYS_SYSCTL_H) /* HAVE_SYS_SYSCTL_H */
    +
    + static long cp_time[5];
    + size_t nlen = sizeof(cp_time);

    #else /* not HAVE_SYS_PSTAT_H */

    @@ -222,6 +227,19 @@
    *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];
    +
    + #elif defined(HAVE_SYS_SYSCTL_H) /* HAVE_SYS_SYSCTL_H */
    +
    + if (sysctlbyname("kern.cp_time", &cp_time, &nlen, NULL, 0) == -1)
    + return;
    +
    + if (nlen != sizeof(cp_time))
    + return;
    +
    + *cpu_user = (zbx_uint64_t)cp_time[0];
    + *cpu_nice = (zbx_uint64_t)cp_time[1];
    + *cpu_system = (zbx_uint64_t)cp_time[2];
    + *cpu_idle = (zbx_uint64_t)cp_time[4];

    #endif /* HAVE_SYS_PSTAT_H */
    return 0;

    Regards jm

    Comment

    • holtet
      Junior Member
      • Aug 2007
      • 9

      #3
      Error?

      I got the following result when patching (the 1.4.1 version):

      $ patch -F3 < cpu.patch
      Hmm... Looks like a unified diff to me...
      The text leading up to this was:
      --------------------------
      |--- src/zabbix_agent/cpustat.c.ori Thu Aug 2 23:16:31 2007
      |+++ src/zabbix_agent/cpustat.c Thu Aug 2 23:52:18 2007
      --------------------------
      Patching file src/zabbix_agent/cpustat.c using Plan A...
      patch: **** malformed patch at line 4: #elif defined(HAVE_SYS_PSTAT_H) /* not HAVE_PROC_STAT */

      I have very little experience using patch, so the problem might be related to that and not the patch itself... Maybe something to do with copying the text, would it be possible to attach the file itself?
      Any help much appreciated.
      Last edited by holtet; 07-08-2007, 16:07.

      Comment

      • jmb
        Junior Member
        • Jul 2007
        • 14

        #4
        Hi,

        Here is the patch file. Have a try with:

        # cd zabbic-1.4.1
        # patch -p0 < ../patch-cpustat.c

        Greets jm
        Attached Files

        Comment

        • holtet
          Junior Member
          • Aug 2007
          • 9

          #5
          It works! Thanks a lot!

          Comment

          • Alexei
            Founder, CEO
            Zabbix Certified Trainer
            Zabbix Certified SpecialistZabbix Certified Professional
            • Sep 2004
            • 5654

            #6
            Thanks for the patch. I hope it will be integrated into 1.4.3.
            Alexei Vladishev
            Creator of Zabbix, Product manager
            New York | Tokyo | Riga
            My Twitter

            Comment

            Working...