Merge pull request #847 from mihu/bind_zone_fix
authorPierre-Yves Ritschard <pyr@spootnik.org>
Wed, 7 Jan 2015 10:42:04 +0000 (11:42 +0100)
committerPierre-Yves Ritschard <pyr@spootnik.org>
Wed, 7 Jan 2015 10:42:04 +0000 (11:42 +0100)
bind-plugin: fix zones iteratation upper limit

src/collectd.conf.in
src/collectd.conf.pod
src/modbus.c
src/virt.c
src/write_kafka.c

index 2454045..dcb1a7a 100644 (file)
 #      <Data "data_name">
 #              RegisterBase 1234
 #              RegisterType float
+#              ModbusRegisterType holding
 #              Type gauge
 #              Instance "..."
 #      </Data>
 #              Host "localhost"
 #              Port 5555
 #              Protocol UDP
+#              Batch false
+#              BatchMaxSize 8192
 #              StoreRates true
 #              AlwaysAppendDS false
 #              TTLFactor 2.0
+#              Notifications true
+#              CheckThresholds false
 #              EventServicePrefix ""
 #      </Node>
 #      Tag "foobar"
-#       Attribute "foo" "bar"
+#      Attribute "foo" "bar"
 #</Plugin>
 
 #<Plugin write_tsdb>
index 1588bf8..35c90b8 100644 (file)
@@ -2890,6 +2890,7 @@ B<Synopsis:>
  <Data "voltage-input-1">
    RegisterBase 0
    RegisterType float
+   ModbusRegisterType holding
    Type voltage
    Instance "input-1"
  </Data>
@@ -2897,6 +2898,7 @@ B<Synopsis:>
  <Data "voltage-input-2">
    RegisterBase 2
    RegisterType float
+   ModbusRegisterType holding
    Type voltage
    Instance "input-2"
  </Data>
@@ -2936,6 +2938,11 @@ Specifies what kind of data is returned by the device. If the type is B<Int32>,
 B<Uint32> or B<Float>, two 16E<nbsp>bit registers will be read and the data is
 combined into one value. Defaults to B<Uint16>.
 
+=item B<ModbusRegisterType> B<holding>|B<input>
+
+Specifies register type to be collected from device. Works only with libmodbus
+2.9.2 or higher. Defaults to B<holding>.
+
 =item B<Type> I<Type>
 
 Specifies the "type" (data set) to use when dispatching the value to
@@ -6084,6 +6091,8 @@ Use the last number found.
 The matched number is a counter. Simply I<sets> the internal counter to this
 value. Variants exist for C<COUNTER>, C<DERIVE>, and C<ABSOLUTE> data sources.
 
+=item B<GaugeAdd>
+
 =item B<CounterAdd>
 
 =item B<DeriveAdd>
@@ -6092,6 +6101,8 @@ Add the matched value to the internal counter. In case of B<DeriveAdd>, the
 matched number may be negative, which will effectively subtract from the
 internal counter.
 
+=item B<GaugeInc>
+
 =item B<CounterInc>
 
 =item B<DeriveInc>
index 887c63c..795465f 100644 (file)
@@ -49,6 +49,7 @@
  *   RegisterBase 1234
  *   RegisterType float
  *   Type gauge
+ *   ModbusRegisterType holding
  *   Instance "..."
  * </Data>
  *
@@ -75,7 +76,13 @@ enum mb_register_type_e /* {{{ */
   REG_TYPE_UINT32,
   REG_TYPE_FLOAT
 }; /* }}} */
+enum mb_mreg_type_e /* {{{ */ 
+{
+  MREG_HOLDING,
+  MREG_INPUT
+}; /* }}} */
 typedef enum mb_register_type_e mb_register_type_t;
+typedef enum mb_mreg_type_e mb_mreg_type_t;
 
 struct mb_data_s;
 typedef struct mb_data_s mb_data_t;
@@ -84,6 +91,7 @@ struct mb_data_s /* {{{ */
   char *name;
   int register_base;
   mb_register_type_t register_type;
+  mb_mreg_type_t modbus_register_type;
   char type[DATA_MAX_NAME_LEN];
   char instance[DATA_MAX_NAME_LEN];
 
@@ -467,14 +475,21 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
     return (-1);
   }
 #endif
-
-  status = modbus_read_registers (host->connection,
+  if (data->modbus_register_type == MREG_INPUT){
+    status = modbus_read_input_registers (host->connection,
+        /* start_addr = */ data->register_base,
+        /* num_registers = */ values_num, /* buffer = */ values);
+  }
+  else{
+    status = modbus_read_registers (host->connection,
         /* start_addr = */ data->register_base,
         /* num_registers = */ values_num, /* buffer = */ values);
+  }
   if (status != values_num)
   {
-    ERROR ("Modbus plugin: modbus_read_registers (%s/%s) failed. status = %i, values_num = %i "
-        "Giving up.", host->host, host->node, status, values_num);
+    ERROR ("Modbus plugin: modbus read function (%s/%s) failed. "
+           " status = %i, values_num = %i. Giving up.",
+           host->host, host->node, status, values_num);
 #if LEGACY_LIBMODBUS
     modbus_close (&host->connection);
 #else
@@ -709,6 +724,28 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */
         status = -1;
       }
     }
+    else if (strcasecmp ("ModbusRegisterType", child->key) == 0)
+    {
+#if LEGACY_LIBMODBUS
+      ERROR("Modbus plugin: ModbusRegisterType parameter can not be used "
+            "with your libmodbus version");
+#else
+      char tmp[16];
+      status = cf_util_get_string_buffer (child, tmp, sizeof (tmp));
+      if (status != 0)
+        /* do nothing */;
+      else if (strcasecmp ("holding", tmp) == 0)
+        data.modbus_register_type = MREG_HOLDING;
+      else if (strcasecmp ("input", tmp) == 0)
+        data.modbus_register_type = MREG_INPUT;
+      else
+      {
+        ERROR ("Modbus plugin: The modbus_register_type \"%s\" is unknown.",
+               tmp);
+        status = -1;
+      }
+#endif
+    }
     else
     {
       ERROR ("Modbus plugin: Unknown configuration option: %s", child->key);
index 6118c0f..5f87625 100644 (file)
@@ -588,7 +588,7 @@ lv_read (void)
         }
 
         for (j = 0; j < status; j++) {
-            memory_stats_submit ((gauge_t) minfo[j].val, domains[i], minfo[j].tag);
+            memory_stats_submit ((gauge_t) minfo[j].val * 1024, domains[i], minfo[j].tag);
         }
 
         sfree (minfo);
index ba76d71..e1d2f12 100644 (file)
@@ -76,8 +76,13 @@ static int32_t kafka_partition(const rd_kafka_topic_t *rkt,
                                int32_t partition_cnt, void *p, void *m)
 {
     u_int32_t key = *((u_int32_t *)keydata );
+    u_int32_t target = key % partition_cnt;
+    int32_t   i = partition_cnt;
 
-    return key % partition_cnt;
+    while (--i > 0 && !rd_kafka_topic_partition_available(rkt, target)) {
+        target = (target + 1) % partition_cnt;
+    }
+    return target;
 }
 
 static int kafka_write(const data_set_t *ds, /* {{{ */