projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Various plugins: Change various plugins to use "derive" internally.
[collectd.git]
/
src
/
serial.c
diff --git
a/src/serial.c
b/src/serial.c
index
8f8e433
..
9bd885d
100644
(file)
--- a/
src/serial.c
+++ b/
src/serial.c
@@
-25,52
+25,37
@@
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
-#if defined(KERNEL_LINUX)
-# define SERIAL_HAVE_READ 1
-#else
-# define SERIAL_HAVE_READ 0
+#if !KERNEL_LINUX
+# error "No applicable input method."
#endif
#endif
-static data_source_t octets_dsrc[2] =
-{
- {"rx", DS_TYPE_COUNTER, 0, 4294967295.0},
- {"tx", DS_TYPE_COUNTER, 0, 4294967295.0}
-};
-
-static data_set_t octets_ds =
-{
- "serial_octets", 2, octets_dsrc
-};
-
-#if SERIAL_HAVE_READ
static void serial_submit (const char *type_instance,
static void serial_submit (const char *type_instance,
-
counter_t rx, counter
_t tx)
+
derive_t rx, derive
_t tx)
{
value_t values[2];
value_list_t vl = VALUE_LIST_INIT;
{
value_t values[2];
value_list_t vl = VALUE_LIST_INIT;
- values[0].
counter
= rx;
- values[1].
counter
= tx;
+ values[0].
derive
= rx;
+ values[1].
derive
= tx;
vl.values = values;
vl.values_len = 2;
vl.values = values;
vl.values_len = 2;
-
vl.time = time (NULL
);
- s
trcpy (vl.host, hostname_g
);
- s
trcpy (vl.plugin, "serial"
);
- strncpy (vl.type_instance, type_instance,
+
sstrncpy (vl.host, hostname_g, sizeof (vl.host)
);
+ s
strncpy (vl.plugin, "serial", sizeof (vl.plugin)
);
+ s
strncpy (vl.type, "serial_octets", sizeof (vl.type)
);
+ s
s
trncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
sizeof (vl.type_instance));
- plugin_dispatch_values (
"serial_octets",
&vl);
+ plugin_dispatch_values (&vl);
}
static int serial_read (void)
{
}
static int serial_read (void)
{
-#ifdef KERNEL_LINUX
FILE *fh;
char buffer[1024];
FILE *fh;
char buffer[1024];
-
counter
_t rx = 0;
-
counter
_t tx = 0;
+
derive
_t rx = 0;
+
derive
_t tx = 0;
char *fields[16];
int i, numfields;
char *fields[16];
int i, numfields;
@@
-80,7
+65,9
@@
static int serial_read (void)
if ((fh = fopen ("/proc/tty/driver/serial", "r")) == NULL &&
(fh = fopen ("/proc/tty/driver/ttyS", "r")) == NULL)
{
if ((fh = fopen ("/proc/tty/driver/serial", "r")) == NULL &&
(fh = fopen ("/proc/tty/driver/ttyS", "r")) == NULL)
{
- syslog (LOG_WARNING, "serial: fopen: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("serial: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
return (-1);
}
@@
-130,15
+117,9
@@
static int serial_read (void)
fclose (fh);
return (0);
fclose (fh);
return (0);
-#endif /* KERNEL_LINUX */
} /* int serial_read */
} /* int serial_read */
-#endif /* SERIAL_HAVE_READ */
void module_register (void)
{
void module_register (void)
{
- plugin_register_data_set (&octets_ds);
-
-#if SERIAL_HAVE_READ
plugin_register_read ("serial", serial_read);
plugin_register_read ("serial", serial_read);
-#endif /* SERIAL_HAVE_READ */
-}
+} /* void module_register */