virt plugin: fix some minor style issues
[collectd.git] / src / virt.c
index 56e44fb..a3f9405 100644 (file)
@@ -138,11 +138,17 @@ static const char *config_keys[] = {"Connection",
                                     "Instances",
                                     "ExtraStats",
                                     "PersistentNotification",
+
+                                    "ReportBlockDevices",
+                                    "ReportNetworkInterfaces",
                                     NULL};
 
 /* PersistentNotification is false by default */
 static bool persistent_notification = false;
 
+static bool report_block_devices = true;
+static bool report_network_interfaces = true;
+
 /* Thread used for handling libvirt notifications events */
 static virt_notif_thread_t notif_thread;
 
@@ -1368,6 +1374,16 @@ static int lv_config(const char *key, const char *value) {
     return 0;
   }
 
+  if (strcasecmp(key, "ReportBlockDevices") == 0) {
+    report_block_devices = IS_TRUE(value);
+    return 0;
+  }
+
+  if (strcasecmp(key, "ReportNetworkInterfaces") == 0) {
+    report_network_interfaces = IS_TRUE(value);
+    return 0;
+  }
+
   /* Unrecognised option. */
   return -1;
 }
@@ -1416,7 +1432,7 @@ static int lv_domain_block_info(virDomainPtr dom, const char *path,
     return -1;
   }
 
-  virTypedParameterPtr params = calloc((size_t)nparams, sizeof(*params));
+  virTypedParameterPtr params = calloc(nparams, sizeof(*params));
   if (params == NULL) {
     ERROR("virt plugin: alloc(%i) for block=%s parameters failed.", nparams,
           path);
@@ -1486,7 +1502,7 @@ static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) {
   int max_cpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
   int cpu_map_len = VIR_CPU_MAPLEN(max_cpus);
 
-  virVcpuInfoPtr vinfo = calloc(nr_virt_cpu, sizeof(vinfo[0]));
+  virVcpuInfoPtr vinfo = calloc(nr_virt_cpu, sizeof(*vinfo));
   if (vinfo == NULL) {
     ERROR(PLUGIN_NAME " plugin: calloc failed.");
     return -1;
@@ -1528,7 +1544,7 @@ static int get_pcpu_stats(virDomainPtr dom) {
     return -1;
   }
 
-  virTypedParameterPtr param = calloc(nparams, sizeof(virTypedParameter));
+  virTypedParameterPtr param = calloc(nparams, sizeof(*param));
   if (param == NULL) {
     ERROR(PLUGIN_NAME " plugin: alloc(%i) for cpu parameters failed.", nparams);
     return -1;
@@ -1611,9 +1627,9 @@ static int get_domain_state_notify(virDomainPtr domain) {
 
 static int get_memory_stats(virDomainPtr domain) {
   virDomainMemoryStatPtr minfo =
-      calloc(VIR_DOMAIN_MEMORY_STAT_NR, sizeof(virDomainMemoryStatStruct));
+      calloc(VIR_DOMAIN_MEMORY_STAT_NR, sizeof(*minfo));
   if (minfo == NULL) {
-    ERROR("virt plugin: malloc failed.");
+    ERROR("virt plugin: calloc failed.");
     return -1;
   }
 
@@ -2624,10 +2640,12 @@ static int refresh_lists(struct lv_read_instance *inst) {
       goto cont;
 
     /* Block devices. */
-    lv_add_block_devices(state, dom, domname, xpath_ctx);
+    if (report_block_devices)
+      lv_add_block_devices(state, dom, domname, xpath_ctx);
 
     /* Network interfaces. */
-    lv_add_network_interfaces(state, dom, domname, xpath_ctx);
+    if (report_network_interfaces)
+      lv_add_network_interfaces(state, dom, domname, xpath_ctx);
 
   cont:
     if (xpath_ctx)