Introduce the DERIVE and ABSOLUTE data source types.
[collectd.git] / src / common.c
index b37db88..8de871b 100644 (file)
@@ -578,26 +578,26 @@ int check_create_dir (const char *file_orig)
 int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
 {
        char ident[128];
+
+       *ksp_ptr = NULL;
        
        if (kc == NULL)
                return (-1);
 
        ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name);
 
+       *ksp_ptr = kstat_lookup (kc, module, instance, name);
        if (*ksp_ptr == NULL)
        {
-               if ((*ksp_ptr = kstat_lookup (kc, module, instance, name)) == NULL)
-               {
-                       ERROR ("Cound not find kstat %s", ident);
-                       return (-1);
-               }
+               ERROR ("get_kstat: Cound not find kstat %s", ident);
+               return (-1);
+       }
 
-               if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
-               {
-                       WARNING ("kstat %s has wrong type", ident);
-                       *ksp_ptr = NULL;
-                       return (-1);
-               }
+       if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
+       {
+               ERROR ("get_kstat: kstat %s has wrong type", ident);
+               *ksp_ptr = NULL;
+               return (-1);
        }
 
 #ifdef assert
@@ -607,13 +607,13 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
 
        if (kstat_read (kc, *ksp_ptr, NULL) == -1)
        {
-               WARNING ("kstat %s could not be read", ident);
+               ERROR ("get_kstat: kstat %s could not be read", ident);
                return (-1);
        }
 
        if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
        {
-               WARNING ("kstat %s has wrong type", ident);
+               ERROR ("get_kstat: kstat %s has wrong type", ident);
                return (-1);
        }
 
@@ -845,6 +845,10 @@ int parse_value (const char *value, value_t *ret_value, const data_source_t ds)
                ret_value->counter = (counter_t)strtoll (value, &endptr, 0);
        else if (DS_TYPE_GAUGE == ds.type)
                ret_value->gauge = (gauge_t)strtod (value, &endptr);
+       else if (DS_TYPE_DERIVE == ds.type)
+               ret_value->counter = (derive_t)strtoll (value, &endptr, 0);
+       else if (DS_TYPE_ABSOLUTE == ds.type)
+               ret_value->counter = (absolute_t)strtoll (value, &endptr, 0);
        else {
                ERROR ("parse_value: Invalid data source \"%s\" "
                                "(type = %i).", ds.name, ds.type);