From: Florian Forster Date: Sat, 18 Nov 2017 08:56:30 +0000 (+0100) Subject: Merge branch 'collectd-5.8' X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=22813e1a6a3d059efc67975893df985052661a7a;hp=161388c36cb939d4ea2e33614103208b57bcfd15 Merge branch 'collectd-5.8' --- diff --git a/configure.ac b/configure.ac index 55f78d8a..e869a6a0 100644 --- a/configure.ac +++ b/configure.ac @@ -5718,20 +5718,25 @@ if test "x$with_libvarnish" = "xyes"; then SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $with_libvarnish_cflags" - AC_CHECK_HEADERS([vapi/vsc.h], - [AC_DEFINE([HAVE_VARNISH_V4], [1], [Varnish 4 API support])], - [ - AC_CHECK_HEADERS([vsc.h], - [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support]) ], - [ - AC_CHECK_HEADERS([varnishapi.h], - [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])], - [with_libvarnish="no (found none of the varnish header files)"] - ) - ] - ) - ] - ) + $PKG_CONFIG --atleast-version=5.2 'varnishapi' 2>/dev/null + if test $? -eq 0; then + AC_DEFINE([HAVE_VARNISH_V5], [1], [Varnish 5 API support]) + else + AC_CHECK_HEADERS([vapi/vsc.h], + [AC_DEFINE([HAVE_VARNISH_V4], [1], [Varnish 4 API support])], + [ + AC_CHECK_HEADERS([vsc.h], + [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support]) ], + [ + AC_CHECK_HEADERS([varnishapi.h], + [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])], + [with_libvarnish="no (found none of the varnish header files)"] + ) + ] + ) + ] + ) + fi CPPFLAGS="$SAVE_CPPFLAGS" fi diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 2051f389..4efa29e4 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1171,7 +1171,7 @@ # # Interval 60 # Service "service_name" -# Query backend # predefined +# Query backends # predefined # Query rt36_tickets # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 97d184a1..0e7a6046 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -6258,7 +6258,7 @@ L. Interval 300 Service "service_name" - Query backend # predefined + Query backends # predefined Query rt36_tickets diff --git a/src/daemon/meta_data.c b/src/daemon/meta_data.c index ce3e1020..4d59b712 100644 --- a/src/daemon/meta_data.c +++ b/src/daemon/meta_data.c @@ -737,7 +737,6 @@ int meta_data_as_string(meta_data_t *md, /* {{{ */ temp = md_strdup(actual); if (temp == NULL) { - pthread_mutex_unlock(&md->lock); ERROR("meta_data_as_string: md_strdup failed for key `%s'.", key); return -ENOMEM; } diff --git a/src/gps.c b/src/gps.c index 210c2934..ecb4bbaa 100644 --- a/src/gps.c +++ b/src/gps.c @@ -307,7 +307,6 @@ static int cgps_shutdown(void) { free(res); // Clean mutex: - pthread_mutex_unlock(&cgps_thread_lock); pthread_mutex_destroy(&cgps_thread_lock); pthread_mutex_unlock(&cgps_data_lock); pthread_mutex_destroy(&cgps_data_lock); diff --git a/src/libcollectdclient/network_buffer.c b/src/libcollectdclient/network_buffer.c index 662265d9..a0f8cfdc 100644 --- a/src/libcollectdclient/network_buffer.c +++ b/src/libcollectdclient/network_buffer.c @@ -255,6 +255,10 @@ static double htond(double val) /* {{{ */ static int nb_add_values(char **ret_buffer, /* {{{ */ size_t *ret_buffer_len, const lcc_value_list_t *vl) { + if ((vl == NULL) || (vl->values_len < 1)) { + return EINVAL; + } + char *packet_ptr; size_t packet_len; diff --git a/src/libcollectdclient/network_parse.c b/src/libcollectdclient/network_parse.c index 67034116..2365ab0a 100644 --- a/src/libcollectdclient/network_parse.c +++ b/src/libcollectdclient/network_parse.c @@ -43,6 +43,23 @@ #include #elif HAVE_SYS_ENDIAN_H #include +#else /* fallback */ +__attribute__((const)) static uint16_t be16toh(uint16_t n) { + uint8_t tmp[2]; + memmove(tmp, &n, sizeof(tmp)); + + return ((uint16_t)tmp[0] << 8) | ((uint16_t)tmp[1] << 0); +} + +__attribute__((const)) static uint64_t be64toh(uint64_t n) { + uint8_t tmp[8]; + memmove(tmp, &n, sizeof(tmp)); + + return ((uint64_t)tmp[0] << 56) | ((uint64_t)tmp[1] << 48) | + ((uint64_t)tmp[2] << 40) | ((uint64_t)tmp[3] << 32) | + ((uint64_t)tmp[4] << 24) | ((uint64_t)tmp[5] << 16) | + ((uint64_t)tmp[6] << 8) | ((uint64_t)tmp[7] << 0); +} #endif #if HAVE_GCRYPT_H diff --git a/src/mcelog.c b/src/mcelog.c index 9838fce9..1a92a065 100644 --- a/src/mcelog.c +++ b/src/mcelog.c @@ -75,12 +75,12 @@ struct socket_adapter_s { typedef struct mcelog_memory_rec_s { int corrected_err_total; /* x total*/ int corrected_err_timed; /* x in 24h*/ - char corrected_err_timed_period[DATA_MAX_NAME_LEN]; + char corrected_err_timed_period[DATA_MAX_NAME_LEN / 2]; int uncorrected_err_total; /* x total*/ int uncorrected_err_timed; /* x in 24h*/ - char uncorrected_err_timed_period[DATA_MAX_NAME_LEN]; - char location[DATA_MAX_NAME_LEN]; /* SOCKET x CHANNEL x DIMM x*/ - char dimm_name[DATA_MAX_NAME_LEN]; /* DMI_NAME "DIMM_F1" */ + char uncorrected_err_timed_period[DATA_MAX_NAME_LEN / 2]; + char location[DATA_MAX_NAME_LEN / 2]; /* SOCKET x CHANNEL x DIMM x*/ + char dimm_name[DATA_MAX_NAME_LEN / 2]; /* DMI_NAME "DIMM_F1" */ } mcelog_memory_rec_t; static int socket_close(socket_adapter_t *self); diff --git a/src/ovs_events.c b/src/ovs_events.c index afa11997..bf457fdb 100644 --- a/src/ovs_events.c +++ b/src/ovs_events.c @@ -253,8 +253,8 @@ static int ovs_events_plugin_config(oconfig_item_t *ci) { ovs_events_config_free(); return -1; } - strncpy(ovs_events_ctx.config.ovs_db_serv, service, - sizeof(ovs_events_ctx.config.ovs_db_serv)); + sstrncpy(ovs_events_ctx.config.ovs_db_serv, service, + sizeof(ovs_events_ctx.config.ovs_db_serv)); sfree(service); } else if (strcasecmp("Socket", child->key) == 0) { if (cf_util_get_string_buffer( diff --git a/src/ovs_stats.c b/src/ovs_stats.c index 20b0dd1f..e2103744 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -330,9 +330,10 @@ static int ovs_stats_update_bridge(yajl_val bridge) { br = ovs_stats_get_bridge(g_bridge_list_head, YAJL_GET_STRING(br_name)); pthread_mutex_lock(&g_stats_lock); if (br == NULL) { - br = (bridge_list_t *)calloc(1, sizeof(bridge_list_t)); + br = calloc(1, sizeof(*br)); if (!br) { - ERROR("%s: Error allocating memory for bridge", plugin_name); + pthread_mutex_unlock(&g_stats_lock); + ERROR("%s: calloc(%zu) failed.", plugin_name, sizeof(*br)); return -1; } char *tmp = YAJL_GET_STRING(br_name); @@ -342,6 +343,7 @@ static int ovs_stats_update_bridge(yajl_val bridge) { if (br->name == NULL) { sfree(br); pthread_mutex_unlock(&g_stats_lock); + ERROR("%s: strdup failed.", plugin_name); return -1; } br->next = g_bridge_list_head; @@ -581,56 +583,57 @@ static int ovs_stats_update_iface_ext_ids(port_list_t *port, yajl_val ext_ids) { /* Get interface statistic and external_ids */ static int ovs_stats_update_iface(yajl_val iface) { - yajl_val row; - port_list_t *port = NULL; - if (iface && YAJL_IS_OBJECT(iface)) { - row = ovs_utils_get_value_by_key(iface, "new"); - if (row && YAJL_IS_OBJECT(row)) { - yajl_val iface_name = ovs_utils_get_value_by_key(row, "name"); - yajl_val iface_stats = ovs_utils_get_value_by_key(row, "statistics"); - yajl_val iface_ext_ids = ovs_utils_get_value_by_key(row, "external_ids"); - yajl_val iface_uuid = ovs_utils_get_value_by_key(row, "_uuid"); - if (iface_name && YAJL_IS_STRING(iface_name)) { - port = ovs_stats_get_port_by_name(YAJL_GET_STRING(iface_name)); - if (port == NULL) - return 0; - } - /* - * { - "statistics": [ - "map", - [ - [ - "collisions", - 0 - ], - . . . - [ - "tx_packets", - 0 - ] - ] - ] - } - Check that statistics is an array with 2 elements - */ - if (iface_stats && YAJL_IS_ARRAY(iface_stats) && - YAJL_GET_ARRAY(iface_stats)->len == 2) - ovs_stats_update_iface_stats(port, - YAJL_GET_ARRAY(iface_stats)->values[1]); - if (iface_ext_ids && YAJL_IS_ARRAY(iface_ext_ids)) - ovs_stats_update_iface_ext_ids( - port, YAJL_GET_ARRAY(iface_ext_ids)->values[1]); - if (iface_uuid && YAJL_IS_ARRAY(iface_uuid) && - YAJL_GET_ARRAY(iface_uuid)->len == 2) - sstrncpy(port->iface_uuid, - YAJL_GET_STRING(YAJL_GET_ARRAY(iface_uuid)->values[1]), - sizeof(port->iface_uuid)); - } - } else { - ERROR("Incorrect JSON Port data"); + if (!iface || !YAJL_IS_OBJECT(iface)) { + ERROR("ovs_stats plugin: incorrect JSON port data"); return -1; } + + yajl_val row = ovs_utils_get_value_by_key(iface, "new"); + if (!row || !YAJL_IS_OBJECT(row)) + return 0; + + yajl_val iface_name = ovs_utils_get_value_by_key(row, "name"); + if (!iface_name || !YAJL_IS_STRING(iface_name)) + return 0; + + port_list_t *port = ovs_stats_get_port_by_name(YAJL_GET_STRING(iface_name)); + if (port == NULL) + return 0; + + yajl_val iface_stats = ovs_utils_get_value_by_key(row, "statistics"); + yajl_val iface_ext_ids = ovs_utils_get_value_by_key(row, "external_ids"); + yajl_val iface_uuid = ovs_utils_get_value_by_key(row, "_uuid"); + /* + * { + "statistics": [ + "map", + [ + [ + "collisions", + 0 + ], + . . . + [ + "tx_packets", + 0 + ] + ] + ] + } + Check that statistics is an array with 2 elements + */ + if (iface_stats && YAJL_IS_ARRAY(iface_stats) && + YAJL_GET_ARRAY(iface_stats)->len == 2) + ovs_stats_update_iface_stats(port, YAJL_GET_ARRAY(iface_stats)->values[1]); + if (iface_ext_ids && YAJL_IS_ARRAY(iface_ext_ids)) + ovs_stats_update_iface_ext_ids(port, + YAJL_GET_ARRAY(iface_ext_ids)->values[1]); + if (iface_uuid && YAJL_IS_ARRAY(iface_uuid) && + YAJL_GET_ARRAY(iface_uuid)->len == 2) + sstrncpy(port->iface_uuid, + YAJL_GET_STRING(YAJL_GET_ARRAY(iface_uuid)->values[1]), + sizeof(port->iface_uuid)); + return 0; } @@ -789,7 +792,6 @@ static void ovs_stats_conn_terminate() { */ static int ovs_stats_plugin_config(oconfig_item_t *ci) { bridge_list_t *bridge; - char *br_name; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -821,19 +823,22 @@ static int ovs_stats_plugin_config(oconfig_item_t *ci) { goto cleanup_fail; } /* get value */ - if ((br_name = strdup(child->values[j].value.string)) == NULL) { - ERROR("%s: strdup() copy bridge name fail", plugin_name); - goto cleanup_fail; - } + char const *br_name = child->values[j].value.string; if ((bridge = ovs_stats_get_bridge(g_monitored_bridge_list_head, br_name)) == NULL) { if ((bridge = calloc(1, sizeof(bridge_list_t))) == NULL) { ERROR("%s: Error allocating memory for bridge", plugin_name); goto cleanup_fail; } else { + char *br_name_dup = strdup(br_name); + if (br_name_dup == NULL) { + ERROR("%s: strdup() copy bridge name fail", plugin_name); + goto cleanup_fail; + } + pthread_mutex_lock(&g_stats_lock); /* store bridge name */ - bridge->name = br_name; + bridge->name = br_name_dup; bridge->next = g_monitored_bridge_list_head; g_monitored_bridge_list_head = bridge; pthread_mutex_unlock(&g_stats_lock); diff --git a/src/postgresql_default.conf b/src/postgresql_default.conf index 0aac41e2..50799013 100644 --- a/src/postgresql_default.conf +++ b/src/postgresql_default.conf @@ -38,9 +38,9 @@ - Statement "SELECT sum(n_tup_ins) AS ins, \ - sum(n_tup_upd) AS upd, \ - sum(n_tup_del) AS del \ + Statement "SELECT coalesce(sum(n_tup_ins), 0) AS ins, \ + coalesce(sum(n_tup_upd), 0) AS upd, \ + coalesce(sum(n_tup_del), 0) AS del \ FROM pg_stat_user_tables;" @@ -63,10 +63,10 @@ - Statement "SELECT sum(n_tup_ins) AS ins, \ - sum(n_tup_upd) AS upd, \ - sum(n_tup_del) AS del, \ - sum(n_tup_hot_upd) AS hot_upd \ + Statement "SELECT coalesce(sum(n_tup_ins), 0) AS ins, \ + coalesce(sum(n_tup_upd), 0) AS upd, \ + coalesce(sum(n_tup_del), 0) AS del, \ + coalesce(sum(n_tup_hot_upd), 0) AS hot_upd \ FROM pg_stat_user_tables;" @@ -188,7 +188,8 @@ - Statement "SELECT sum(n_live_tup) AS live, sum(n_dead_tup) AS dead \ + Statement "SELECT coalesce(sum(n_live_tup), 0) AS live, \ + coalesce(sum(n_dead_tup), 0) AS dead \ FROM pg_stat_user_tables;" diff --git a/src/processes.c b/src/processes.c index 339c4d1e..30c4954a 100644 --- a/src/processes.c +++ b/src/processes.c @@ -502,7 +502,7 @@ static void ps_list_add(const char *name, const char *cmdline, ps_update_counter(&ps->io_diskw, &pse->io_diskw, entry->io_diskw); } - if ((entry->cswitch_vol != -1) && (entry->cswitch_vol != -1)) { + if ((entry->cswitch_vol != -1) && (entry->cswitch_invol != -1)) { ps_update_counter(&ps->cswitch_vol, &pse->cswitch_vol, entry->cswitch_vol); ps_update_counter(&ps->cswitch_invol, &pse->cswitch_invol, diff --git a/src/snmp.c b/src/snmp.c index 0a20e34b..8cb866d3 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1432,8 +1432,12 @@ static int csnmp_read_table(host_definition_t *host, data_definition_t *data) { for (vb = res->variables, i = 0; (vb != NULL); vb = vb->next_variable, i++) { /* Calculate value index from todo list */ - while ((i < oid_list_len) && !oid_list_todo[i]) + while ((i < oid_list_len) && !oid_list_todo[i]) { i++; + } + if (i >= oid_list_len) { + break; + } /* An instance is configured and the res variable we process is the * instance value (last index) */ diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 497d157c..948107b5 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -1117,12 +1117,6 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { } } - llentry_t *entry = llentry_create(td->name, td); - if (entry == NULL) { - snmp_agent_free_table(&td); - return -ENOMEM; - } - td->instance_index = c_avl_create((int (*)(const void *, const void *))strcmp); if (td->instance_index == NULL) { @@ -1137,6 +1131,11 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { return -ENOMEM; } + llentry_t *entry = llentry_create(td->name, td); + if (entry == NULL) { + snmp_agent_free_table(&td); + return -ENOMEM; + } llist_append(g_agent->tables, entry); return 0; diff --git a/src/target_notification.c b/src/target_notification.c index 429e256d..f83a904a 100644 --- a/src/target_notification.c +++ b/src/target_notification.c @@ -221,7 +221,9 @@ static int tn_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */ char template[DATA_MAX_NAME_LEN]; char value_str[DATA_MAX_NAME_LEN]; - snprintf(template, sizeof(template), "%%{ds:%s}", ds->ds[i].name); + const char *format = "%%{ds:%.*s}"; + snprintf(template, sizeof(template), format, + DATA_MAX_NAME_LEN - strlen(format), ds->ds[i].name); if (ds->ds[i].type != DS_TYPE_GAUGE) { if ((rates == NULL) && (rates_failed == 0)) { diff --git a/src/utils_ovs.c b/src/utils_ovs.c index 9bca398d..5a8090e3 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -263,12 +263,11 @@ static void ovs_db_callback_remove(ovs_db_t *pdb, ovs_callback_t *del_cb) { /* Remove all callbacks form OVS DB object */ static void ovs_db_callback_remove_all(ovs_db_t *pdb) { pthread_mutex_lock(&pdb->mutex); - for (ovs_callback_t *del_cb = pdb->remote_cb; pdb->remote_cb; - del_cb = pdb->remote_cb) { + while (pdb->remote_cb != NULL) { + ovs_callback_t *del_cb = pdb->remote_cb; pdb->remote_cb = del_cb->next; - free(del_cb); + sfree(del_cb); } - pdb->remote_cb = NULL; pthread_mutex_unlock(&pdb->mutex); } @@ -896,7 +895,7 @@ static void *ovs_event_worker(void *arg) { /* Initialize EVENT thread */ static int ovs_db_event_thread_init(ovs_db_t *pdb) { - pdb->event_thread.tid = (pthread_t)-1; + pdb->event_thread.tid = (pthread_t){0}; /* init event thread condition variable */ if (pthread_cond_init(&pdb->event_thread.cond, NULL)) { return -1; @@ -929,10 +928,12 @@ static int ovs_db_event_thread_init(ovs_db_t *pdb) { } /* Destroy EVENT thread */ +/* XXX: Must hold pdb->mutex when calling! */ static int ovs_db_event_thread_destroy(ovs_db_t *pdb) { - if (pdb->event_thread.tid == (pthread_t)-1) + if (pthread_equal(pdb->event_thread.tid, (pthread_t){0})) { /* already destroyed */ return 0; + } ovs_db_event_post(pdb, OVS_DB_EVENT_TERMINATE); if (pthread_join(pdb->event_thread.tid, NULL) != 0) return -1; @@ -943,13 +944,13 @@ static int ovs_db_event_thread_destroy(ovs_db_t *pdb) { pthread_mutex_unlock(&pdb->event_thread.mutex); pthread_mutex_destroy(&pdb->event_thread.mutex); pthread_cond_destroy(&pdb->event_thread.cond); - pdb->event_thread.tid = (pthread_t)-1; + pdb->event_thread.tid = (pthread_t){0}; return 0; } /* Initialize POLL thread */ static int ovs_db_poll_thread_init(ovs_db_t *pdb) { - pdb->poll_thread.tid = (pthread_t)-1; + pdb->poll_thread.tid = (pthread_t){0}; /* init event thread mutex */ if (pthread_mutex_init(&pdb->poll_thread.mutex, NULL)) { return -1; @@ -967,10 +968,12 @@ static int ovs_db_poll_thread_init(ovs_db_t *pdb) { } /* Destroy POLL thread */ +/* XXX: Must hold pdb->mutex when calling! */ static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) { - if (pdb->poll_thread.tid == (pthread_t)-1) + if (pthread_equal(pdb->poll_thread.tid, (pthread_t){0})) { /* already destroyed */ return 0; + } /* change thread state */ pthread_mutex_lock(&pdb->poll_thread.mutex); pdb->poll_thread.state = OVS_DB_POLL_STATE_EXITING; @@ -979,7 +982,7 @@ static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) { if (pthread_join(pdb->poll_thread.tid, NULL) != 0) return -1; pthread_mutex_destroy(&pdb->poll_thread.mutex); - pdb->poll_thread.tid = (pthread_t)-1; + pdb->poll_thread.tid = (pthread_t){0}; return 0; } @@ -1253,15 +1256,17 @@ int ovs_db_destroy(ovs_db_t *pdb) { /* stop poll thread */ if (ovs_db_event_thread_destroy(pdb) < 0) { OVS_ERROR("destroy poll thread failed"); - ovs_db_ret = (-1); + ovs_db_ret = -1; } /* stop event thread */ if (ovs_db_poll_thread_destroy(pdb) < 0) { OVS_ERROR("stop event thread failed"); - ovs_db_ret = (-1); + ovs_db_ret = -1; } + pthread_mutex_unlock(&pdb->mutex); + /* unsubscribe callbacks */ ovs_db_callback_remove_all(pdb); @@ -1270,7 +1275,6 @@ int ovs_db_destroy(ovs_db_t *pdb) { close(pdb->sock); /* release DB handler */ - pthread_mutex_unlock(&pdb->mutex); pthread_mutex_destroy(&pdb->mutex); sfree(pdb); return ovs_db_ret; diff --git a/src/utils_tail_match.c b/src/utils_tail_match.c index 65655dcd..79868fcd 100644 --- a/src/utils_tail_match.c +++ b/src/utils_tail_match.c @@ -118,7 +118,7 @@ static int latency_submit_match(cu_match_t *match, void *user_data) { sstrncpy(vl.type, data->type, sizeof(vl.type)); for (size_t i = 0; i < data->latency_config.percentile_num; i++) { if (strlen(data->type_instance) != 0) - snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%.0f", + snprintf(vl.type_instance, sizeof(vl.type_instance), "%.117s-%.2f", data->type_instance, data->latency_config.percentile[i]); else snprintf(vl.type_instance, sizeof(vl.type_instance), "%.0f", @@ -150,10 +150,11 @@ static int latency_submit_match(cu_match_t *match, void *user_data) { bucket.upper_bound ? CDTIME_T_TO_DOUBLE(bucket.upper_bound) : INFINITY; if (strlen(data->type_instance) != 0) - snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g", - data->type, data->type_instance, lower_bound, upper_bound); + snprintf(vl.type_instance, sizeof(vl.type_instance), + "%.54s-%.54s-%.2g_%.2g", data->type, data->type_instance, + lower_bound, upper_bound); else - snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g", + snprintf(vl.type_instance, sizeof(vl.type_instance), "%.107s-%.2g_%.2g", data->type, lower_bound, upper_bound); vl.values = &(value_t){ diff --git a/src/varnish.c b/src/varnish.c index e4daf4bf..08260dc2 100644 --- a/src/varnish.c +++ b/src/varnish.c @@ -29,7 +29,7 @@ #include "common.h" #include "plugin.h" -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 #include #include typedef struct VSC_C_main c_varnish_stats_t; @@ -71,17 +71,17 @@ struct user_config_s { #if HAVE_VARNISH_V2 _Bool collect_sm; #endif -#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 _Bool collect_sma; #endif _Bool collect_struct; _Bool collect_totals; -#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 _Bool collect_uptime; #endif _Bool collect_vcl; _Bool collect_workers; -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 _Bool collect_vsm; _Bool collect_lck; _Bool collect_mempool; @@ -138,13 +138,12 @@ static int varnish_submit_derive(const char *plugin_instance, /* {{{ */ }); } /* }}} int varnish_submit_derive */ -#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 static int varnish_monitor(void *priv, const struct VSC_point *const pt) /* {{{ */ { uint64_t val; const user_config_t *conf; - const char *class; const char *name; if (pt == NULL) @@ -152,19 +151,26 @@ static int varnish_monitor(void *priv, conf = priv; -#if HAVE_VARNISH_V4 - class = pt->section->fantom->type; - name = pt->desc->name; +#if HAVE_VARNISH_V5 + char namebuff[DATA_MAX_NAME_LEN]; + + char const *c = strrchr(pt->name, '.'); + if (c == NULL) { + return EINVAL; + } + sstrncpy(namebuff, c + 1, sizeof(namebuff)); + name = namebuff; - if (strcmp(class, "MAIN") != 0) +#elif HAVE_VARNISH_V4 + if (strcmp(pt->section->fantom->type, "MAIN") != 0) return 0; + name = pt->desc->name; #elif HAVE_VARNISH_V3 - class = pt->class; - name = pt->name; - - if (strcmp(class, "") != 0) + if (strcmp(pt->class, "") != 0) return 0; + + name = pt->name; #endif val = *(const volatile uint64_t *)pt->ptr; @@ -191,7 +197,7 @@ static int varnish_monitor(void *priv, else if (strcmp(name, "client_req") == 0) return varnish_submit_derive(conf->instance, "connections", "connections", "received", val); -#ifdef HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 else if (strcmp(name, "client_req_400") == 0) return varnish_submit_derive(conf->instance, "connections", "connections", "error_400", val); @@ -306,7 +312,7 @@ static int varnish_monitor(void *priv, else if (strcmp(name, "fetch_304") == 0) return varnish_submit_derive(conf->instance, "fetch", "http_requests", "no_body_304", val); -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 else if (strcmp(name, "fetch_no_thread") == 0) return varnish_submit_derive(conf->instance, "fetch", "http_requests", "no_thread", val); @@ -365,7 +371,7 @@ static int varnish_monitor(void *priv, else if (strcmp(name, "n_objoverflow") == 0) return varnish_submit_derive(conf->instance, "objects", "total_objects", "workspace_overflow", val); -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 else if (strcmp(name, "exp_mailed") == 0) return varnish_submit_gauge(conf->instance, "struct", "objects", "exp_mailed", val); @@ -397,7 +403,7 @@ static int varnish_monitor(void *priv, "duplicate", val); } #endif -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 if (conf->collect_ban) { if (strcmp(name, "bans") == 0) return varnish_submit_derive(conf->instance, "ban", "total_operations", @@ -450,7 +456,6 @@ static int varnish_monitor(void *priv, else if (strcmp(name, "bans_tests_tested") == 0) return varnish_submit_derive(conf->instance, "ban", "total_operations", "tests_tested", val); - } #endif @@ -485,13 +490,14 @@ static int varnish_monitor(void *priv, else if (strcmp(name, "sess_herd") == 0) return varnish_submit_derive(conf->instance, "session", "total_operations", "herd", val); -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 else if (strcmp(name, "sess_closed_err") == 0) return varnish_submit_derive(conf->instance, "session", "total_operations", "closed_err", val); else if (strcmp(name, "sess_dropped") == 0) return varnish_submit_derive(conf->instance, "session", - "total_operations", "dropped_for_thread", val); + "total_operations", "dropped_for_thread", + val); #endif } @@ -669,7 +675,7 @@ static int varnish_monitor(void *priv, "dropped", val); else if (strcmp(name, "thread_queue_len") == 0) return varnish_submit_gauge(conf->instance, "workers", "queue_length", - "threads", val); + "threads", val); else if (strcmp(name, "n_wrk") == 0) return varnish_submit_gauge(conf->instance, "workers", "threads", "worker", val); @@ -697,17 +703,17 @@ static int varnish_monitor(void *priv, else if (strcmp(name, "n_wrk_lqueue") == 0) return varnish_submit_derive(conf->instance, "workers", "total_requests", "queue_length", val); -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 else if (strcmp(name, "pools") == 0) - return varnish_submit_gauge(conf->instance, "workers", "pools", - "pools", val); + return varnish_submit_gauge(conf->instance, "workers", "pools", "pools", + val); else if (strcmp(name, "busy_killed") == 0) return varnish_submit_derive(conf->instance, "workers", "http_requests", "busy_killed", val); #endif } -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 if (conf->collect_vsm) { if (strcmp(name, "vsm_free") == 0) return varnish_submit_gauge(conf->instance, "vsm", "bytes", "free", val); @@ -731,38 +737,38 @@ static int varnish_monitor(void *priv, "bitmap", "happy_hprobes", val); */ if (strcmp(name, "bereq_hdrbytes") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "bereq_hdrbytes", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "bereq_hdrbytes", val); else if (strcmp(name, "bereq_bodybytes") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "bereq_bodybytes", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "bereq_bodybytes", val); else if (strcmp(name, "bereq_protobytes") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "bereq_protobytes", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "bereq_protobytes", val); else if (strcmp(name, "beresp_hdrbytes") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "beresp_hdrbytes", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "beresp_hdrbytes", val); else if (strcmp(name, "beresp_bodybytes") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "beresp_bodybytes", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "beresp_bodybytes", val); else if (strcmp(name, "beresp_protobytes") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "beresp_protobytes", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "beresp_protobytes", val); else if (strcmp(name, "pipe_hdrbytes") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "pipe_hdrbytes", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "pipe_hdrbytes", val); else if (strcmp(name, "pipe_out") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "pipe_out", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "pipe_out", val); else if (strcmp(name, "pipe_in") == 0) - return varnish_submit_derive(conf->instance, "vbe", - "total_bytes", "pipe_in", val); + return varnish_submit_derive(conf->instance, "vbe", "total_bytes", + "pipe_in", val); else if (strcmp(name, "conn") == 0) return varnish_submit_derive(conf->instance, "vbe", "connections", - "c_conns", val); + "c_conns", val); else if (strcmp(name, "req") == 0) return varnish_submit_derive(conf->instance, "vbe", "http_requests", - "b_reqs", val); + "b_reqs", val); } /* All Stevedores support these counters */ @@ -777,20 +783,20 @@ static int varnish_monitor(void *priv, strncpy(category, "mse", 4); if (strcmp(name, "c_req") == 0) - return varnish_submit_derive(conf->instance, category, - "total_operations", "alloc_req", val); + return varnish_submit_derive(conf->instance, category, "total_operations", + "alloc_req", val); else if (strcmp(name, "c_fail") == 0) - return varnish_submit_derive(conf->instance, category, - "total_operations", "alloc_fail", val); + return varnish_submit_derive(conf->instance, category, "total_operations", + "alloc_fail", val); else if (strcmp(name, "c_bytes") == 0) - return varnish_submit_derive(conf->instance, category, - "total_bytes", "bytes_allocated", val); + return varnish_submit_derive(conf->instance, category, "total_bytes", + "bytes_allocated", val); else if (strcmp(name, "c_freed") == 0) - return varnish_submit_derive(conf->instance, category, - "total_bytes", "bytes_freed", val); + return varnish_submit_derive(conf->instance, category, "total_bytes", + "bytes_freed", val); else if (strcmp(name, "g_alloc") == 0) - return varnish_submit_derive(conf->instance, category, - "total_operations", "alloc_outstanding", val); + return varnish_submit_derive(conf->instance, category, "total_operations", + "alloc_outstanding", val); else if (strcmp(name, "g_bytes") == 0) return varnish_submit_gauge(conf->instance, category, "bytes", "bytes_outstanding", val); @@ -803,14 +809,14 @@ static int varnish_monitor(void *priv, if (conf->collect_smf) { if (strcmp(name, "g_smf") == 0) - return varnish_submit_gauge(conf->instance, "smf", "objects", - "n_struct_smf", val); - else if (strcmp(name, "g_smf_frag") == 0) - return varnish_submit_gauge(conf->instance, "smf", "objects", - "n_small_free_smf", val); - else if (strcmp(name, "g_smf_large") == 0) - return varnish_submit_gauge(conf->instance, "smf", "objects", - "n_large_free_smf", val); + return varnish_submit_gauge(conf->instance, "smf", "objects", + "n_struct_smf", val); + else if (strcmp(name, "g_smf_frag") == 0) + return varnish_submit_gauge(conf->instance, "smf", "objects", + "n_small_free_smf", val); + else if (strcmp(name, "g_smf_large") == 0) + return varnish_submit_gauge(conf->instance, "smf", "objects", + "n_large_free_smf", val); } if (conf->collect_mgt) { @@ -818,35 +824,35 @@ static int varnish_monitor(void *priv, return varnish_submit_gauge(conf->instance, "mgt", "uptime", "mgt_proc_uptime", val); else if (strcmp(name, "child_start") == 0) - return varnish_submit_derive(conf->instance, "mgt", - "total_operations", "child_start", val); + return varnish_submit_derive(conf->instance, "mgt", "total_operations", + "child_start", val); else if (strcmp(name, "child_exit") == 0) - return varnish_submit_derive(conf->instance, "mgt", - "total_operations", "child_exit", val); + return varnish_submit_derive(conf->instance, "mgt", "total_operations", + "child_exit", val); else if (strcmp(name, "child_stop") == 0) - return varnish_submit_derive(conf->instance, "mgt", - "total_operations", "child_stop", val); + return varnish_submit_derive(conf->instance, "mgt", "total_operations", + "child_stop", val); else if (strcmp(name, "child_died") == 0) - return varnish_submit_derive(conf->instance, "mgt", - "total_operations", "child_died", val); + return varnish_submit_derive(conf->instance, "mgt", "total_operations", + "child_died", val); else if (strcmp(name, "child_dump") == 0) - return varnish_submit_derive(conf->instance, "mgt", - "total_operations", "child_dump", val); + return varnish_submit_derive(conf->instance, "mgt", "total_operations", + "child_dump", val); else if (strcmp(name, "child_panic") == 0) - return varnish_submit_derive(conf->instance, "mgt", - "total_operations", "child_panic", val); + return varnish_submit_derive(conf->instance, "mgt", "total_operations", + "child_panic", val); } if (conf->collect_lck) { if (strcmp(name, "creat") == 0) - return varnish_submit_gauge(conf->instance, "lck", "objects", - "created", val); + return varnish_submit_gauge(conf->instance, "lck", "objects", "created", + val); else if (strcmp(name, "destroy") == 0) - return varnish_submit_gauge(conf->instance, "lck", "objects", - "destroyed", val); + return varnish_submit_gauge(conf->instance, "lck", "objects", "destroyed", + val); else if (strcmp(name, "locks") == 0) return varnish_submit_derive(conf->instance, "lck", "total_operations", - "lock_ops", val); + "lock_ops", val); } if (conf->collect_mempool) { @@ -869,112 +875,111 @@ static int varnish_monitor(void *priv, return varnish_submit_derive(conf->instance, "mempool", "total_operations", "frees", val); else if (strcmp(name, "recycle") == 0) - return varnish_submit_gauge(conf->instance, "mempool", - "objects", "recycled", val); + return varnish_submit_gauge(conf->instance, "mempool", "objects", + "recycled", val); else if (strcmp(name, "timeout") == 0) - return varnish_submit_gauge(conf->instance, "mempool", - "objects", "timed_out", val); + return varnish_submit_gauge(conf->instance, "mempool", "objects", + "timed_out", val); else if (strcmp(name, "toosmall") == 0) - return varnish_submit_gauge(conf->instance, "mempool", - "objects", "too_small", val); + return varnish_submit_gauge(conf->instance, "mempool", "objects", + "too_small", val); else if (strcmp(name, "surplus") == 0) - return varnish_submit_gauge(conf->instance, "mempool", - "objects", "surplus", val); + return varnish_submit_gauge(conf->instance, "mempool", "objects", + "surplus", val); else if (strcmp(name, "randry") == 0) - return varnish_submit_gauge(conf->instance, "mempool", - "objects", "ran_dry", val); + return varnish_submit_gauge(conf->instance, "mempool", "objects", + "ran_dry", val); } if (conf->collect_mse) { if (strcmp(name, "c_full") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_operations", "full_allocs", val); + return varnish_submit_derive(conf->instance, "mse", "total_operations", + "full_allocs", val); else if (strcmp(name, "c_truncated") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_operations", "truncated_allocs", val); + return varnish_submit_derive(conf->instance, "mse", "total_operations", + "truncated_allocs", val); else if (strcmp(name, "c_expanded") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_operations", "expanded_allocs", val); + return varnish_submit_derive(conf->instance, "mse", "total_operations", + "expanded_allocs", val); else if (strcmp(name, "c_failed") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_operations", "failed_allocs", val); + return varnish_submit_derive(conf->instance, "mse", "total_operations", + "failed_allocs", val); else if (strcmp(name, "c_bytes") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_bytes", "bytes_allocated", val); + return varnish_submit_derive(conf->instance, "mse", "total_bytes", + "bytes_allocated", val); else if (strcmp(name, "c_freed") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_bytes", "bytes_freed", val); + return varnish_submit_derive(conf->instance, "mse", "total_bytes", + "bytes_freed", val); else if (strcmp(name, "g_fo_alloc") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_operations", "fo_allocs_outstanding", val); + return varnish_submit_derive(conf->instance, "mse", "total_operations", + "fo_allocs_outstanding", val); else if (strcmp(name, "g_fo_bytes") == 0) - return varnish_submit_gauge(conf->instance, "mse", - "bytes", "fo_bytes_outstanding", val); + return varnish_submit_gauge(conf->instance, "mse", "bytes", + "fo_bytes_outstanding", val); else if (strcmp(name, "g_membuf_alloc") == 0) - return varnish_submit_gauge(conf->instance, "mse", - "objects", "membufs_allocated", val); + return varnish_submit_gauge(conf->instance, "mse", "objects", + "membufs_allocated", val); else if (strcmp(name, "g_membuf_inuse") == 0) - return varnish_submit_gauge(conf->instance, "mse", - "objects", "membufs_inuse", val); + return varnish_submit_gauge(conf->instance, "mse", "objects", + "membufs_inuse", val); else if (strcmp(name, "g_bans_bytes") == 0) - return varnish_submit_gauge(conf->instance, "mse", - "bytes", "persisted_banspace_used", val); + return varnish_submit_gauge(conf->instance, "mse", "bytes", + "persisted_banspace_used", val); else if (strcmp(name, "g_bans_space") == 0) - return varnish_submit_gauge(conf->instance, "mse", - "bytes", "persisted_banspace_available", val); + return varnish_submit_gauge(conf->instance, "mse", "bytes", + "persisted_banspace_available", val); else if (strcmp(name, "g_bans_persisted") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_operations", "bans_persisted", val); + return varnish_submit_derive(conf->instance, "mse", "total_operations", + "bans_persisted", val); else if (strcmp(name, "g_bans_lost") == 0) - return varnish_submit_derive(conf->instance, "mse", - "total_operations", "bans_lost", val); + return varnish_submit_derive(conf->instance, "mse", "total_operations", + "bans_lost", val); - /* mse seg */ + /* mse seg */ else if (strcmp(name, "g_journal_bytes") == 0) - return varnish_submit_gauge(conf->instance, "mse_reg", - "bytes", "journal_bytes_used", val); + return varnish_submit_gauge(conf->instance, "mse_reg", "bytes", + "journal_bytes_used", val); else if (strcmp(name, "g_journal_space") == 0) - return varnish_submit_gauge(conf->instance, "mse_reg", - "bytes", "journal_bytes_free", val); + return varnish_submit_gauge(conf->instance, "mse_reg", "bytes", + "journal_bytes_free", val); /* mse segagg */ else if (strcmp(name, "g_bigspace") == 0) - return varnish_submit_gauge(conf->instance, "mse_segagg", - "bytes", "big_extents_bytes_available", val); + return varnish_submit_gauge(conf->instance, "mse_segagg", "bytes", + "big_extents_bytes_available", val); else if (strcmp(name, "g_extfree") == 0) - return varnish_submit_gauge(conf->instance, "mse_segagg", - "objects", "free_extents", val); + return varnish_submit_gauge(conf->instance, "mse_segagg", "objects", + "free_extents", val); else if (strcmp(name, "g_sparenode") == 0) - return varnish_submit_gauge(conf->instance, "mse_segagg", - "objects", "spare_nodes_available", val); + return varnish_submit_gauge(conf->instance, "mse_segagg", "objects", + "spare_nodes_available", val); else if (strcmp(name, "g_objnode") == 0) - return varnish_submit_gauge(conf->instance, "mse_segagg", - "objects", "object_nodes_in_use", val); + return varnish_submit_gauge(conf->instance, "mse_segagg", "objects", + "object_nodes_in_use", val); else if (strcmp(name, "g_extnode") == 0) - return varnish_submit_gauge(conf->instance, "mse_segagg", - "objects", "extent_nodes_in_use", val); + return varnish_submit_gauge(conf->instance, "mse_segagg", "objects", + "extent_nodes_in_use", val); else if (strcmp(name, "g_bigextfree") == 0) - return varnish_submit_gauge(conf->instance, "mse_segagg", - "objects", "free_big_extents", val); + return varnish_submit_gauge(conf->instance, "mse_segagg", "objects", + "free_big_extents", val); else if (strcmp(name, "c_pruneloop") == 0) return varnish_submit_derive(conf->instance, "mse_segagg", - "total_operations", "prune_loops", val); + "total_operations", "prune_loops", val); else if (strcmp(name, "c_pruned") == 0) return varnish_submit_derive(conf->instance, "mse_segagg", - "total_objects", "pruned_objects", val); + "total_objects", "pruned_objects", val); else if (strcmp(name, "c_spared") == 0) return varnish_submit_derive(conf->instance, "mse_segagg", - "total_operations", "spared_objects", val); + "total_operations", "spared_objects", val); else if (strcmp(name, "c_skipped") == 0) return varnish_submit_derive(conf->instance, "mse_segagg", - "total_operations", "missed_objects", val); + "total_operations", "missed_objects", val); else if (strcmp(name, "c_nuked") == 0) return varnish_submit_derive(conf->instance, "mse_segagg", - "total_operations", "nuked_objects", val); + "total_operations", "nuked_objects", val); else if (strcmp(name, "c_sniped") == 0) return varnish_submit_derive(conf->instance, "mse_segagg", - "total_operations", "sniped_objects", val); - + "total_operations", "sniped_objects", val); } #endif @@ -1321,12 +1326,18 @@ static void varnish_monitor(const user_config_t *conf, /* {{{ */ } /* }}} void varnish_monitor */ #endif -#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 static int varnish_read(user_data_t *ud) /* {{{ */ { +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 struct VSM_data *vd; - const c_varnish_stats_t *stats; _Bool ok; + const c_varnish_stats_t *stats; +#elif HAVE_VARNISH_V5 + struct vsm *vd; + struct vsc *vsc; + int vsm_status; +#endif user_config_t *conf; @@ -1336,6 +1347,11 @@ static int varnish_read(user_data_t *ud) /* {{{ */ conf = ud->data; vd = VSM_New(); + +#if HAVE_VARNISH_V5 + vsc = VSC_New(); +#endif + #if HAVE_VARNISH_V3 VSC_Setup(vd); #endif @@ -1343,10 +1359,20 @@ static int varnish_read(user_data_t *ud) /* {{{ */ if (conf->instance != NULL) { int status; +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 status = VSM_n_Arg(vd, conf->instance); +#elif HAVE_VARNISH_V5 + status = VSM_Arg(vd, 'n', conf->instance); +#endif + if (status < 0) { +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 VSM_Delete(vd); - ERROR("varnish plugin: VSM_n_Arg (\"%s\") failed " +#elif HAVE_VARNISH_V5 + VSC_Destroy(&vsc, vd); + VSM_Destroy(&vd); +#endif + ERROR("varnish plugin: VSM_Arg (\"%s\") failed " "with status %i.", conf->instance, status); return -1; @@ -1355,34 +1381,61 @@ static int varnish_read(user_data_t *ud) /* {{{ */ #if HAVE_VARNISH_V3 ok = (VSC_Open(vd, /* diag = */ 1) == 0); -#else /* if HAVE_VARNISH_V4 */ +#elif HAVE_VARNISH_V4 ok = (VSM_Open(vd) == 0); #endif +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 if (!ok) { VSM_Delete(vd); ERROR("varnish plugin: Unable to open connection."); - return -1; } +#endif #if HAVE_VARNISH_V3 stats = VSC_Main(vd); -#else /* if HAVE_VARNISH_V4 */ +#elif HAVE_VARNISH_V4 stats = VSC_Main(vd, NULL); #endif +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 if (!stats) { VSM_Delete(vd); ERROR("varnish plugin: Unable to get statistics."); + return -1; + } +#endif + +#if HAVE_VARNISH_V5 + if (VSM_Attach(vd, STDERR_FILENO)) { + ERROR("varnish plugin: Cannot attach to varnish. %s", VSM_Error(vd)); + VSC_Destroy(&vsc, vd); + VSM_Destroy(&vd); + return -1; + } + vsm_status = VSM_Status(vd); + if (vsm_status & ~(VSM_MGT_RUNNING | VSM_WRK_RUNNING)) { + ERROR("varnish plugin: Unable to get statistics."); + VSC_Destroy(&vsc, vd); + VSM_Destroy(&vd); return -1; } +#endif #if HAVE_VARNISH_V3 VSC_Iter(vd, varnish_monitor, conf); -#else /* if HAVE_VARNISH_V4 */ +#elif HAVE_VARNISH_V4 VSC_Iter(vd, NULL, varnish_monitor, conf); +#elif HAVE_VARNISH_V5 + VSC_Iter(vsc, vd, varnish_monitor, conf); #endif + +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 VSM_Delete(vd); +#elif HAVE_VARNISH_V5 + VSC_Destroy(&vsc, vd); + VSM_Destroy(&vd); +#endif return 0; } /* }}} */ @@ -1447,18 +1500,18 @@ static int varnish_config_apply_default(user_config_t *conf) /* {{{ */ #if HAVE_VARNISH_V2 conf->collect_sm = 0; #endif -#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 conf->collect_sma = 0; #endif conf->collect_sms = 0; conf->collect_struct = 0; conf->collect_totals = 0; -#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 conf->collect_uptime = 0; #endif conf->collect_vcl = 0; conf->collect_workers = 0; -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 conf->collect_vsm = 0; conf->collect_lck = 0; conf->collect_mempool = 0; @@ -1577,7 +1630,7 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ else if (strcasecmp("CollectSMS", child->key) == 0) cf_util_get_boolean(child, &conf->collect_sms); else if (strcasecmp("CollectSMA", child->key) == 0) -#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_sma); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", @@ -1595,7 +1648,7 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ else if (strcasecmp("CollectTotals", child->key) == 0) cf_util_get_boolean(child, &conf->collect_totals); else if (strcasecmp("CollectUptime", child->key) == 0) -#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_uptime); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", @@ -1606,56 +1659,56 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ else if (strcasecmp("CollectWorkers", child->key) == 0) cf_util_get_boolean(child, &conf->collect_workers); else if (strcasecmp("CollectVSM", child->key) == 0) -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_vsm); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v4"); #endif else if (strcasecmp("CollectLock", child->key) == 0) -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_lck); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v4"); #endif else if (strcasecmp("CollectMempool", child->key) == 0) -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_mempool); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v4"); #endif else if (strcasecmp("CollectManagement", child->key) == 0) -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_mgt); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v4"); #endif else if (strcasecmp("CollectSMF", child->key) == 0) -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_smf); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v4"); #endif else if (strcasecmp("CollectSMF", child->key) == 0) -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_smf); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v4"); #endif else if (strcasecmp("CollectVBE", child->key) == 0) -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_vbe); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", child->key, "v4"); #endif else if (strcasecmp("CollectMSE", child->key) == 0) -#if HAVE_VARNISH_V4 +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 cf_util_get_boolean(child, &conf->collect_mse); #else WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.", @@ -1685,18 +1738,18 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ #if HAVE_VARNISH_V2 && !conf->collect_sm #endif -#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 && !conf->collect_sma #endif && !conf->collect_struct && !conf->collect_totals -#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 +#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5 && !conf->collect_uptime #endif && !conf->collect_vcl && !conf->collect_workers -#if HAVE_VARNISH_V4 - && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf - && !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool - && !conf->collect_mse +#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5 + && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf && + !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool && + !conf->collect_mse #endif ) { WARNING("Varnish plugin: No metric has been configured for " diff --git a/src/write_riemann.c b/src/write_riemann.c index 6db3ef58..86f0c1fa 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -610,6 +610,7 @@ static void wrr_free(void *p) /* {{{ */ wrr_disconnect(host); + pthread_mutex_lock(&host->lock); pthread_mutex_destroy(&host->lock); sfree(host); } /* }}} void wrr_free */ diff --git a/src/zfs_arc.c b/src/zfs_arc.c index 8f3b1b4b..af4bfccb 100644 --- a/src/zfs_arc.c +++ b/src/zfs_arc.c @@ -207,26 +207,21 @@ static int za_read(void) { return -1; } - ksp = llist_create(); - if (ksp == NULL) { - ERROR("zfs_arc plugin: `llist_create' failed."); - fclose(fh); - return -1; - } - - // Ignore the first two lines because they contain information about - // the rest of the file. - // See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel - // module. - if (fgets(buffer, sizeof(buffer), fh) == NULL) { - ERROR("zfs_arc plugin: \"%s\" does not contain a single line.", + /* Ignore the first two lines because they contain information about the rest + * of the file. + * See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel module. + */ + if ((fgets(buffer, sizeof(buffer), fh) == NULL) || + (fgets(buffer, sizeof(buffer), fh) == NULL)) { + ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.", ZOL_ARCSTATS_FILE); fclose(fh); return -1; } - if (fgets(buffer, sizeof(buffer), fh) == NULL) { - ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.", - ZOL_ARCSTATS_FILE); + + ksp = llist_create(); + if (ksp == NULL) { + ERROR("zfs_arc plugin: `llist_create' failed."); fclose(fh); return -1; }