X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcpufreq.c;h=ba0149ad1f390298af4049690cc56c9458f4c8b7;hb=73f68e879976ecee72dba83317e2d015cdf65467;hp=92f1cc5824dc905ebc835e90f2f54d013e9c36d7;hpb=73681054cbff428d352d8ed707d24fab1bf67b24;p=collectd.git diff --git a/src/cpufreq.c b/src/cpufreq.c index 92f1cc58..ba0149ad 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -1,6 +1,6 @@ /** * collectd - src/cpufreq.c - * Copyright (C) 2005 Peter Holik + * Copyright (C) 2005,2006 Peter Holik * * 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 @@ -26,11 +26,17 @@ #define MODULE_NAME "cpufreq" +#if defined(KERNEL_LINUX) +# define CPUFREQ_HAVE_READ 1 +#else +# define CPUFREQ_HAVE_READ 0 +#endif + static char *cpufreq_file = "cpufreq-%s.rrd"; static char *ds_def[] = { - "DS:value:GAUGE:25:0:U", + "DS:value:GAUGE:"COLLECTD_HEARTBEAT":0:U", NULL }; static int ds_num = 1; @@ -51,7 +57,7 @@ static void cpufreq_init (void) while (1) { - status = snprintf (filename, BUFSIZE, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq", num_cpu); + status = snprintf (filename, BUFSIZE, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", num_cpu); if (status < 1 || status >= BUFSIZE) break; @@ -79,6 +85,7 @@ static void cpufreq_write (char *host, char *inst, char *val) rrd_update_file (host, file, val, ds_def, ds_num); } +#if CPUFREQ_HAVE_READ static void cpufreq_submit (int cpu_num, unsigned long long val) { char buf[BUFSIZE]; @@ -103,7 +110,7 @@ static void cpufreq_read (void) for (i = 0; i < num_cpu; i++) { - status = snprintf (filename, BUFSIZE, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq", i); + status = snprintf (filename, BUFSIZE, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i); if (status < 1 || status >= BUFSIZE) return; @@ -116,6 +123,7 @@ static void cpufreq_read (void) if (fgets (buffer, 16, fp) == NULL) { syslog (LOG_WARNING, "cpufreq: fgets: %s", strerror (errno)); + fclose (fp); return; } @@ -131,6 +139,9 @@ static void cpufreq_read (void) return; } +#else +#define cpufreq_read NULL +#endif #undef BUFSIZE void module_register (void)