projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e14e8b7
)
contrib/examples/myplugin.c: Use a compound literal in the example plugin, too.
author
Florian Forster
<octo@collectd.org>
Wed, 14 Sep 2016 06:58:51 +0000
(08:58 +0200)
committer
Florian Forster
<octo@collectd.org>
Wed, 14 Sep 2016 06:59:00 +0000
(08:59 +0200)
contrib/examples/myplugin.c
patch
|
blob
|
history
diff --git
a/contrib/examples/myplugin.c
b/contrib/examples/myplugin.c
index
e1b89f6
..
71fb5f8
100644
(file)
--- a/
contrib/examples/myplugin.c
+++ b/
contrib/examples/myplugin.c
@@
-85,36
+85,50
@@
static int my_init (void)
} /* static int my_init (void) */
/*
} /* static int my_init (void) */
/*
- * This function is called in regular intervalls to collect the data.
+ * This is a utility function used by the read callback to populate a
+ * value_list_t and pass it to plugin_dispatch_values.
*/
*/
-static int my_
read (void
)
+static int my_
submit (gauge_t value
)
{
{
- value_t values[1]; /* the size of this list should equal the number of
- data sources */
value_list_t vl = VALUE_LIST_INIT;
value_list_t vl = VALUE_LIST_INIT;
- /* do the magic to read the data */
- values[0].gauge = random ();
-
- vl.values = values;
+ /* Convert the gauge_t to a value_t and add it to the value_list_t. */
+ vl.values = &(value_t) { .gauge = value };
vl.values_len = 1;
vl.values_len = 1;
- vl.time = time (NULL);
+
+ /* Only set vl.time yourself if you update multiple metrics (i.e. you
+ * have multiple calls to plugin_dispatch_values()) and they need to all
+ * have the same timestamp. */
+ /* vl.time = cdtime(); */
+
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "myplugin", sizeof (vl.plugin));
/* it is strongly recommended to use a type defined in the types.db file
* instead of a custom type */
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "myplugin", sizeof (vl.plugin));
/* it is strongly recommended to use a type defined in the types.db file
* instead of a custom type */
- sstrncpy (vl.type, "myplugin", sizeof (vl.
plugin
));
+ sstrncpy (vl.type, "myplugin", sizeof (vl.
type
));
/* optionally set vl.plugin_instance and vl.type_instance to reasonable
* values (default: "") */
/* dispatch the values to collectd which passes them on to all registered
* write functions */
/* optionally set vl.plugin_instance and vl.type_instance to reasonable
* values (default: "") */
/* dispatch the values to collectd which passes them on to all registered
* write functions */
- plugin_dispatch_values (&vl);
+ return plugin_dispatch_values (&vl);
+}
+
+/*
+ * This function is called in regular intervalls to collect the data.
+ */
+static int my_read (void)
+{
+ /* do the magic to read the data */
+ gauge_t value = random ();
+
+ if (my_submit (value) != 0)
+ WARNING ("myplugin plugin: Dispatching a random value failed.");
/* A return value != 0 indicates an error and the plugin will be skipped
* for an increasing amount of time. */
/* A return value != 0 indicates an error and the plugin will be skipped
* for an increasing amount of time. */
- return 0;
+
return 0;
} /* static int my_read (void) */
/*
} /* static int my_read (void) */
/*