X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetapp.c;h=f7bc04d3b1db35c54ab5a607316c9f1fc146209d;hb=b4c8f3f762d666742c774ab3b45815e5a416e5da;hp=c50b3dbdbcb707860d7a4658d211e844f1b3fe3a;hpb=a898c17330d9a2039bcdb8f7e6dbedba516a6cd8;p=collectd.git diff --git a/src/netapp.c b/src/netapp.c index c50b3dbd..f7bc04d3 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -1,6 +1,6 @@ /** * collectd - src/netapp.c - * Copyright (C) 2009 Sven Trenkel + * Copyright (C) 2009,2010 Sven Trenkel * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -38,8 +38,8 @@ typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *dat struct cna_interval_s { - time_t interval; - time_t last_read; + cdtime_t interval; + cdtime_t last_read; }; typedef struct cna_interval_s cna_interval_t; @@ -79,7 +79,7 @@ typedef struct { cna_interval_t interval; na_elem_t *query; - time_t timestamp; + cdtime_t timestamp; uint64_t name_cache_hit; uint64_t name_cache_miss; uint64_t find_dir_hit; @@ -104,7 +104,7 @@ typedef struct { typedef struct disk_s { char *name; uint32_t flags; - time_t timestamp; + cdtime_t timestamp; uint64_t disk_busy; uint64_t base_for_disk_busy; double disk_busy_percent; @@ -153,7 +153,7 @@ typedef struct data_volume_perf_s data_volume_perf_t; struct data_volume_perf_s { char *name; uint32_t flags; - time_t timestamp; + cdtime_t timestamp; uint64_t read_bytes; uint64_t write_bytes; @@ -242,7 +242,7 @@ struct host_config_s { int port; char *username; char *password; - int interval; + cdtime_t interval; na_server_t *srv; cfg_wafl_t *cfg_wafl; @@ -566,7 +566,7 @@ static int submit_values (const char *host, /* {{{ */ const char *plugin_inst, const char *type, const char *type_inst, value_t *values, int values_len, - time_t timestamp, int interval) + cdtime_t timestamp, cdtime_t interval) { value_list_t vl = VALUE_LIST_INIT; @@ -593,33 +593,34 @@ 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, - time_t timestamp, int interval) +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, time_t timestamp, int interval) +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, - time_t timestamp, int interval) + cdtime_t timestamp, cdtime_t interval) { value_t values[2]; @@ -631,7 +632,8 @@ static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ * } /* }}} int submit_two_gauge */ static int submit_double (const char *host, const char *plugin_inst, /* {{{ */ - const char *type, const char *type_inst, double d, time_t timestamp, int interval) + const char *type, const char *type_inst, double d, + cdtime_t timestamp, cdtime_t interval) { value_t v; @@ -650,8 +652,8 @@ static int submit_cache_ratio (const char *host, /* {{{ */ uint64_t new_misses, uint64_t old_hits, uint64_t old_misses, - time_t timestamp, - int interval) + cdtime_t timestamp, + cdtime_t interval) { value_t v; @@ -742,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 */ @@ -816,6 +818,16 @@ static int submit_volume_perf_data (const char *hostname, /* {{{ */ return (0); } /* }}} int submit_volume_perf_data */ +static cdtime_t cna_child_get_cdtime (na_elem_t *data) /* {{{ */ +{ + time_t t; + + t = (time_t) na_child_get_uint64 (data, "timestamp", /* default = */ 0); + + return (TIME_T_TO_CDTIME_T (t)); +} /* }}} cdtime_t cna_child_get_cdtime */ + + /* * Query functions * @@ -835,7 +847,7 @@ static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* memset (&perf_data, 0, sizeof (perf_data)); - perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0); + perf_data.timestamp = cna_child_get_cdtime (data); instances = na_elem_child(na_elem_child (data, "instances"), "instance-data"); if (instances == NULL) @@ -950,7 +962,7 @@ static int cna_query_wafl (host_config_t *host) /* {{{ */ { na_elem_t *data; int status; - time_t now; + cdtime_t now; if (host == NULL) return (EINVAL); @@ -959,7 +971,7 @@ static int cna_query_wafl (host_config_t *host) /* {{{ */ if (host->cfg_wafl == NULL) return (0); - now = time (NULL); + now = cdtime (); if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now) return (0); @@ -988,9 +1000,9 @@ static int cna_query_wafl (host_config_t *host) /* {{{ */ /* Data corresponding to */ static int cna_handle_disk_data (const char *hostname, /* {{{ */ - cfg_disk_t *cfg_disk, na_elem_t *data, int interval) + cfg_disk_t *cfg_disk, na_elem_t *data, cdtime_t interval) { - time_t timestamp; + cdtime_t timestamp; na_elem_t *instances; na_elem_t *instance; na_elem_iter_t instance_iter; @@ -999,7 +1011,7 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ if ((cfg_disk == NULL) || (data == NULL)) return (EINVAL); - timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0); + timestamp = cna_child_get_cdtime (data); instances = na_elem_child (data, "instances"); if (instances == NULL) @@ -1144,7 +1156,7 @@ static int cna_query_disk (host_config_t *host) /* {{{ */ { na_elem_t *data; int status; - time_t now; + cdtime_t now; if (host == NULL) return (EINVAL); @@ -1154,7 +1166,7 @@ static int cna_query_disk (host_config_t *host) /* {{{ */ if (host->cfg_disk == NULL) return (0); - now = time (NULL); + now = cdtime (); if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now) return (0); @@ -1183,14 +1195,14 @@ static int cna_query_disk (host_config_t *host) /* {{{ */ /* Data corresponding to */ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ - cfg_volume_perf_t *cvp, na_elem_t *data, int interval) + cfg_volume_perf_t *cvp, na_elem_t *data, cdtime_t interval) { - time_t timestamp; + cdtime_t timestamp; na_elem_t *elem_instances; na_elem_iter_t iter_instances; na_elem_t *elem_instance; - timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0); + timestamp = cna_child_get_cdtime (data); elem_instances = na_elem_child(data, "instances"); if (elem_instances == NULL) @@ -1315,7 +1327,7 @@ static int cna_query_volume_perf (host_config_t *host) /* {{{ */ { na_elem_t *data; int status; - time_t now; + cdtime_t now; if (host == NULL) return (EINVAL); @@ -1325,7 +1337,7 @@ static int cna_query_volume_perf (host_config_t *host) /* {{{ */ if (host->cfg_volume_perf == NULL) return (0); - now = time (NULL); + now = cdtime (); if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now) return (0); @@ -1444,7 +1456,7 @@ static int cna_change_volume_status (const char *hostname, /* {{{ */ notification_t n; memset (&n, 0, sizeof (&n)); - n.time = time (NULL); + n.time = cdtime (); sstrncpy (n.host, hostname, sizeof (n.host)); sstrncpy (n.plugin, "netapp", sizeof (n.plugin)); sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance)); @@ -1590,6 +1602,9 @@ static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */ if (sis == NULL) continue; + if (na_elem_child(sis, "sis-info")) + sis = na_elem_child(sis, "sis-info"); + sis_state = na_child_get_string(sis, "state"); if (sis_state == NULL) continue; @@ -1679,7 +1694,7 @@ static int cna_query_volume_usage (host_config_t *host) /* {{{ */ { na_elem_t *data; int status; - time_t now; + cdtime_t now; if (host == NULL) return (EINVAL); @@ -1689,7 +1704,7 @@ static int cna_query_volume_usage (host_config_t *host) /* {{{ */ if (host->cfg_volume_usage == NULL) return (0); - now = time (NULL); + now = cdtime (); if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now) return (0); @@ -1724,15 +1739,15 @@ 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; - time_t timestamp; + cdtime_t timestamp; - timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0); + timestamp = cna_child_get_cdtime (data); instances = na_elem_child(na_elem_child (data, "instances"), "instance-data"); if (instances == NULL) @@ -1769,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); } @@ -1839,7 +1854,7 @@ static int cna_query_system (host_config_t *host) /* {{{ */ { na_elem_t *data; int status; - time_t now; + cdtime_t now; if (host == NULL) return (EINVAL); @@ -1848,7 +1863,7 @@ static int cna_query_system (host_config_t *host) /* {{{ */ if (host->cfg_system == NULL) return (0); - now = time (NULL); + now = cdtime (); if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now) return (0); @@ -1905,23 +1920,12 @@ static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */ static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */ cna_interval_t *out_interval) { - time_t tmp; - - if ((ci == NULL) || (out_interval == NULL)) - return (EINVAL); - - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) - { - WARNING ("netapp plugin: The `Interval' option needs exactly one numeric argument."); - return (-1); - } + cdtime_t tmp = 0; + int status; - tmp = (time_t) (ci->values[0].value.number + .5); - if (tmp < 1) - { - WARNING ("netapp plugin: The `Interval' option needs a positive integer argument."); - return (-1); - } + status = cf_util_get_cdtime (ci, &tmp); + if (status != 0) + return (status); out_interval->interval = tmp; out_interval->last_read = 0; @@ -2421,11 +2425,7 @@ static host_config_t *cna_config_host (const oconfig_item_t *ci) /* {{{ */ } else if (!strcasecmp(item->key, "Password")) { status = cf_util_get_string (item, &host->password); } else if (!strcasecmp(item->key, "Interval")) { - if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_NUMBER || item->values[0].value.number != (int) item->values[0].value.number || item->values[0].value.number < 2) { - WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string); - continue; - } - host->interval = item->values[0].value.number; + status = cf_util_get_cdtime (item, &host->interval); } else if (!strcasecmp(item->key, "WAFL")) { cna_config_wafl(host, item); } else if (!strcasecmp(item->key, "Disks")) { @@ -2497,7 +2497,7 @@ static int cna_init_host (host_config_t *host) /* {{{ */ na_server_adminuser(host->srv, host->username, host->password); na_server_set_timeout(host->srv, 5 /* seconds */); - return 0; + return (0); } /* }}} int cna_init_host */ static int cna_init (void) /* {{{ */ @@ -2514,6 +2514,32 @@ static int cna_init (void) /* {{{ */ return (0); } /* }}} cna_init */ +static int cna_read_internal (host_config_t *host) { /* {{{ */ + int status; + + status = cna_query_wafl (host); + if (status != 0) + return (status); + + status = cna_query_disk (host); + if (status != 0) + return (status); + + status = cna_query_volume_perf (host); + if (status != 0) + return (status); + + status = cna_query_volume_usage (host); + if (status != 0) + return (status); + + status = cna_query_system (host); + if (status != 0) + return (status); + + return 0; +} /* }}} int cna_read_internal */ + static int cna_read (user_data_t *ud) { /* {{{ */ host_config_t *host; int status; @@ -2526,12 +2552,14 @@ static int cna_read (user_data_t *ud) { /* {{{ */ status = cna_init_host (host); if (status != 0) return (status); - - cna_query_wafl (host); - cna_query_disk (host); - cna_query_volume_perf (host); - cna_query_volume_usage (host); - cna_query_system (host); + + status = cna_read_internal (host); + if (status != 0) + { + if (host->srv != NULL) + na_server_close (host->srv); + host->srv = NULL; + } return 0; } /* }}} int cna_read */ @@ -2556,8 +2584,7 @@ static int cna_config (oconfig_item_t *ci) { /* {{{ */ ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name); - memset (&interval, 0, sizeof (interval)); - interval.tv_sec = host->interval; + CDTIME_T_TO_TIMESPEC (host->interval, &interval); memset (&ud, 0, sizeof (ud)); ud.data = host;