From dc42e3e04d334a3624da5c566fe92c8d3db59f80 Mon Sep 17 00:00:00 2001 From: octo Date: Tue, 11 Apr 2006 19:03:13 +0000 Subject: [PATCH] Renamed `iokit' to `apple_sensors' --- configure.in | 4 +-- src/Makefile.am | 22 ++++++------- src/{iokit.c => apple_sensors.c} | 70 +++++++++++++++++++++++++++++----------- 3 files changed, 64 insertions(+), 32 deletions(-) rename src/{iokit.c => apple_sensors.c} (73%) diff --git a/configure.in b/configure.in index 5b620250..8fd2b489 100644 --- a/configure.in +++ b/configure.in @@ -157,7 +157,7 @@ AC_CHECK_HEADERS(mach/kern_return.h) # For hddtemp module AC_CHECK_HEADERS(linux/major.h) -# For the iokit module +# For the apple_sensors module AC_CHECK_HEADERS(CoreFoundation/CoreFoundation.h) AC_CHECK_HEADERS(IOKit/IOKitLib.h) AC_CHECK_HEADERS(IOKit/IOTypes.h) @@ -789,6 +789,7 @@ AC_COLLECTD([daemon], [disable], [feature], [daemon mode]) m4_divert_once([HELP_ENABLE], [ collectd modules:]) AC_COLLECTD([apache], [disable], [module], [Apache httpd statistics]) +AC_COLLECTD([apple_sensors], [disable], [module], [Apple's hardware sensors]) AC_COLLECTD([battery], [disable], [module], [battery statistics]) AC_COLLECTD([cpu], [disable], [module], [cpu usage statistics]) AC_COLLECTD([cpufreq], [disable], [module], [system cpu frequency statistics]) @@ -796,7 +797,6 @@ AC_COLLECTD([disk], [disable], [module], [disk/partition statistics]) AC_COLLECTD([df], [disable], [module], [df statistics]) AC_COLLECTD([quota], [enable], [module], [quota statistics (experimental)]) AC_COLLECTD([hddtemp], [disable], [module], [hdd temperature statistics]) -AC_COLLECTD([iokit], [disable], [module], [Apple's iokit hardware sensors]) AC_COLLECTD([load], [disable], [module], [system load statistics]) AC_COLLECTD([memory], [disable], [module], [memory statistics]) AC_COLLECTD([mysql], [disable], [module], [mysql statistics]) diff --git a/src/Makefile.am b/src/Makefile.am index c13e9506..dc47b884 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -55,6 +55,17 @@ collectd_LDADD += "-dlopen" apache.la collectd_DEPENDENCIES += apache.la endif +if BUILD_MODULE_APPLE_SENSORS +pkglib_LTLIBRARIES += apple_sensors.la +apple_sensors_la_SOURCES = apple_sensors.c +apple_sensors_la_LDFLAGS = -module -avoid-version +if BUILD_WITH_LIBIOKIT +apple_sensors_la_LDFLAGS += -lIOKit +endif +collectd_LDADD += "-dlopen" apple_sensors.la +collectd_DEPENDENCIES += apple_sensors.la +endif + if BUILD_MODULE_BATTERY pkglib_LTLIBRARIES += battery.la battery_la_SOURCES = battery.c @@ -114,17 +125,6 @@ collectd_LDADD += "-dlopen" hddtemp.la collectd_DEPENDENCIES += hddtemp.la endif -if BUILD_MODULE_IOKIT -pkglib_LTLIBRARIES += iokit.la -iokit_la_SOURCES = iokit.c -iokit_la_LDFLAGS = -module -avoid-version -if BUILD_WITH_LIBIOKIT -iokit_la_LDFLAGS += -lIOKit -endif -collectd_LDADD += "-dlopen" iokit.la -collectd_DEPENDENCIES += iokit.la -endif - if BUILD_MODULE_LOAD pkglib_LTLIBRARIES += load.la load_la_SOURCES = load.c diff --git a/src/iokit.c b/src/apple_sensors.c similarity index 73% rename from src/iokit.c rename to src/apple_sensors.c index 8a533f0f..04a97cc0 100644 --- a/src/iokit.c +++ b/src/apple_sensors.c @@ -1,5 +1,5 @@ /** - * collectd - src/iokit.c + * collectd - src/apple_sensors.c * Copyright (C) 2006 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ #include "plugin.h" #include "utils_debug.h" -#define MODULE_NAME "iokit" +#define MODULE_NAME "apple_sensors" #if HAVE_CTYPE_H # include @@ -59,7 +59,9 @@ static mach_port_t io_master_port; #endif -static char *temperature_file = "temperature-%s.rrd"; +static char *temperature_file = "apple_sensors/temperature-%s.rrd"; +static char *fanspeed_file = "apple_sensors/fanspeed-%s.rrd"; +static char *voltage_file = "apple_sensors/temperature-%s.rrd"; static char *ds_def[] = { @@ -68,7 +70,7 @@ static char *ds_def[] = }; static int ds_num = 1; -static void iokit_init (void) +static void as_init (void) { #if IOKIT_HAVE_READ kern_return_t status; @@ -88,13 +90,35 @@ static void iokit_init (void) return; } +static void as_write (char *host, char *inst, char *val, const char *template) +{ + char filename[256]; + int status; + + status = snprintf (filename, 256, template, inst); + if ((status < 1) || (status >= 256)) + return; + + rrd_update_file (host, filename, val, ds_def, ds_num); +} + static void temperature_write (char *host, char *inst, char *val) { - rrd_update_file (host, temperature_file, val, ds_def, ds_num); + as_write (host, inst, val, temperature_file); +} + +static void fanspeed_write (char *host, char *inst, char *val) +{ + as_write (host, inst, val, fanspeed_file); +} + +static void voltage_write (char *host, char *inst, char *val) +{ + as_write (host, inst, val, voltage_file); } #if IOKIT_HAVE_READ -static void iokit_submit (char *type, char *inst, double value) +static void as_submit (char *type, char *inst, double value) { char buf[128]; @@ -105,7 +129,7 @@ static void iokit_submit (char *type, char *inst, double value) plugin_submit (type, inst, buf); } -static void iokit_read (void) +static void as_read (void) { kern_return_t status; io_iterator_t iterator; @@ -197,21 +221,29 @@ static void iokit_read (void) &value_int)) continue; - if ((strcmp (type, "temperature") == 0) - || (strcmp (type, "fanspeed") == 0) - || (strcmp (type, "voltage") == 0)) + if (strcmp (type, "temperature") == 0) + { + value_double = ((double) value_int) / 65536.0; + strncpy (type, "apple_temperature", 128); + } + else if (strcmp (type, "fanspeed") == 0) { value_double = ((double) value_int) / 65536.0; + strncpy (type, "apple_fanspeed", 128); + } + else if (strcmp (type, "voltage") == 0) + { + value_double = ((double) value_int) / 65536.0; + strncpy (type, "apple_voltage", 128); } else { + DBG ("apple_sensors: Read unknown sensor type: %s", + type); value_double = (double) value_int; } - /* Do stuff */ - DBG ("type = %s, inst = %s, value_int = %i, value_double = %f", - type, inst, value_int, value_double); - iokit_submit (type, inst, value_double); + as_submit (type, inst, value_double); CFRelease (prop_dict); IOObjectRelease (io_obj); @@ -220,15 +252,15 @@ static void iokit_read (void) IOObjectRelease (iterator); } #else -# define iokit_read NULL +# define as_read NULL #endif /* IOKIT_HAVE_READ */ void module_register (void) { - DBG ("IOKIT_HAVE_READ = %i", IOKIT_HAVE_READ); - - plugin_register (MODULE_NAME, iokit_init, iokit_read, NULL); - plugin_register ("iokit-temperature", NULL, NULL, temperature_write); + plugin_register (MODULE_NAME, as_init, as_read, NULL); + plugin_register ("apple_temperature", NULL, NULL, temperature_write); + plugin_register ("apple_fanspeed", NULL, NULL, fanspeed_write); + plugin_register ("apple_voltage", NULL, NULL, voltage_write); } #undef MODULE_NAME -- 2.11.0