Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. A config function
  2. An init function
  3. A read function
  4. A shutdown function
  5. A function to register callbacks for all the functions above.

 

 

Code Block
#include "collectd.h"
#include "common.h"
 
#define PLUGIN_NAME "my_plugin"
 
static _Bool g_enable_option1;
static char g_option2 [DATA_MAX_NAME_LEN];
 
static int my_config_function(oconfig_item_t *ci) {
  int ret = 0;
 
  INFO (PLUGIN_NAME ": %s:%d", __FUNCTION__, __LINE__);
 
  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;
 
    if (strcasecmp("Option1", child->key) == 0) {
      ret = cf_util_get_boolean(child, & g_enable_option1);
    } else if (strcasecmp("Option2 ", child->key) == 0) {
      ret = cf_util_get_string_buffer(child, g_option2,
                                sizeof(g_option2));
 
    }else {
      ERROR(PLUGIN_NAME ": Unknown configuration parameter \"%s\".", child->key);
      ret = (-1);
    }
 
    if (ret != 0) {
      INFO (PLUGIN_NAME ": %s:%d ret=%d", __FUNCTION__, __LINE__, ret);
      return ret;
    }
  }
 
  return (0);
}
 
 
static int my_read_function(__attribute__((unused)) user_data_t *ud) {
 
  INFO (PLUGIN_NAME ": %s:%d", __FUNCTION__, __LINE__);
  /* 
   *  value_list_t vl = VALUE_LIST_INIT;
   *
   *  vl.values = &(value_t){.derive = value}; //NOTE please change this to an appropriate type checkout https://wiki.opnfv.org/display/fastpath/Collectd+101 for more info
   *
   *  vl.values_len = 1;
   *
   *  sstrncpy(vl.plugin, PLUGIN_NAME, sizeof(vl.plugin));
   *
   *  sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
   *
   *  sstrncpy(vl.type, type, sizeof(vl.type));
   *
   *
   *  plugin_dispatch_values(&vl);
   */



  return (0);
}
 
 
static int my_shutdown_function (void) {
 
  INFO (PLUGIN_NAME ": %s:%d", __FUNCTION__, __LINE__);
 
  return (0);
}
 
static my_init_function(void) {
  INFO(PLUGIN_NAME ": %s:%d", __FUNCTION__, __LINE__);
 
  return (0);
}
 
 
void module_register(void) {
 plugin_register_init("my_plugin", my_init_function);
  plugin_register_complex_config("my_plugin", my_config_function);
  plugin_register_complex_read(NULL, "my_plugin", my_read_function, 0, NULL);
  plugin_register_shutdown("my_plugin", my_shutdown_function);
}
 

...

  1. Try to add a double plugin configuration option and read it in with: cf_util_get_double
  2. Write the configuration parameters to the collectd logfile

 

Statistics in collectd

Statistics in collectd consist of a value list. A value list includes:

 

Value listExamplecomment
Values 99.8999percentage
Value lengththe number of values in the data set.  
Timetimestamp at which the value was collected.1475837857epoch
Intervalinterval at which to expect a new value.10interval
Hostused to identify the host.localhostcan be uuid for vm or host… or can give host a name
Pluginused to identify the plugin.cpu 
Plugin instance (optional)used to group a set of values together. For e.g. values belonging to a DPDK interface.0 
Typeunit used to measure a value. In other words used to refer to a data set.percent 
Type instance (optional)used to distinguish between values that have an identical type.user 
meta dataan opaque data structure that enables the passing of additional information about a value list. “Meta data in the global cache can be used to store arbitrary information about an identifier”   

Notifications in collectd


Notifications in collectd are generic messages containing:

An associated severity, which can be one of OKAY, WARNING, and FAILURE.
A time.      
A Message     
A host.      
A plugin.      
A plugin instance (optional).    
A type.      
A types instance (optional).    
Meta-data.