projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into processes
[collectd.git]
/
src
/
cpufreq.c
diff --git
a/src/cpufreq.c
b/src/cpufreq.c
index
001ccec
..
ba0149a
100644
(file)
--- a/
src/cpufreq.c
+++ b/
src/cpufreq.c
@@
-1,6
+1,6
@@
/**
* collectd - src/cpufreq.c
/**
* 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
*
* 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
@@
-20,33
+20,36
@@
* Peter Holik <peter at holik.at>
**/
* Peter Holik <peter at holik.at>
**/
-#include "cpufreq.h"
-
-/*
- * Originally written by Peter Holik
- */
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
-#if COLLECT_CPUFREQ
#define MODULE_NAME "cpufreq"
#define MODULE_NAME "cpufreq"
-#include "plugin.h"
-#include "common.h"
-
-static int num_cpu = 0;
+#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[] =
{
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;
NULL
};
static int ds_num = 1;
+#ifdef KERNEL_LINUX
+static int num_cpu = 0;
+#endif
+
#define BUFSIZE 256
#define BUFSIZE 256
-void cpufreq_init (void)
+
static
void cpufreq_init (void)
{
{
+#ifdef KERNEL_LINUX
int status;
char filename[BUFSIZE];
int status;
char filename[BUFSIZE];
@@
-54,7
+57,7
@@
void cpufreq_init (void)
while (1)
{
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;
if (status < 1 || status >= BUFSIZE)
break;
@@
-65,9
+68,12
@@
void cpufreq_init (void)
}
syslog (LOG_INFO, MODULE_NAME" found %d cpu(s)", num_cpu);
}
syslog (LOG_INFO, MODULE_NAME" found %d cpu(s)", num_cpu);
+#endif /* defined(KERNEL_LINUX) */
+
+ return;
}
}
-void cpufreq_write (char *host, char *inst, char *val)
+
static
void cpufreq_write (char *host, char *inst, char *val)
{
int status;
char file[BUFSIZE];
{
int status;
char file[BUFSIZE];
@@
-79,7
+85,8
@@
void cpufreq_write (char *host, char *inst, char *val)
rrd_update_file (host, file, val, ds_def, ds_num);
}
rrd_update_file (host, file, val, ds_def, ds_num);
}
-void cpufreq_submit (int cpu_num, unsigned long long val)
+#if CPUFREQ_HAVE_READ
+static void cpufreq_submit (int cpu_num, unsigned long long val)
{
char buf[BUFSIZE];
char cpu[16];
{
char buf[BUFSIZE];
char cpu[16];
@@
-91,8
+98,9
@@
void cpufreq_submit (int cpu_num, unsigned long long val)
plugin_submit (MODULE_NAME, cpu, buf);
}
plugin_submit (MODULE_NAME, cpu, buf);
}
-void cpufreq_read (void)
+
static
void cpufreq_read (void)
{
{
+#ifdef KERNEL_LINUX
int status;
unsigned long long val;
int i = 0;
int status;
unsigned long long val;
int i = 0;
@@
-102,7
+110,7
@@
void cpufreq_read (void)
for (i = 0; i < num_cpu; i++)
{
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;
if (status < 1 || status >= BUFSIZE)
return;
@@
-115,6
+123,7
@@
void cpufreq_read (void)
if (fgets (buffer, 16, fp) == NULL)
{
syslog (LOG_WARNING, "cpufreq: fgets: %s", strerror (errno));
if (fgets (buffer, 16, fp) == NULL)
{
syslog (LOG_WARNING, "cpufreq: fgets: %s", strerror (errno));
+ fclose (fp);
return;
}
return;
}
@@
-126,7
+135,13
@@
void cpufreq_read (void)
cpufreq_submit (i, val);
}
cpufreq_submit (i, val);
}
+#endif /* defined(KERNEL_LINUX) */
+
+ return;
}
}
+#else
+#define cpufreq_read NULL
+#endif
#undef BUFSIZE
void module_register (void)
#undef BUFSIZE
void module_register (void)
@@
-135,4
+150,3
@@
void module_register (void)
}
#undef MODULE_NAME
}
#undef MODULE_NAME
-#endif /* COLLECT_CPUFREQ */