collection.conf: Configure the "memory" graph.
[collection4.git] / graph_instance.c
index fa4716d..103be23 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "graph_instance.h"
 #include "graph_ident.h"
+#include "graph_list.h"
 #include "common.h"
 #include "utils_params.h"
 
@@ -165,10 +166,10 @@ graph_instance_t *inst_create (graph_config_t *cfg, /* {{{ */
     return (NULL);
   memset (i, 0, sizeof (*i));
 
-  selector = gl_graph_get_selector (cfg);
+  selector = graph_get_selector (cfg);
   if (selector == NULL)
   {
-    fprintf (stderr, "inst_create: gl_graph_get_selector failed\n");
+    fprintf (stderr, "inst_create: graph_get_selector failed\n");
     free (i);
     return (NULL);
   }
@@ -244,7 +245,7 @@ graph_instance_t *inst_get_selected (graph_config_t *cfg) /* {{{ */
   graph_instance_t *inst;
 
   if (cfg == NULL)
-    cfg = graph_get_selected ();
+    cfg = gl_graph_get_selected ();
 
   if (cfg == NULL)
   {
@@ -262,7 +263,7 @@ graph_instance_t *inst_get_selected (graph_config_t *cfg) /* {{{ */
 
   ident = ident_create (host, plugin, plugin_instance, type, type_instance);
 
-  for (inst = gl_graph_get_instances (cfg); inst != NULL; inst = inst->next)
+  for (inst = graph_get_instances (cfg); inst != NULL; inst = inst->next)
   {
     if (ident_compare (ident, inst->select) != 0)
       continue;
@@ -287,22 +288,11 @@ int inst_get_rrdargs (graph_config_t *cfg, /* {{{ */
   if ((cfg == NULL) || (inst == NULL) || (args == NULL))
     return (EINVAL);
 
-/* FIXME: Re-enable title and vertical label stuff. */
-#if 0
-  if (cfg->title != NULL)
-  {
-    array_append (args, "-t");
-    array_append (args, cfg->title);
-  }
-
-  if (cfg->vertical_label != NULL)
-  {
-    array_append (args, "-v");
-    array_append (args, cfg->vertical_label);
-  }
-#endif
+  status = graph_get_rrdargs (cfg, inst, args);
+  if (status != 0)
+    return (status);
 
-  defs = gl_graph_get_defs (cfg);
+  defs = graph_get_defs (cfg);
   if (defs == NULL)
   {
     defs = inst_get_default_defs (cfg, inst);
@@ -339,10 +329,10 @@ int inst_get_params (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
       || (buffer == NULL) || (buffer_size < 1))
     return (EINVAL);
 
-  cfg_select = gl_graph_get_selector (cfg);
+  cfg_select = graph_get_selector (cfg);
   if (cfg_select == NULL)
   {
-    fprintf (stderr, "inst_get_params: gl_graph_get_selector failed");
+    fprintf (stderr, "inst_get_params: graph_get_selector failed");
     return (-1);
   }
 
@@ -405,7 +395,7 @@ int inst_append (graph_instance_t *head, graph_instance_t *inst) /* {{{ */
 } /* }}} int inst_append */
 
 int inst_foreach (graph_instance_t *inst, /* {{{ */
-               inst_callback cb, void *user_data)
+               inst_callback_t cb, void *user_data)
 {
   graph_instance_t *ptr;
 
@@ -439,4 +429,47 @@ graph_instance_t *inst_find_matching (graph_instance_t *inst, /* {{{ */
   return (NULL);
 } /* }}} graph_instance_t *inst_find_matching */
 
+int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
+    char *buffer, size_t buffer_size)
+{
+  graph_ident_t *cfg_select;
+
+  if ((cfg == NULL) || (inst == NULL)
+      || (buffer == NULL) || (buffer_size < 2))
+    return (EINVAL);
+
+  cfg_select = graph_get_selector (cfg);
+  if (cfg_select == NULL)
+  {
+    fprintf (stderr, "inst_describe: graph_get_selector failed\n");
+    return (-1);
+  }
+
+  buffer[0] = 0;
+
+#define CHECK_FIELD(field) do {                                              \
+  if (IS_ANY (ident_get_##field (cfg_select)))                               \
+  {                                                                          \
+    if (buffer[0] != 0)                                                      \
+      strlcat (buffer, "/", buffer_size);                                    \
+    strlcat (buffer, ident_get_##field (inst->select), buffer_size);         \
+  }                                                                          \
+} while (0)
+
+  CHECK_FIELD (host);
+  CHECK_FIELD (plugin);
+  CHECK_FIELD (plugin_instance);
+  CHECK_FIELD (type);
+  CHECK_FIELD (type_instance);
+
+#undef CHECK_FIELD
+
+  if (buffer[0] == 0)
+    strlcat (buffer, "default", buffer_size);
+
+  ident_destroy (cfg_select);
+
+  return (0);
+} /* }}} int inst_describe */
+
 /* vim: set sw=2 sts=2 et fdm=marker : */