From aff80830f1154a5b6c4da16a0b1033aafde14e24 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 5 Dec 2010 16:40:34 +0100 Subject: [PATCH] Various plugins: Convert more plugins to use "derive" instead of "counter". --- src/bind.c | 39 +++++++++++++++++---------------------- src/dns.c | 26 +++++++++++++------------- src/gmond.c | 40 +++++++++++++++++++--------------------- src/iptables.c | 16 ++++++++-------- src/ipvs.c | 10 +++++----- src/irq.c | 49 ++++++++++++++++++++++++++----------------------- src/libvirt.c | 38 +++++++++++++++++++------------------- src/madwifi.c | 26 +++++++++++++------------- src/memcached.c | 38 +++++++++++++++++++------------------- src/mysql.c | 10 +++++----- src/netlink.c | 14 +++++++------- src/nfs.c | 2 +- src/nginx.c | 6 +++--- src/openvpn.c | 32 ++++++++++++++++---------------- src/protocols.c | 12 ++++-------- src/redis.c | 10 +++++----- src/routeros.c | 26 +++++++++++++------------- src/tape.c | 6 +++--- src/teamspeak2.c | 14 +++++++------- 19 files changed, 203 insertions(+), 211 deletions(-) diff --git a/src/bind.c b/src/bind.c index 47215c74..497fcb65 100644 --- a/src/bind.c +++ b/src/bind.c @@ -1,7 +1,7 @@ /** * collectd - src/bind.c - * Copyright (C) 2009 Bruno Prémont - * Copyright (C) 2009 Florian Forster + * Copyright (C) 2009 Bruno Prémont + * Copyright (C) 2009,2010 Florian Forster * * 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 @@ -18,7 +18,7 @@ * * Authors: * Bruno Prémont - * Florian Forster + * Florian Forster **/ #include "config.h" @@ -337,36 +337,31 @@ static int bind_xml_list_callback (const char *name, /* {{{ */ return (0); } /* }}} int bind_xml_list_callback */ -static int bind_xml_read_counter (xmlDoc *doc, xmlNode *node, /* {{{ */ - counter_t *ret_value) +static int bind_xml_read_derive (xmlDoc *doc, xmlNode *node, /* {{{ */ + derive_t *ret_value) { - char *str_ptr, *end_ptr; - long long int value; + char *str_ptr; + value_t value; + int status; str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1); if (str_ptr == NULL) { - ERROR ("bind plugin: bind_xml_read_counter: xmlNodeListGetString failed."); + ERROR ("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed."); return (-1); } - errno = 0; - value = strtoll (str_ptr, &end_ptr, 10); - xmlFree(str_ptr); - if (str_ptr == end_ptr || errno) + status = parse_value (str_ptr, &value, DS_TYPE_DERIVE); + if (status != 0) { - if (errno && (value < 0)) - ERROR ("bind plugin: bind_xml_read_counter: strtoll failed with underflow."); - else if (errno && (value > 0)) - ERROR ("bind plugin: bind_xml_read_counter: strtoll failed with overflow."); - else - ERROR ("bind plugin: bind_xml_read_counter: strtoll failed."); + ERROR ("bind plugin: Parsing string \"%s\" to derive value failed.", + str_ptr); return (-1); } - *ret_value = value; + *ret_value = value.derive; return (0); -} /* }}} int bind_xml_read_counter */ +} /* }}} int bind_xml_read_derive */ static int bind_xml_read_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */ gauge_t *ret_value) @@ -527,7 +522,7 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ * if (ds_type == DS_TYPE_GAUGE) status = bind_xml_read_gauge (doc, counter, &value.gauge); else - status = bind_xml_read_counter (doc, counter, &value.counter); + status = bind_xml_read_derive (doc, counter, &value.derive); if (status != 0) continue; @@ -600,7 +595,7 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ * if (ds_type == DS_TYPE_GAUGE) status = bind_xml_read_gauge (doc, child, &value.gauge); else - status = bind_xml_read_counter (doc, child, &value.counter); + status = bind_xml_read_derive (doc, child, &value.derive); if (status != 0) continue; diff --git a/src/dns.c b/src/dns.c index 47da4e94..f6c35047 100644 --- a/src/dns.c +++ b/src/dns.c @@ -59,8 +59,8 @@ static int select_numeric_qtype = 1; #define PCAP_SNAPLEN 1460 static char *pcap_device = NULL; -static counter_t tr_queries; -static counter_t tr_responses; +static derive_t tr_queries; +static derive_t tr_responses; static counter_list_t *qtype_list; static counter_list_t *opcode_list; static counter_list_t *rcode_list; @@ -299,13 +299,13 @@ static int dns_init (void) return (0); } /* int dns_init */ -static void submit_counter (const char *type, const char *type_instance, - counter_t value) +static void submit_derive (const char *type, const char *type_instance, + derive_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; @@ -315,15 +315,15 @@ static void submit_counter (const char *type, const char *type_instance, sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); -} /* void submit_counter */ +} /* void submit_derive */ -static void submit_octets (counter_t queries, counter_t responses) +static void submit_octets (derive_t queries, derive_t responses) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = queries; - values[1].counter = responses; + values[0].derive = queries; + values[1].derive = responses; vl.values = values; vl.values_len = 2; @@ -332,7 +332,7 @@ static void submit_octets (counter_t queries, counter_t responses) sstrncpy (vl.type, "dns_octets", sizeof (vl.type)); plugin_dispatch_values (&vl); -} /* void submit_counter */ +} /* void submit_octets */ static int dns_read (void) { @@ -364,7 +364,7 @@ static int dns_read (void) for (i = 0; i < len; i++) { DEBUG ("dns plugin: qtype = %u; counter = %u;", keys[i], values[i]); - submit_counter ("dns_qtype", qtype_str (keys[i]), values[i]); + submit_derive ("dns_qtype", qtype_str (keys[i]), values[i]); } pthread_mutex_lock (&opcode_mutex); @@ -380,7 +380,7 @@ static int dns_read (void) for (i = 0; i < len; i++) { DEBUG ("dns plugin: opcode = %u; counter = %u;", keys[i], values[i]); - submit_counter ("dns_opcode", opcode_str (keys[i]), values[i]); + submit_derive ("dns_opcode", opcode_str (keys[i]), values[i]); } pthread_mutex_lock (&rcode_mutex); @@ -396,7 +396,7 @@ static int dns_read (void) for (i = 0; i < len; i++) { DEBUG ("dns plugin: rcode = %u; counter = %u;", keys[i], values[i]); - submit_counter ("dns_rcode", rcode_str (keys[i]), values[i]); + submit_derive ("dns_rcode", rcode_str (keys[i]), values[i]); } return (0); diff --git a/src/gmond.c b/src/gmond.c index 8c774e53..3c746c48 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -1,6 +1,6 @@ /** * collectd - src/gmond.c - * Copyright (C) 2009 Florian octo Forster + * Copyright (C) 2009,2010 Florian octo Forster * * 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 @@ -16,7 +16,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster **/ #include "collectd.h" @@ -545,6 +545,8 @@ static int staging_entry_update (const char *host, const char *name, /* {{{ */ se->vl.values[ds_index].derive += value.derive; else if (ds_type == DS_TYPE_ABSOLUTE) se->vl.values[ds_index].absolute = value.absolute; + else + assert (23 == 42); se->flags |= (0x01 << ds_index); @@ -593,32 +595,24 @@ static int mc_handle_value_msg (Ganglia_value_msg *msg) /* {{{ */ case gmetric_string: { Ganglia_gmetric_string msg_string; - char *endptr; + int status; msg_string = msg->Ganglia_value_msg_u.gstr; host = msg_string.metric_id.host; name = msg_string.metric_id.name; - endptr = NULL; - errno = 0; - value_counter.counter = (counter_t) strtoull (msg_string.str, - &endptr, /* base = */ 0); - if ((endptr == msg_string.str) || (errno != 0)) - value_counter.counter = -1; - - endptr = NULL; - errno = 0; - value_gauge.gauge = (gauge_t) strtod (msg_string.str, &endptr); - if ((endptr == msg_string.str) || (errno != 0)) + status = parse_value (msg_string.str, &value_derive, DS_TYPE_DERIVE); + if (status != 0) + value_derive.derive = -1; + + status = parse_value (msg_string.str, &value_gauge, DS_TYPE_GAUGE); + if (status != 0) value_gauge.gauge = NAN; - endptr = NULL; - errno = 0; - value_derive.derive = (derive_t) strtoll (msg_string.str, - &endptr, /* base = */ 0); - if ((endptr == msg_string.str) || (errno != 0)) - value_derive.derive = 0; + status = parse_value (msg_string.str, &value_counter, DS_TYPE_COUNTER); + if (status != 0) + value_counter.counter = 0; break; } @@ -663,11 +657,15 @@ static int mc_handle_value_msg (Ganglia_value_msg *msg) /* {{{ */ { value_t val_copy; - val_copy = value_counter; + if ((map->ds_type == DS_TYPE_COUNTER) + || (map->ds_type == DS_TYPE_ABSOLUTE)) + val_copy = value_counter; if (map->ds_type == DS_TYPE_GAUGE) val_copy = value_gauge; else if (map->ds_type == DS_TYPE_DERIVE) val_copy = value_derive; + else + assert (23 == 42); return (staging_entry_update (host, name, map->type, map->type_instance, diff --git a/src/iptables.c b/src/iptables.c index aa53074a..c39aff8f 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -1,8 +1,8 @@ /** * collectd - src/iptables.c - * Copyright (C) 2007 Sjoerd van der Berg - * Copyright (C) 2007 Florian octo Forster - * Copyright (C) 2009 Marco Chiappero + * Copyright (C) 2007 Sjoerd van der Berg + * Copyright (C) 2007-2010 Florian octo Forster + * Copyright (C) 2009 Marco Chiappero * * 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 @@ -20,7 +20,7 @@ * * Authors: * Sjoerd van der Berg - * Florian Forster + * Florian Forster * Marco Chiappero **/ @@ -297,11 +297,11 @@ static int submit6_match (const struct ip6t_entry_match *match, } sstrncpy (vl.type, "ipt_bytes", sizeof (vl.type)); - values[0].counter = (counter_t) entry->counters.bcnt; + values[0].derive = (derive_t) entry->counters.bcnt; plugin_dispatch_values (&vl); sstrncpy (vl.type, "ipt_packets", sizeof (vl.type)); - values[0].counter = (counter_t) entry->counters.pcnt; + values[0].derive = (derive_t) entry->counters.pcnt; plugin_dispatch_values (&vl); return (0); @@ -358,11 +358,11 @@ static int submit_match (const struct ipt_entry_match *match, } sstrncpy (vl.type, "ipt_bytes", sizeof (vl.type)); - values[0].counter = (counter_t) entry->counters.bcnt; + values[0].derive = (derive_t) entry->counters.bcnt; plugin_dispatch_values (&vl); sstrncpy (vl.type, "ipt_packets", sizeof (vl.type)); - values[0].counter = (counter_t) entry->counters.pcnt; + values[0].derive = (derive_t) entry->counters.pcnt; plugin_dispatch_values (&vl); return (0); diff --git a/src/ipvs.c b/src/ipvs.c index f3a583b9..ab76f1eb 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -225,12 +225,12 @@ static int get_ti (struct ip_vs_dest_entry *de, char *ti, size_t size) return 0; } /* get_ti */ -static void cipvs_submit_connections (char *pi, char *ti, counter_t value) +static void cipvs_submit_connections (char *pi, char *ti, derive_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; @@ -247,13 +247,13 @@ static void cipvs_submit_connections (char *pi, char *ti, counter_t value) } /* cipvs_submit_connections */ static void cipvs_submit_if (char *pi, char *t, char *ti, - counter_t rx, counter_t tx) + derive_t rx, derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; vl.values = values; vl.values_len = 2; diff --git a/src/irq.c b/src/irq.c index 401cc6f9..94e42537 100644 --- a/src/irq.c +++ b/src/irq.c @@ -116,7 +116,7 @@ static int check_ignore_irq (const unsigned int irq) return (1 - irq_list_action); } -static void irq_submit (unsigned int irq, counter_t value) +static void irq_submit (unsigned int irq, derive_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -125,7 +125,7 @@ static void irq_submit (unsigned int irq, counter_t value) if (check_ignore_irq (irq)) return; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; @@ -143,35 +143,34 @@ static void irq_submit (unsigned int irq, counter_t value) static int irq_read (void) { -#undef BUFSIZE -#define BUFSIZE 256 - FILE *fh; - char buffer[BUFSIZE]; - unsigned int irq; - unsigned long long irq_value; - unsigned long long value; - char *endptr; - int i; + char buffer[1024]; - char *fields[64]; - int fields_num; - - if ((fh = fopen ("/proc/interrupts", "r")) == NULL) + fh = fopen ("/proc/interrupts", "r"); + if (fh == NULL) { char errbuf[1024]; - WARNING ("irq plugin: fopen (/proc/interrupts): %s", + ERROR ("irq plugin: fopen (/proc/interrupts): %s", sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } + while (fgets (buffer, BUFSIZE, fh) != NULL) { + unsigned int irq; + derive_t irq_value; + char *endptr; + int i; + + char *fields[64]; + int fields_num; + fields_num = strsplit (buffer, fields, 64); if (fields_num < 2) continue; errno = 0; /* To distinguish success/failure after call */ - irq = strtol (fields[0], &endptr, 10); + irq = (unsigned int) strtoul (fields[0], &endptr, /* base = */ 10); if ((endptr == fields[0]) || (errno != 0) || (*endptr != ':')) continue; @@ -179,17 +178,21 @@ static int irq_read (void) irq_value = 0; for (i = 1; i < fields_num; i++) { - errno = 0; - value = strtoull (fields[i], &endptr, 10); + /* Per-CPU value */ + value_t v; + int status; - if ((*endptr != '\0') || (errno != 0)) + status = parse_value (fields[i], &v, DS_TYPE_DERIVE); + if (status != 0) break; - irq_value += value; + irq_value += v.derive; } /* for (i) */ - /* Force 32bit wrap-around */ - irq_submit (irq, irq_value % 4294967296ULL); + if (i < fields_num) + continue; + + irq_submit (irq, irq_value); } fclose (fh); diff --git a/src/libvirt.c b/src/libvirt.c index 5d9d84b6..b5e7e99c 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -190,7 +190,7 @@ cpu_submit (unsigned long long cpu_time, init_value_list (&vl, dom); - values[0].counter = cpu_time; + values[0].derive = cpu_time; vl.values = values; vl.values_len = 1; @@ -201,7 +201,7 @@ cpu_submit (unsigned long long cpu_time, } static void -vcpu_submit (counter_t cpu_time, +vcpu_submit (derive_t cpu_time, virDomainPtr dom, int vcpu_nr, const char *type) { value_t values[1]; @@ -209,7 +209,7 @@ vcpu_submit (counter_t cpu_time, init_value_list (&vl, dom); - values[0].counter = cpu_time; + values[0].derive = cpu_time; vl.values = values; vl.values_len = 1; @@ -220,7 +220,7 @@ vcpu_submit (counter_t cpu_time, } static void -submit_counter2 (const char *type, counter_t v0, counter_t v1, +submit_derive2 (const char *type, derive_t v0, derive_t v1, virDomainPtr dom, const char *devname) { value_t values[2]; @@ -228,8 +228,8 @@ submit_counter2 (const char *type, counter_t v0, counter_t v1, init_value_list (&vl, dom); - values[0].counter = v0; - values[1].counter = v1; + values[0].derive = v0; + values[1].derive = v1; vl.values = values; vl.values_len = 2; @@ -237,7 +237,7 @@ submit_counter2 (const char *type, counter_t v0, counter_t v1, sstrncpy (vl.type_instance, devname, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); -} /* void submit_counter2 */ +} /* void submit_derive2 */ static int lv_init (void) @@ -448,13 +448,13 @@ lv_read (void) continue; if ((stats.rd_req != -1) && (stats.wr_req != -1)) - submit_counter2 ("disk_ops", - (counter_t) stats.rd_req, (counter_t) stats.wr_req, + submit_derive2 ("disk_ops", + (derive_t) stats.rd_req, (derive_t) stats.wr_req, block_devices[i].dom, block_devices[i].path); if ((stats.rd_bytes != -1) && (stats.wr_bytes != -1)) - submit_counter2 ("disk_octets", - (counter_t) stats.rd_bytes, (counter_t) stats.wr_bytes, + submit_derive2 ("disk_octets", + (derive_t) stats.rd_bytes, (derive_t) stats.wr_bytes, block_devices[i].dom, block_devices[i].path); } /* for (nr_block_devices) */ @@ -472,23 +472,23 @@ lv_read (void) continue; if ((stats.rx_bytes != -1) && (stats.tx_bytes != -1)) - submit_counter2 ("if_octets", - (counter_t) stats.rx_bytes, (counter_t) stats.tx_bytes, + submit_derive2 ("if_octets", + (derive_t) stats.rx_bytes, (derive_t) stats.tx_bytes, interface_devices[i].dom, display_name); if ((stats.rx_packets != -1) && (stats.tx_packets != -1)) - submit_counter2 ("if_packets", - (counter_t) stats.rx_packets, (counter_t) stats.tx_packets, + submit_derive2 ("if_packets", + (derive_t) stats.rx_packets, (derive_t) stats.tx_packets, interface_devices[i].dom, display_name); if ((stats.rx_errs != -1) && (stats.tx_errs != -1)) - submit_counter2 ("if_errors", - (counter_t) stats.rx_errs, (counter_t) stats.tx_errs, + submit_derive2 ("if_errors", + (derive_t) stats.rx_errs, (derive_t) stats.tx_errs, interface_devices[i].dom, display_name); if ((stats.rx_drop != -1) && (stats.tx_drop != -1)) - submit_counter2 ("if_dropped", - (counter_t) stats.rx_drop, (counter_t) stats.tx_drop, + submit_derive2 ("if_dropped", + (derive_t) stats.rx_drop, (derive_t) stats.tx_drop, interface_devices[i].dom, display_name); } /* for (nr_interface_devices) */ diff --git a/src/madwifi.c b/src/madwifi.c index 8b3266dc..13301fff 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -561,20 +561,20 @@ static void submit (const char *dev, const char *type, const char *ti1, plugin_dispatch_values (&vl); } -static void submit_counter (const char *dev, const char *type, const char *ti1, - const char *ti2, counter_t val) +static void submit_derive (const char *dev, const char *type, const char *ti1, + const char *ti2, derive_t val) { value_t item; - item.counter = val; + item.derive = val; submit (dev, type, ti1, ti2, &item, 1); } -static void submit_counter2 (const char *dev, const char *type, const char *ti1, - const char *ti2, counter_t val1, counter_t val2) +static void submit_derive2 (const char *dev, const char *type, const char *ti1, + const char *ti2, derive_t val1, derive_t val2) { value_t items[2]; - items[0].counter = val1; - items[1].counter = val2; + items[0].derive = val1; + items[1].derive = val2; submit (dev, type, ti1, ti2, items, 2); } @@ -598,8 +598,8 @@ static void submit_antx (const char *dev, const char *name, continue; ssnprintf (ti2, sizeof (ti2), "%i", i); - submit_counter (dev, "ath_stat", name, ti2, - (counter_t) vals[i]); + submit_derive (dev, "ath_stat", name, ti2, + (derive_t) vals[i]); } } @@ -625,14 +625,14 @@ process_stat_struct (int which, const void *ptr, const char *dev, const char *ma uint32_t val = *(uint32_t *)(((char *) ptr) + specs[i].offset) ; if (item_watched (i) && (val != 0)) - submit_counter (dev, type_name, specs[i].name, mac, val); + submit_derive (dev, type_name, specs[i].name, mac, val); if (item_summed (i)) misc += val; } if (misc != 0) - submit_counter (dev, type_name, misc_name, mac, misc); + submit_derive (dev, type_name, misc_name, mac, misc); } @@ -734,13 +734,13 @@ process_station (int sk, const char *dev, struct ieee80211req_sta_info *si) /* These two stats are handled as a special case as they are a pair of 64bit values */ if (item_watched (STAT_NODE_OCTETS)) - submit_counter2 (dev, "node_octets", mac, NULL, + submit_derive2 (dev, "node_octets", mac, NULL, ns->ns_rx_bytes, ns->ns_tx_bytes); /* This stat is handled as a special case, because it is stored as uin64_t, but we will ignore upper half */ if (item_watched (STAT_NS_RX_BEACONS)) - submit_counter (dev, "node_stat", "ns_rx_beacons", mac, + submit_derive (dev, "node_stat", "ns_rx_beacons", mac, (ns->ns_rx_beacons & 0xFFFFFFFF)); /* All other node statistics */ diff --git a/src/memcached.c b/src/memcached.c index 8b4a8fc1..ee3dbe12 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -1,7 +1,7 @@ /** * collectd - src/memcached.c, based on src/hddtemp.c * Copyright (C) 2007 Antony Dovgal - * Copyright (C) 2007-2009 Florian Forster + * Copyright (C) 2007-2010 Florian Forster * Copyright (C) 2009 Doug MacEachern * Copyright (C) 2009 Franck Lombardi * @@ -21,7 +21,7 @@ * * Authors: * Antony Dovgal - * Florian octo Forster + * Florian octo Forster * Doug MacEachern * Franck Lombardi **/ @@ -273,13 +273,13 @@ static int memcached_config (const char *key, const char *value) /* {{{ */ } /* }}} */ -static void submit_counter (const char *type, const char *type_inst, - counter_t value) /* {{{ */ +static void submit_derive (const char *type, const char *type_inst, + derive_t value) /* {{{ */ { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; @@ -293,14 +293,14 @@ static void submit_counter (const char *type, const char *type_inst, } /* void memcached_submit_cmd */ /* }}} */ -static void submit_counter2 (const char *type, const char *type_inst, - counter_t value0, counter_t value1) /* {{{ */ +static void submit_derive2 (const char *type, const char *type_inst, + derive_t value0, derive_t value1) /* {{{ */ { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value0; - values[1].counter = value1; + values[0].derive = value0; + values[1].derive = value1; vl.values = values; vl.values_len = 2; @@ -368,10 +368,10 @@ static int memcached_read (void) /* {{{ */ gauge_t bytes_total = NAN; gauge_t hits = NAN; gauge_t gets = NAN; - counter_t rusage_user = 0; - counter_t rusage_syst = 0; - counter_t octets_rx = 0; - counter_t octets_tx = 0; + derive_t rusage_user = 0; + derive_t rusage_syst = 0; + derive_t octets_rx = 0; + derive_t octets_tx = 0; /* get data from daemon */ if (memcached_query_daemon (buf, sizeof (buf)) < 0) { @@ -456,7 +456,7 @@ static int memcached_read (void) /* {{{ */ else if ((name_len > 4) && (strncmp (fields[1], "cmd_", 4) == 0)) { const char *name = fields[1] + 4; - submit_counter ("memcached_command", name, atoll (fields[2])); + submit_derive ("memcached_command", name, atoll (fields[2])); if (strcmp (name, "get") == 0) gets = atof (fields[2]); } @@ -466,16 +466,16 @@ static int memcached_read (void) /* {{{ */ */ else if (FIELD_IS ("get_hits")) { - submit_counter ("memcached_ops", "hits", atoll (fields[2])); + submit_derive ("memcached_ops", "hits", atoll (fields[2])); hits = atof (fields[2]); } else if (FIELD_IS ("get_misses")) { - submit_counter ("memcached_ops", "misses", atoll (fields[2])); + submit_derive ("memcached_ops", "misses", atoll (fields[2])); } else if (FIELD_IS ("evictions")) { - submit_counter ("memcached_ops", "evictions", atoll (fields[2])); + submit_derive ("memcached_ops", "evictions", atoll (fields[2])); } /* @@ -495,10 +495,10 @@ static int memcached_read (void) /* {{{ */ submit_gauge2 ("df", "cache", bytes_used, bytes_total - bytes_used); if ((rusage_user != 0) || (rusage_syst != 0)) - submit_counter2 ("ps_cputime", NULL, rusage_user, rusage_syst); + submit_derive2 ("ps_cputime", NULL, rusage_user, rusage_syst); if ((octets_rx != 0) || (octets_tx != 0)) - submit_counter2 ("memcached_octets", NULL, octets_rx, octets_tx); + submit_derive2 ("memcached_octets", NULL, octets_rx, octets_tx); if (!isnan (gets) && !isnan (hits)) { diff --git a/src/mysql.c b/src/mysql.c index 1ca3b484..f4ad01c6 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -321,11 +321,11 @@ static void submit (const char *type, const char *type_instance, } /* submit */ static void counter_submit (const char *type, const char *type_instance, - counter_t value, mysql_database_t *db) + derive_t value, mysql_database_t *db) { value_t values[1]; - values[0].counter = value; + values[0].derive = value; submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db); } /* void counter_submit */ @@ -347,12 +347,12 @@ static void derive_submit (const char *type, const char *type_instance, submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db); } /* void derive_submit */ -static void traffic_submit (counter_t rx, counter_t tx, mysql_database_t *db) +static void traffic_submit (derive_t rx, derive_t tx, mysql_database_t *db) { value_t values[2]; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; submit ("mysql_octets", NULL, values, STATIC_ARRAY_SIZE (values), db); } /* void traffic_submit */ diff --git a/src/netlink.c b/src/netlink.c index 49c4e990..ef851d35 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -1,6 +1,6 @@ /** * collectd - src/netlink.c - * Copyright (C) 2007 Florian octo Forster + * Copyright (C) 2007-2010 Florian octo Forster * * 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 @@ -16,7 +16,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster **/ #include "collectd.h" @@ -161,12 +161,12 @@ static int check_ignorelist (const char *dev, } /* int check_ignorelist */ static void submit_one (const char *dev, const char *type, - const char *type_instance, counter_t value) + const char *type_instance, derive_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; @@ -183,13 +183,13 @@ static void submit_one (const char *dev, const char *type, static void submit_two (const char *dev, const char *type, const char *type_instance, - counter_t rx, counter_t tx) + derive_t rx, derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; vl.values = values; vl.values_len = 2; diff --git a/src/nfs.c b/src/nfs.c index e4d12e34..f3c636ec 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -195,7 +195,7 @@ static void nfs_procedures_submit (const char *plugin_instance, for (i = 0; i < len; i++) { - values[0].counter = val[i]; + values[0].derive = val[i]; sstrncpy (vl.type_instance, names[i], sizeof (vl.type_instance)); DEBUG ("%s-%s/nfs_procedure-%s = %llu", diff --git a/src/nginx.c b/src/nginx.c index 36d3d8d2..1cb7a90a 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -1,6 +1,6 @@ /** * collectd - src/nginx.c - * Copyright (C) 2006,2007 Florian octo Forster + * Copyright (C) 2006-2010 Florian octo Forster * Copyright (C) 2008 Sebastian Harl * * This program is free software; you can redistribute it and/or modify it @@ -18,7 +18,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster * Sebastian Harl **/ @@ -178,7 +178,7 @@ static void submit (char *type, char *inst, long long value) if (strcmp (type, "nginx_connections") == 0) values[0].gauge = value; else if (strcmp (type, "nginx_requests") == 0) - values[0].counter = value; + values[0].derive = value; else return; diff --git a/src/openvpn.c b/src/openvpn.c index 2aca4145..9ce23b4f 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -1,9 +1,9 @@ /** * collectd - src/openvpn.c - * Copyright (C) 2008 Doug MacEachern - * Copyright (C) 2009 Florian octo Forster - * Copyright (C) 2009 Marco Chiappero - * Copyright (C) 2009 Fabian Schuh + * Copyright (C) 2008 Doug MacEachern + * Copyright (C) 2009,2010 Florian octo Forster + * Copyright (C) 2009 Marco Chiappero + * Copyright (C) 2009 Fabian Schuh * * 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 @@ -20,7 +20,7 @@ * * Authors: * Doug MacEachern - * Florian octo Forster + * Florian octo Forster * Marco Chiappero * Fabian Schuh **/ @@ -114,13 +114,13 @@ static void numusers_submit (char *pinst, char *tinst, gauge_t value) } /* void numusers_submit */ /* dispatches stats about traffic (TCP or UDP) generated by the tunnel per single endpoint */ -static void iostats_submit (char *pinst, char *tinst, counter_t rx, counter_t tx) +static void iostats_submit (char *pinst, char *tinst, derive_t rx, derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; /* NOTE ON THE NEW NAMING SCHEMA: * using plugin_instance to identify each vpn config (and @@ -144,13 +144,13 @@ static void iostats_submit (char *pinst, char *tinst, counter_t rx, counter_t tx /* dispatches stats about data compression shown when in single mode */ static void compression_submit (char *pinst, char *tinst, - counter_t uncompressed, counter_t compressed) + derive_t uncompressed, derive_t compressed) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = uncompressed; - values[1].counter = compressed; + values[0].derive = uncompressed; + values[1].derive = compressed; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); @@ -173,11 +173,11 @@ static int single_read (char *name, FILE *fh) const int max_fields = STATIC_ARRAY_SIZE (fields); int fields_num, read = 0; - counter_t link_rx, link_tx; - counter_t tun_rx, tun_tx; - counter_t pre_compress, post_compress; - counter_t pre_decompress, post_decompress; - counter_t overhead_rx, overhead_tx; + derive_t link_rx, link_tx; + derive_t tun_rx, tun_tx; + derive_t pre_compress, post_compress; + derive_t pre_decompress, post_decompress; + derive_t overhead_rx, overhead_tx; link_rx = 0; link_tx = 0; diff --git a/src/protocols.c b/src/protocols.c index e90c1a4e..0dfba210 100644 --- a/src/protocols.c +++ b/src/protocols.c @@ -1,6 +1,6 @@ /** * collectd - src/protocols.c - * Copyright (C) 2009 Florian octo Forster + * Copyright (C) 2009,2010 Florian octo Forster * * 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 @@ -51,14 +51,10 @@ static void submit (const char *protocol_name, { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; + int status; - char *tmp_ptr; - - errno = 0; - tmp_ptr = NULL; - values[0].counter = (counter_t) strtoll (str_value, &tmp_ptr, - /* base = */ 0); - if ((errno != 0) || (tmp_ptr == str_value)) + status = parse_value (str_value, values, DS_TYPE_DERIVE); + if (status != 0) { ERROR ("protocols plugin: Parsing string as integer failed: %s", str_value); diff --git a/src/redis.c b/src/redis.c index 30bd8da3..b694e09d 100644 --- a/src/redis.c +++ b/src/redis.c @@ -196,14 +196,14 @@ static void redis_submit_g (char *plugin_instance, } /* }}} */ __attribute__ ((nonnull(2))) -static void redis_submit_c (char *plugin_instance, +static void redis_submit_d (char *plugin_instance, const char *type, const char *type_instance, - counter_t value) /* {{{ */ + derive_t value) /* {{{ */ { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; @@ -288,8 +288,8 @@ static int redis_read (void) /* {{{ */ redis_submit_g (rn->name, "current_connections", "slaves", info.connected_slaves); redis_submit_g (rn->name, "memory", "used", info.used_memory); redis_submit_g (rn->name, "volatile_changes", NULL, info.changes_since_last_save); - redis_submit_c (rn->name, "total_connections", NULL, info.total_connections_received); - redis_submit_c (rn->name, "total_operations", NULL, info.total_commands_processed); + redis_submit_d (rn->name, "total_connections", NULL, info.total_connections_received); + redis_submit_d (rn->name, "total_operations", NULL, info.total_commands_processed); credis_close (rh); } diff --git a/src/routeros.c b/src/routeros.c index ff8789ed..d61ffe98 100644 --- a/src/routeros.c +++ b/src/routeros.c @@ -1,6 +1,6 @@ /** * collectd - src/routeros.c - * Copyright (C) 2009 Florian octo Forster + * Copyright (C) 2009,2010 Florian octo Forster * * 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 @@ -16,7 +16,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster **/ #include "collectd.h" @@ -44,13 +44,13 @@ struct cr_data_s typedef struct cr_data_s cr_data_t; static void cr_submit_io (cr_data_t *rd, const char *type, /* {{{ */ - const char *type_instance, counter_t rx, counter_t tx) + const char *type_instance, derive_t rx, derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); @@ -75,13 +75,13 @@ static void submit_interface (cr_data_t *rd, /* {{{ */ } cr_submit_io (rd, "if_packets", i->name, - (counter_t) i->rx_packets, (counter_t) i->tx_packets); + (derive_t) i->rx_packets, (derive_t) i->tx_packets); cr_submit_io (rd, "if_octets", i->name, - (counter_t) i->rx_bytes, (counter_t) i->tx_bytes); + (derive_t) i->rx_bytes, (derive_t) i->tx_bytes); cr_submit_io (rd, "if_errors", i->name, - (counter_t) i->rx_errors, (counter_t) i->tx_errors); + (derive_t) i->rx_errors, (derive_t) i->tx_errors); cr_submit_io (rd, "if_dropped", i->name, - (counter_t) i->rx_drops, (counter_t) i->tx_drops); + (derive_t) i->rx_drops, (derive_t) i->tx_drops); submit_interface (rd, i->next); } /* }}} void submit_interface */ @@ -116,12 +116,12 @@ static void cr_submit_gauge (cr_data_t *rd, const char *type, /* {{{ */ #if ROS_VERSION >= ROS_VERSION_ENCODE(1, 1, 0) static void cr_submit_counter (cr_data_t *rd, const char *type, /* {{{ */ - const char *type_instance, counter_t value) + const char *type_instance, derive_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); @@ -166,7 +166,7 @@ static void submit_regtable (cr_data_t *rd, /* {{{ */ ssnprintf (type_instance, sizeof (type_instance), "%s-%s", r->interface, r->radio_name); cr_submit_io (rd, "if_octets", type_instance, - (counter_t) r->rx_bytes, (counter_t) r->tx_bytes); + (derive_t) r->rx_bytes, (derive_t) r->tx_bytes); cr_submit_gauge (rd, "snr", type_instance, (gauge_t) r->signal_to_noise); submit_regtable (rd, r->next); @@ -212,7 +212,7 @@ static int handle_system_resource (__attribute__((unused)) ros_connection_t *c, if (rd->collect_disk) { - cr_submit_counter (rd, "counter", "secors_written", (counter_t) r->write_sect_total); + cr_submit_counter (rd, "counter", "secors_written", (derive_t) r->write_sect_total); cr_submit_gauge (rd, "gauge", "bad_blocks", (gauge_t) r->bad_blocks); } diff --git a/src/tape.c b/src/tape.c index 32b42965..a8e7dc45 100644 --- a/src/tape.c +++ b/src/tape.c @@ -58,13 +58,13 @@ static int tape_init (void) static void tape_submit (const char *plugin_instance, const char *type, - counter_t read, counter_t write) + derive_t read, derive_t write) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = read; - values[1].counter = write; + values[0].derive = read; + values[1].derive = write; vl.values = values; vl.values_len = 2; diff --git a/src/teamspeak2.c b/src/teamspeak2.c index d4bf2aa4..7528406c 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -146,7 +146,7 @@ static void tss2_submit_gauge (const char *plugin_instance, } /* void tss2_submit_gauge */ static void tss2_submit_io (const char *plugin_instance, const char *type, - counter_t rx, counter_t tx) + derive_t rx, derive_t tx) { /* * Submits the io rx/tx tuple to the collectd daemon @@ -154,8 +154,8 @@ static void tss2_submit_io (const char *plugin_instance, const char *type, value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; vl.values = values; vl.values_len = 2; @@ -498,10 +498,10 @@ static int tss2_read_vserver (vserver_list_t *vserver) gauge_t users = NAN; gauge_t channels = NAN; gauge_t servers = NAN; - counter_t rx_octets = 0; - counter_t tx_octets = 0; - counter_t rx_packets = 0; - counter_t tx_packets = 0; + derive_t rx_octets = 0; + derive_t tx_octets = 0; + derive_t rx_packets = 0; + derive_t tx_packets = 0; gauge_t packet_loss = NAN; int valid = 0; -- 2.11.0