From: Florian Forster Date: Sun, 5 Dec 2010 11:18:33 +0000 (+0100) Subject: Various plugins: Change various plugins to use "derive" internally. X-Git-Tag: collectd-5.0.0-beta0~5 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4fd631aa4fc9aa2e5339a1531dc74915676844a4;p=collectd.git Various plugins: Change various plugins to use "derive" internally. This is just a beginning, other plugins will have to be changed, too. --- diff --git a/src/apache.c b/src/apache.c index 506ba84e..9be32d16 100644 --- a/src/apache.c +++ b/src/apache.c @@ -476,13 +476,13 @@ static void submit_value (const char *type, const char *type_instance, plugin_dispatch_values (&vl); } /* void submit_value */ -static void submit_counter (const char *type, const char *type_instance, - counter_t c, apache_t *st) +static void submit_derive (const char *type, const char *type_instance, + derive_t c, apache_t *st) { value_t v; - v.counter = c; + v.derive = c; submit_value (type, type_instance, v, st); -} /* void submit_counter */ +} /* void submit_derive */ static void submit_gauge (const char *type, const char *type_instance, gauge_t g, apache_t *st) @@ -644,11 +644,11 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */ { if ((strcmp (fields[0], "Total") == 0) && (strcmp (fields[1], "Accesses:") == 0)) - submit_counter ("apache_requests", "", + submit_derive ("apache_requests", "", atoll (fields[2]), st); else if ((strcmp (fields[0], "Total") == 0) && (strcmp (fields[1], "kBytes:") == 0)) - submit_counter ("apache_bytes", "", + submit_derive ("apache_bytes", "", 1024LL * atoll (fields[2]), st); } else if (fields_num == 2) diff --git a/src/cpu.c b/src/cpu.c index 3dbe80ee..12071a2c 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -1,6 +1,6 @@ /** * collectd - src/cpu.c - * Copyright (C) 2005-2009 Florian octo Forster + * Copyright (C) 2005-2010 Florian octo Forster * Copyright (C) 2008 Oleg King * Copyright (C) 2009 Simon Kuhnle * Copyright (C) 2009 Manuel Sanmartin @@ -241,12 +241,12 @@ static int init (void) return (0); } /* int init */ -static void submit (int cpu_num, const char *type_instance, counter_t value) +static void submit (int cpu_num, 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; @@ -298,10 +298,10 @@ static int cpu_read (void) continue; } - submit (cpu, "user", (counter_t) cpu_info.cpu_ticks[CPU_STATE_USER]); - submit (cpu, "nice", (counter_t) cpu_info.cpu_ticks[CPU_STATE_NICE]); - submit (cpu, "system", (counter_t) cpu_info.cpu_ticks[CPU_STATE_SYSTEM]); - submit (cpu, "idle", (counter_t) cpu_info.cpu_ticks[CPU_STATE_IDLE]); + submit (cpu, "user", (derive_t) cpu_info.cpu_ticks[CPU_STATE_USER]); + submit (cpu, "nice", (derive_t) cpu_info.cpu_ticks[CPU_STATE_NICE]); + submit (cpu, "system", (derive_t) cpu_info.cpu_ticks[CPU_STATE_SYSTEM]); + submit (cpu, "idle", (derive_t) cpu_info.cpu_ticks[CPU_STATE_IDLE]); #endif /* PROCESSOR_CPU_LOAD_INFO */ #if PROCESSOR_TEMPERATURE /* @@ -352,8 +352,8 @@ static int cpu_read (void) #elif defined(KERNEL_LINUX) int cpu; - counter_t user, nice, syst, idle; - counter_t wait, intr, sitr; /* sitr == soft interrupt */ + derive_t user, nice, syst, idle; + derive_t wait, intr, sitr; /* sitr == soft interrupt */ FILE *fh; char buf[1024]; @@ -410,7 +410,7 @@ static int cpu_read (void) #elif defined(HAVE_LIBKSTAT) int cpu; - counter_t user, syst, idle, wait; + derive_t user, syst, idle, wait; static cpu_stat_t cs; if (kc == NULL) @@ -421,10 +421,10 @@ static int cpu_read (void) if (kstat_read (kc, ksp[cpu], &cs) == -1) continue; /* error message? */ - idle = (counter_t) cs.cpu_sysinfo.cpu[CPU_IDLE]; - user = (counter_t) cs.cpu_sysinfo.cpu[CPU_USER]; - syst = (counter_t) cs.cpu_sysinfo.cpu[CPU_KERNEL]; - wait = (counter_t) cs.cpu_sysinfo.cpu[CPU_WAIT]; + idle = (derive_t) cs.cpu_sysinfo.cpu[CPU_IDLE]; + user = (derive_t) cs.cpu_sysinfo.cpu[CPU_USER]; + syst = (derive_t) cs.cpu_sysinfo.cpu[CPU_KERNEL]; + wait = (derive_t) cs.cpu_sysinfo.cpu[CPU_WAIT]; submit (ksp[cpu]->ks_instance, "user", user); submit (ksp[cpu]->ks_instance, "system", syst); @@ -551,12 +551,12 @@ static int cpu_read (void) return (-1); } - submit (0, "idle", (counter_t) cs->idle); - submit (0, "nice", (counter_t) cs->nice); - submit (0, "swap", (counter_t) cs->swap); - submit (0, "system", (counter_t) cs->kernel); - submit (0, "user", (counter_t) cs->user); - submit (0, "wait", (counter_t) cs->iowait); + submit (0, "idle", (derive_t) cs->idle); + submit (0, "nice", (derive_t) cs->nice); + submit (0, "swap", (derive_t) cs->swap); + submit (0, "system", (derive_t) cs->kernel); + submit (0, "user", (derive_t) cs->user); + submit (0, "wait", (derive_t) cs->iowait); /* #endif HAVE_LIBSTATGRAB */ #elif defined(HAVE_PERFSTAT) @@ -591,10 +591,10 @@ static int cpu_read (void) for (i = 0; i < cpus; i++) { - submit (i, "idle", (counter_t) perfcpu[i].idle); - submit (i, "system", (counter_t) perfcpu[i].sys); - submit (i, "user", (counter_t) perfcpu[i].user); - submit (i, "wait", (counter_t) perfcpu[i].wait); + submit (i, "idle", (derive_t) perfcpu[i].idle); + submit (i, "system", (derive_t) perfcpu[i].sys); + submit (i, "user", (derive_t) perfcpu[i].user); + submit (i, "wait", (derive_t) perfcpu[i].wait); } #endif /* HAVE_PERFSTAT */ diff --git a/src/disk.c b/src/disk.c index 0a908992..697d850f 100644 --- a/src/disk.c +++ b/src/disk.c @@ -1,6 +1,6 @@ /** * collectd - src/disk.c - * Copyright (C) 2005-2008 Florian octo Forster + * Copyright (C) 2005-2010 Florian octo Forster * Copyright (C) 2009 Manuel Sanmartin * * This program is free software; you can redistribute it and/or modify it @@ -85,19 +85,19 @@ typedef struct diskstats /* This overflows in roughly 1361 years */ unsigned int poll_count; - counter_t read_sectors; - counter_t write_sectors; + derive_t read_sectors; + derive_t write_sectors; - counter_t read_bytes; - counter_t write_bytes; + derive_t read_bytes; + derive_t write_bytes; - counter_t read_ops; - counter_t write_ops; - counter_t read_time; - counter_t write_time; + derive_t read_ops; + derive_t write_ops; + derive_t read_time; + derive_t write_time; - counter_t avg_read_time; - counter_t avg_write_time; + derive_t avg_read_time; + derive_t avg_write_time; struct diskstats *next; } diskstats_t; @@ -212,7 +212,7 @@ static int disk_init (void) static void disk_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; @@ -221,8 +221,8 @@ static void disk_submit (const char *plugin_instance, if (ignorelist_match (ignorelist, plugin_instance) != 0) return; - values[0].counter = read; - values[1].counter = write; + values[0].derive = read; + values[1].derive = write; vl.values = values; vl.values_len = 2; @@ -429,15 +429,15 @@ static int disk_read (void) int major = 0; int minor = 0; - counter_t read_sectors = 0; - counter_t write_sectors = 0; + derive_t read_sectors = 0; + derive_t write_sectors = 0; - counter_t read_ops = 0; - counter_t read_merged = 0; - counter_t read_time = 0; - counter_t write_ops = 0; - counter_t write_merged = 0; - counter_t write_time = 0; + derive_t read_ops = 0; + derive_t read_merged = 0; + derive_t read_time = 0; + derive_t write_ops = 0; + derive_t write_merged = 0; + derive_t write_time = 0; int is_disk = 0; diskstats_t *ds, *pre_ds; @@ -523,8 +523,8 @@ static int disk_read (void) } { - counter_t diff_read_sectors; - counter_t diff_write_sectors; + derive_t diff_read_sectors; + derive_t diff_write_sectors; /* If the counter wraps around, it's only 32 bits.. */ if (read_sectors < ds->read_sectors) @@ -547,18 +547,18 @@ static int disk_read (void) /* Calculate the average time an io-op needs to complete */ if (is_disk) { - counter_t diff_read_ops; - counter_t diff_write_ops; - counter_t diff_read_time; - counter_t diff_write_time; + derive_t diff_read_ops; + derive_t diff_write_ops; + derive_t diff_read_time; + derive_t diff_write_time; if (read_ops < ds->read_ops) diff_read_ops = 1 + read_ops + (UINT_MAX - ds->read_ops); else diff_read_ops = read_ops - ds->read_ops; - DEBUG ("disk plugin: disk_name = %s; read_ops = %llu; " - "ds->read_ops = %llu; diff_read_ops = %llu;", + DEBUG ("disk plugin: disk_name = %s; read_ops = %"PRIi64"; " + "ds->read_ops = %"PRIi64"; diff_read_ops = %"PRIi64";", disk_name, read_ops, ds->read_ops, diff_read_ops); @@ -700,12 +700,12 @@ static int disk_read (void) /* #endif defined(HAVE_LIBSTATGRAB) */ #elif defined(HAVE_PERFSTAT) - counter_t read_sectors; - counter_t write_sectors; - counter_t read_time; - counter_t write_time; - counter_t read_ops; - counter_t write_ops; + derive_t read_sectors; + derive_t write_sectors; + derive_t read_time; + derive_t write_time; + derive_t read_ops; + derive_t write_ops; perfstat_id_t firstpath; int rnumdisk; int i; diff --git a/src/fscache.c b/src/fscache.c index dc0eb119..8fbd2713 100644 --- a/src/fscache.c +++ b/src/fscache.c @@ -107,16 +107,13 @@ Ops pend=N Number of times async ops added to pending queues 63 events to collect in 13 groups */ static void fscache_submit (const char *section, const char *name, - counter_t counter_value) + value_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - vl.values = values; + vl.values = &value; vl.values_len = 1; - vl.values[0].counter = counter_value; - sstrncpy(vl.host, hostname_g, sizeof (vl.host)); sstrncpy(vl.plugin, "fscache", sizeof (vl.plugin)); sstrncpy(vl.plugin_instance, section, sizeof (vl.plugin_instance)); @@ -189,8 +186,8 @@ static void fscache_read_stats_file (FILE *fh) { char *field_name; char *field_value_str; - char *endptr; - counter_t field_value_cnt; + value_t field_value_cnt; + int status; field_name = fields[i]; assert (field_name != NULL); @@ -201,11 +198,9 @@ static void fscache_read_stats_file (FILE *fh) *field_value_str = 0; field_value_str++; - errno = 0; - endptr = NULL; - field_value_cnt = (counter_t) strtoull (field_value_str, - &endptr, /* base = */ 10); - if ((errno != 0) || (endptr == field_value_str)) + status = parse_value (field_value_str, &field_value_cnt, + DS_TYPE_DERIVE); + if (status != 0) continue; fscache_submit (section, field_name, field_value_cnt); diff --git a/src/interface.c b/src/interface.c index 177afbaa..c1e28e32 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1,6 +1,6 @@ /** * collectd - src/interface.c - * Copyright (C) 2005-2008 Florian octo Forster + * Copyright (C) 2005-2010 Florian octo Forster * Copyright (C) 2009 Manuel Sanmartin * * This program is free software; you can redistribute it and/or modify it @@ -128,7 +128,7 @@ static int interface_config (const char *key, const char *value) static int interface_init (void) { kstat_t *ksp_chain; - unsigned long long val; + derive_t val; numif = 0; @@ -155,8 +155,8 @@ static int interface_init (void) #endif /* HAVE_LIBKSTAT */ static void if_submit (const char *dev, const char *type, - unsigned long long rx, - unsigned long long tx) + derive_t rx, + derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; @@ -164,8 +164,8 @@ static void if_submit (const char *dev, const char *type, if (ignorelist_match (ignorelist, dev) != 0) return; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; vl.values = values; vl.values_len = 2; @@ -233,7 +233,7 @@ static int interface_read (void) #elif KERNEL_LINUX FILE *fh; char buffer[1024]; - unsigned long long incoming, outgoing; + derive_t incoming, outgoing; char *device; char *dummy; @@ -285,8 +285,8 @@ static int interface_read (void) #elif HAVE_LIBKSTAT int i; - unsigned long long rx; - unsigned long long tx; + derive_t rx; + derive_t tx; if (kc == NULL) return (-1); diff --git a/src/netapp.c b/src/netapp.c index 5d100a69..d9bd1ae5 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -593,30 +593,30 @@ static int submit_values (const char *host, /* {{{ */ return (plugin_dispatch_values (&vl)); } /* }}} int submit_uint64 */ -static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */ - const char *type, const char *type_inst, counter_t val0, counter_t val1, +static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ */ + const char *type, const char *type_inst, derive_t val0, derive_t val1, cdtime_t timestamp, cdtime_t interval) { value_t values[2]; - values[0].counter = val0; - values[1].counter = val1; + values[0].derive = val0; + values[1].derive = val1; return (submit_values (host, plugin_inst, type, type_inst, values, 2, timestamp, interval)); -} /* }}} int submit_two_counters */ +} /* }}} int submit_two_derive */ -static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */ - const char *type, const char *type_inst, counter_t counter, +static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */ + const char *type, const char *type_inst, derive_t counter, cdtime_t timestamp, cdtime_t interval) { value_t v; - v.counter = counter; + v.derive = counter; return (submit_values (host, plugin_inst, type, type_inst, &v, 1, timestamp, interval)); -} /* }}} int submit_counter */ +} /* }}} int submit_derive */ static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */ const char *type, const char *type_inst, gauge_t val0, gauge_t val1, @@ -744,16 +744,16 @@ static int submit_volume_perf_data (const char *hostname, /* {{{ */ if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO) && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE)) { - submit_two_counters (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL, - (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp, interval); + submit_two_derive (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL, + (derive_t) new_data->read_bytes, (derive_t) new_data->write_bytes, new_data->timestamp, interval); } /* Check for and submit disk-operations values */ if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS) && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE)) { - submit_two_counters (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL, - (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp, interval); + submit_two_derive (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL, + (derive_t) new_data->read_ops, (derive_t) new_data->write_ops, new_data->timestamp, interval); } /* Check for, calculate and submit disk-latency values */ @@ -1739,9 +1739,9 @@ static int cna_handle_system_data (const char *hostname, /* {{{ */ na_elem_t *counter; na_elem_iter_t counter_iter; - counter_t disk_read = 0, disk_written = 0; - counter_t net_recv = 0, net_sent = 0; - counter_t cpu_busy = 0, cpu_total = 0; + derive_t disk_read = 0, disk_written = 0; + derive_t net_recv = 0, net_sent = 0; + derive_t cpu_busy = 0, cpu_total = 0; uint32_t counter_flags = 0; const char *instance; @@ -1784,47 +1784,47 @@ static int cna_handle_system_data (const char *hostname, /* {{{ */ continue; if (!strcmp(name, "disk_data_read")) { - disk_read = (counter_t) (value * 1024); + disk_read = (derive_t) (value * 1024); counter_flags |= 0x01; } else if (!strcmp(name, "disk_data_written")) { - disk_written = (counter_t) (value * 1024); + disk_written = (derive_t) (value * 1024); counter_flags |= 0x02; } else if (!strcmp(name, "net_data_recv")) { - net_recv = (counter_t) (value * 1024); + net_recv = (derive_t) (value * 1024); counter_flags |= 0x04; } else if (!strcmp(name, "net_data_sent")) { - net_sent = (counter_t) (value * 1024); + net_sent = (derive_t) (value * 1024); counter_flags |= 0x08; } else if (!strcmp(name, "cpu_busy")) { - cpu_busy = (counter_t) value; + cpu_busy = (derive_t) value; counter_flags |= 0x10; } else if (!strcmp(name, "cpu_elapsed_time")) { - cpu_total = (counter_t) value; + cpu_total = (derive_t) value; counter_flags |= 0x20; } else if ((cfg_system->flags & CFG_SYSTEM_OPS) && (value > 0) && (strlen(name) > 4) && (!strcmp(name + strlen(name) - 4, "_ops"))) { - submit_counter (hostname, instance, "disk_ops_complex", name, - (counter_t) value, timestamp, interval); + submit_derive (hostname, instance, "disk_ops_complex", name, + (derive_t) value, timestamp, interval); } } /* for (counter) */ if ((cfg_system->flags & CFG_SYSTEM_DISK) && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02))) - submit_two_counters (hostname, instance, "disk_octets", NULL, + submit_two_derive (hostname, instance, "disk_octets", NULL, disk_read, disk_written, timestamp, interval); if ((cfg_system->flags & CFG_SYSTEM_NET) && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08))) - submit_two_counters (hostname, instance, "if_octets", NULL, + submit_two_derive (hostname, instance, "if_octets", NULL, net_recv, net_sent, timestamp, interval); if ((cfg_system->flags & CFG_SYSTEM_CPU) && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20))) { - submit_counter (hostname, instance, "cpu", "system", + submit_derive (hostname, instance, "cpu", "system", cpu_busy, timestamp, interval); - submit_counter (hostname, instance, "cpu", "idle", + submit_derive (hostname, instance, "cpu", "idle", cpu_total - cpu_busy, timestamp, interval); } diff --git a/src/network.c b/src/network.c index 7a1fcf7f..cc3d6b3a 100644 --- a/src/network.c +++ b/src/network.c @@ -1,6 +1,6 @@ /** * collectd - src/network.c - * Copyright (C) 2005-2009 Florian octo Forster + * Copyright (C) 2005-2010 Florian octo Forster * Copyright (C) 2009 Aman Gupta * * This program is free software; you can redistribute it and/or modify it @@ -296,14 +296,14 @@ static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER; * example). Only if neither is true, the stats_lock is acquired. The counters * are always read without holding a lock in the hope that writing 8 bytes to * memory is an atomic operation. */ -static uint64_t stats_octets_rx = 0; -static uint64_t stats_octets_tx = 0; -static uint64_t stats_packets_rx = 0; -static uint64_t stats_packets_tx = 0; -static uint64_t stats_values_dispatched = 0; -static uint64_t stats_values_not_dispatched = 0; -static uint64_t stats_values_sent = 0; -static uint64_t stats_values_not_sent = 0; +static derive_t stats_octets_rx = 0; +static derive_t stats_octets_tx = 0; +static derive_t stats_packets_rx = 0; +static derive_t stats_packets_tx = 0; +static derive_t stats_values_dispatched = 0; +static derive_t stats_values_not_dispatched = 0; +static derive_t stats_values_sent = 0; +static derive_t stats_values_not_sent = 0; static pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER; /* @@ -3201,15 +3201,15 @@ static int network_shutdown (void) static int network_stats_read (void) /* {{{ */ { - uint64_t copy_octets_rx; - uint64_t copy_octets_tx; - uint64_t copy_packets_rx; - uint64_t copy_packets_tx; - uint64_t copy_values_dispatched; - uint64_t copy_values_not_dispatched; - uint64_t copy_values_sent; - uint64_t copy_values_not_sent; - uint64_t copy_receive_list_length; + derive_t copy_octets_rx; + derive_t copy_octets_tx; + derive_t copy_packets_rx; + derive_t copy_packets_tx; + derive_t copy_values_dispatched; + derive_t copy_values_not_dispatched; + derive_t copy_values_sent; + derive_t copy_values_not_sent; + derive_t copy_receive_list_length; value_list_t vl = VALUE_LIST_INIT; value_t values[2]; @@ -3232,14 +3232,14 @@ static int network_stats_read (void) /* {{{ */ sstrncpy (vl.plugin, "network", sizeof (vl.plugin)); /* Octets received / sent */ - vl.values[0].counter = (counter_t) copy_octets_rx; - vl.values[1].counter = (counter_t) copy_octets_tx; + vl.values[0].derive = (derive_t) copy_octets_rx; + vl.values[1].derive = (derive_t) copy_octets_tx; sstrncpy (vl.type, "if_octets", sizeof (vl.type)); plugin_dispatch_values (&vl); /* Packets received / send */ - vl.values[0].counter = (counter_t) copy_packets_rx; - vl.values[1].counter = (counter_t) copy_packets_tx; + vl.values[0].derive = (derive_t) copy_packets_rx; + vl.values[1].derive = (derive_t) copy_packets_tx; sstrncpy (vl.type, "if_packets", sizeof (vl.type)); plugin_dispatch_values (&vl); diff --git a/src/processes.c b/src/processes.c index 30798d42..655cddb7 100644 --- a/src/processes.c +++ b/src/processes.c @@ -1,7 +1,7 @@ /** * collectd - src/processes.c * Copyright (C) 2005 Lyonel Vincent - * Copyright (C) 2006-2008 Florian octo Forster + * Copyright (C) 2006-2010 Florian octo Forster * Copyright (C) 2008 Oleg King * Copyright (C) 2009 Sebastian Harl * Copyright (C) 2009 Andrés J. Díaz @@ -143,13 +143,13 @@ typedef struct procstat_entry_s unsigned long vmem_minflt; unsigned long vmem_majflt; - unsigned long vmem_minflt_counter; - unsigned long vmem_majflt_counter; + derive_t vmem_minflt_counter; + derive_t vmem_majflt_counter; unsigned long cpu_user; unsigned long cpu_system; - unsigned long cpu_user_counter; - unsigned long cpu_system_counter; + derive_t cpu_user_counter; + derive_t cpu_system_counter; /* io data */ derive_t io_rchar; @@ -176,11 +176,11 @@ typedef struct procstat unsigned long vmem_code; unsigned long stack_size; - unsigned long vmem_minflt_counter; - unsigned long vmem_majflt_counter; + derive_t vmem_minflt_counter; + derive_t vmem_majflt_counter; - unsigned long cpu_user_counter; - unsigned long cpu_system_counter; + derive_t cpu_user_counter; + derive_t cpu_system_counter; /* io data */ derive_t io_rchar; @@ -664,8 +664,8 @@ static void ps_submit_proc_list (procstat_t *ps) plugin_dispatch_values (&vl); sstrncpy (vl.type, "ps_cputime", sizeof (vl.type)); - vl.values[0].counter = ps->cpu_user_counter; - vl.values[1].counter = ps->cpu_system_counter; + vl.values[0].derive = ps->cpu_user_counter; + vl.values[1].derive = ps->cpu_system_counter; vl.values_len = 2; plugin_dispatch_values (&vl); @@ -676,8 +676,8 @@ static void ps_submit_proc_list (procstat_t *ps) plugin_dispatch_values (&vl); sstrncpy (vl.type, "ps_pagefaults", sizeof (vl.type)); - vl.values[0].counter = ps->vmem_minflt_counter; - vl.values[1].counter = ps->vmem_majflt_counter; + vl.values[0].derive = ps->vmem_minflt_counter; + vl.values[1].derive = ps->vmem_majflt_counter; vl.values_len = 2; plugin_dispatch_values (&vl); @@ -702,8 +702,8 @@ static void ps_submit_proc_list (procstat_t *ps) DEBUG ("name = %s; num_proc = %lu; num_lwp = %lu; " "vmem_size = %lu; vmem_rss = %lu; vmem_data = %lu; " "vmem_code = %lu; " - "vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; " - "cpu_user_counter = %lu; cpu_system_counter = %lu; " + "vmem_minflt_counter = %"PRIi64"; vmem_majflt_counter = %"PRIi64"; " + "cpu_user_counter = %"PRIi64"; cpu_system_counter = %"PRIi64"; " "io_rchar = %"PRIi64"; io_wchar = %"PRIi64"; " "io_syscr = %"PRIi64"; io_syscw = %"PRIi64";", ps->name, ps->num_proc, ps->num_lwp, @@ -874,8 +874,8 @@ int ps_read_process (int pid, procstat_t *ps, char *state) int ppid; int name_len; - long long unsigned cpu_user_counter; - long long unsigned cpu_system_counter; + derive_t cpu_user_counter; + derive_t cpu_system_counter; long long unsigned vmem_size; long long unsigned vmem_rss; long long unsigned stack_size; @@ -940,8 +940,8 @@ int ps_read_process (int pid, procstat_t *ps, char *state) cpu_system_counter = atoll (fields[14]); vmem_size = atoll (fields[22]); vmem_rss = atoll (fields[23]); - ps->vmem_minflt_counter = atol (fields[9]); - ps->vmem_majflt_counter = atol (fields[11]); + ps->vmem_minflt_counter = atoll (fields[9]); + ps->vmem_majflt_counter = atoll (fields[11]); { unsigned long long stack_start = atoll (fields[27]); @@ -965,8 +965,8 @@ int ps_read_process (int pid, procstat_t *ps, char *state) DEBUG("ps_read_process: did not get vmem data for pid %i",pid); } - ps->cpu_user_counter = (unsigned long) cpu_user_counter; - ps->cpu_system_counter = (unsigned long) cpu_system_counter; + ps->cpu_user_counter = cpu_user_counter; + ps->cpu_system_counter = cpu_system_counter; ps->vmem_size = (unsigned long) vmem_size; ps->vmem_rss = (unsigned long) vmem_rss; ps->stack_size = (unsigned long) stack_size; diff --git a/src/serial.c b/src/serial.c index cfa26bbd..9bd885db 100644 --- a/src/serial.c +++ b/src/serial.c @@ -30,13 +30,13 @@ #endif static void serial_submit (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; @@ -54,8 +54,8 @@ static int serial_read (void) FILE *fh; char buffer[1024]; - counter_t rx = 0; - counter_t tx = 0; + derive_t rx = 0; + derive_t tx = 0; char *fields[16]; int i, numfields; diff --git a/src/vmem.c b/src/vmem.c index d32f1db8..56997bf1 100644 --- a/src/vmem.c +++ b/src/vmem.c @@ -1,6 +1,6 @@ /** * collectd - src/vmem.c - * Copyright (C) 2008 Florian octo Forster + * Copyright (C) 2008-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" @@ -57,12 +57,12 @@ static void submit (const char *plugin_instance, const char *type, } /* void vmem_submit */ static void submit_two (const char *plugin_instance, const char *type, - const char *type_instance, counter_t c0, counter_t c1) + const char *type_instance, derive_t c0, derive_t c1) { value_t values[2]; - values[0].counter = c0; - values[1].counter = c1; + values[0].derive = c0; + values[1].derive = c1; submit (plugin_instance, type, type_instance, values, 2); } /* void submit_one */ @@ -93,16 +93,16 @@ static int vmem_config (const char *key, const char *value) static int vmem_read (void) { #if KERNEL_LINUX - counter_t pgpgin = 0; - counter_t pgpgout = 0; + derive_t pgpgin = 0; + derive_t pgpgout = 0; int pgpgvalid = 0; - counter_t pswpin = 0; - counter_t pswpout = 0; + derive_t pswpin = 0; + derive_t pswpout = 0; int pswpvalid = 0; - counter_t pgfault = 0; - counter_t pgmajfault = 0; + derive_t pgfault = 0; + derive_t pgmajfault = 0; int pgfaultvalid = 0; FILE *fh; @@ -123,7 +123,7 @@ static int vmem_read (void) int fields_num; char *key; char *endptr; - counter_t counter; + derive_t counter; gauge_t gauge; fields_num = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields)); @@ -205,31 +205,31 @@ static int vmem_read (void) else if (strncmp ("pgalloc_", key, strlen ("pgalloc_")) == 0) { char *inst = key + strlen ("pgalloc_"); - value_t value = { .counter = counter }; + value_t value = { .derive = counter }; submit_one (inst, "vmpage_action", "alloc", value); } else if (strncmp ("pgrefill_", key, strlen ("pgrefill_")) == 0) { char *inst = key + strlen ("pgrefill_"); - value_t value = { .counter = counter }; + value_t value = { .derive = counter }; submit_one (inst, "vmpage_action", "refill", value); } else if (strncmp ("pgsteal_", key, strlen ("pgsteal_")) == 0) { char *inst = key + strlen ("pgsteal_"); - value_t value = { .counter = counter }; + value_t value = { .derive = counter }; submit_one (inst, "vmpage_action", "steal", value); } else if (strncmp ("pgscan_kswapd_", key, strlen ("pgscan_kswapd_")) == 0) { char *inst = key + strlen ("pgscan_kswapd_"); - value_t value = { .counter = counter }; + value_t value = { .derive = counter }; submit_one (inst, "vmpage_action", "scan_kswapd", value); } else if (strncmp ("pgscan_direct_", key, strlen ("pgscan_direct_")) == 0) { char *inst = key + strlen ("pgscan_direct_"); - value_t value = { .counter = counter }; + value_t value = { .derive = counter }; submit_one (inst, "vmpage_action", "scan_direct", value); } @@ -241,17 +241,17 @@ static int vmem_read (void) */ else if (strcmp ("pgfree", key) == 0) { - value_t value = { .counter = counter }; + value_t value = { .derive = counter }; submit_one (NULL, "vmpage_action", "free", value); } else if (strcmp ("pgactivate", key) == 0) { - value_t value = { .counter = counter }; + value_t value = { .derive = counter }; submit_one (NULL, "vmpage_action", "activate", value); } else if (strcmp ("pgdeactivate", key) == 0) { - value_t value = { .counter = counter }; + value_t value = { .derive = counter }; submit_one (NULL, "vmpage_action", "deactivate", value); } } /* while (fgets) */ diff --git a/src/vserver.c b/src/vserver.c index 1615ca04..d80717cd 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -1,7 +1,7 @@ /** * collectd - src/vserver.c * Copyright (C) 2006,2007 Sebastian Harl - * Copyright (C) 2007,2008 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 @@ -48,13 +48,13 @@ static int vserver_init (void) } /* static void vserver_init(void) */ static void traffic_submit (const char *plugin_instance, - 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); @@ -107,14 +107,21 @@ static void submit_gauge (const char *plugin_instance, const char *type, plugin_dispatch_values (&vl); } /* void submit_gauge */ -static inline long long __get_sock_bytes(const char *s) +static derive_t vserver_get_sock_bytes(const char *s) { + value_t v; + int status; + while (s[0] != '/') ++s; /* Remove '/' */ ++s; - return atoll(s); + + status = parse_value (s, &v, DS_TYPE_DERIVE); + if (status != 0) + return (-1); + return (v.derive); } static int vserver_read (void) @@ -201,8 +208,8 @@ static int vserver_read (void) while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh))) { - counter_t rx; - counter_t tx; + derive_t rx; + derive_t tx; char *type_instance; if (strsplit (buffer, cols, 4) < 4) @@ -221,8 +228,8 @@ static int vserver_read (void) else continue; - rx = __get_sock_bytes (cols[1]); - tx = __get_sock_bytes (cols[2]); + rx = vserver_get_sock_bytes (cols[1]); + tx = vserver_get_sock_bytes (cols[2]); /* cols[3] == errors */ traffic_submit (dent->d_name, type_instance, rx, tx);