Merge branch 'collectd-4.4'
[collectd.git] / src / vserver.c
index 2e39060..4cc8251 100644 (file)
@@ -4,8 +4,7 @@
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Free Software Foundation; only version 2 of the license is applicable.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #define BUFSIZE 512
 
-#define MODULE_NAME "vserver"
 #define PROCDIR "/proc/virtual"
 
-#if defined(KERNEL_LINUX)
-# define VSERVER_HAVE_READ 1
-#else
-# define VSERVER_HAVE_READ 0
-#endif /* defined(KERNEL_LINUX) */
+#if !KERNEL_LINUX
+# error "No applicable input method."
+#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 =
-{
-       "if_octets", 2, octets_dsrc
-};
-
-static data_source_t load_dsrc[3] =
-{
-       {"shortterm", DS_TYPE_GAUGE, 0.0, 100.0},
-       {"midterm",   DS_TYPE_GAUGE, 0.0, 100.0},
-       {"longterm",  DS_TYPE_GAUGE, 0.0, 100.0}
-};
-
-static data_set_t load_ds =
-{
-       "load", 3, load_dsrc
-};
-
-static data_source_t threads_dsrc[1] =
-{
-       {"value", DS_TYPE_GAUGE, 0.0, 65535.0}
-};
-
-static data_set_t threads_ds =
-{
-       "vs_threads", 1, threads_dsrc
-};
-
-static data_source_t processes_dsrc[1] =
-{
-       {"value", DS_TYPE_GAUGE, 0.0, 65535.0}
-};
-
-static data_set_t processes_ds =
-{
-       "vs_processes", 1, processes_dsrc
-};
-
-static data_source_t memory_dsrc[1] =
-{
-       {"value", DS_TYPE_GAUGE, 0.0, 9223372036854775807.0}
-};
-
-static data_set_t memory_ds =
-{
-       "vs_memory", 1, memory_dsrc
-};
-
-#if VSERVER_HAVE_READ
 static int pagesize = 0;
 
 static int vserver_init (void)
@@ -117,10 +59,11 @@ static void traffic_submit (const char *plugin_instance,
        vl.time = time (NULL);
        strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "vserver");
-       strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
-       strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+       sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+       strcpy (vl.type, "if_octets");
+       sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
-       plugin_dispatch_values ("if_octets", &vl);
+       plugin_dispatch_values (&vl);
 } /* void traffic_submit */
 
 static void load_submit (const char *plugin_instance,
@@ -138,9 +81,10 @@ static void load_submit (const char *plugin_instance,
        vl.time = time (NULL);
        strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "vserver");
-       strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+       sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+       strcpy (vl.type, "load");
 
-       plugin_dispatch_values ("load", &vl);
+       plugin_dispatch_values (&vl);
 }
 
 static void submit_gauge (const char *plugin_instance, const char *type,
@@ -157,10 +101,11 @@ static void submit_gauge (const char *plugin_instance, const char *type,
        vl.time = time (NULL);
        strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "vserver");
-       strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
-       strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+       sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
-       plugin_dispatch_values (type, &vl);
+       plugin_dispatch_values (&vl);
 } /* void submit_gauge */
 
 static inline long long __get_sock_bytes(const char *s)
@@ -205,8 +150,9 @@ static int vserver_read (void)
                        continue;
 
                /* socket message accounting */
-               len = snprintf (file, BUFSIZE, PROCDIR "/%s/cacct", dent->d_name);
-               if ((len < 0) || (len >= BUFSIZE))
+               len = ssnprintf (file, sizeof (file),
+                               PROCDIR "/%s/cacct", dent->d_name);
+               if ((len < 0) || (len >= sizeof (file)))
                        continue;
 
                if (NULL == (fh = fopen (file, "r")))
@@ -252,8 +198,9 @@ static int vserver_read (void)
                }
 
                /* thread information and load */
-               len = snprintf (file, BUFSIZE, PROCDIR "/%s/cvirt", dent->d_name);
-               if ((len < 0) || (len >= BUFSIZE))
+               len = ssnprintf (file, sizeof (file),
+                               PROCDIR "/%s/cvirt", dent->d_name);
+               if ((len < 0) || (len >= sizeof (file)))
                        continue;
 
                if (NULL == (fh = fopen (file, "r")))
@@ -304,8 +251,9 @@ static int vserver_read (void)
                }
 
                /* processes and memory usage */
-               len = snprintf (file, BUFSIZE, PROCDIR "/%s/limit", dent->d_name);
-               if ((len < 0) || (len >= BUFSIZE))
+               len = ssnprintf (file, sizeof (file),
+                               PROCDIR "/%s/limit", dent->d_name);
+               if ((len < 0) || (len >= sizeof (file)))
                        continue;
 
                if (NULL == (fh = fopen (file, "r")))
@@ -360,26 +308,11 @@ static int vserver_read (void)
 
        return (0);
 } /* int vserver_read */
-#endif /* VSERVER_HAVE_READ */
 
-void module_register (modreg_e load)
+void module_register (void)
 {
-       if (load & MR_DATASETS)
-       {
-               plugin_register_data_set (&octets_ds);
-               plugin_register_data_set (&load_ds);
-               plugin_register_data_set (&threads_ds);
-               plugin_register_data_set (&processes_ds);
-               plugin_register_data_set (&memory_ds);
-       }
-
-#if VSERVER_HAVE_READ
-       if (load & MR_READ)
-       {
-               plugin_register_init ("vserver", vserver_init);
-               plugin_register_read ("vserver", vserver_read);
-       }
-#endif /* VSERVER_HAVE_READ */
+       plugin_register_init ("vserver", vserver_init);
+       plugin_register_read ("vserver", vserver_read);
 } /* void module_register(void) */
 
 /* vim: set ts=4 sw=4 noexpandtab : */