From: Tahhan, Maryam Date: Mon, 27 Feb 2017 13:33:31 +0000 (+0000) Subject: mcelog: notification persist option X-Git-Tag: collectd-5.8.0~109^2~5 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;ds=sidebyside;h=21234c8ef4fd418af7ab5477416dadf8e5ffc78a;p=collectd.git mcelog: notification persist option Implement notification persist option and separate out memory block from the rest of the configuration. Change-Id: I48d946bb381d3cfc61fee91a31f3865802389eef Signed-off-by: Tahhan, Maryam --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index e2d6aafa..a0bfc15c 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -720,8 +720,11 @@ # # -# McelogClientSocket "/var/run/mcelog-client" -# McelogLogfile "/var/log/mcelog" +# +# McelogClientSocket "/var/run/mcelog-client" +# PersistentNotification false +# +# McelogLogfile "/var/log/mcelog" # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 32020154..c1c94619 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -3475,12 +3475,24 @@ client protocol to retrieve memory related machine check exceptions. Note that for memory exceptions, notifications are only sent when there is a change in the number of corrected/uncorrected memory errors. -=over 4 +=head3 The Memory block + +=over 3 =item B I Connect to the mcelog client socket using the UNIX domain socket at I. Defaults to B<"/var/run/mcelog-client">. +=item B B|B +Override default configuration to only send notifications when sent when there +is a change in the number of corrected/uncorrected memory errors. When set to +true notifications will be sent for every read cycle. Default is false. Does +not affect the stats being dispatched. + +=back + +=over 4 + =item B I The mcelog file to parse. Defaults to B<"/var/log/mcelog">. diff --git a/src/mcelog.c b/src/mcelog.c index 654305d3..23040c81 100644 --- a/src/mcelog.c +++ b/src/mcelog.c @@ -2,7 +2,7 @@ * collectd - src/mcelog.c * MIT License * - * Copyright(c) 2016 Intel Corporation. All rights reserved. + * Copyright(c) 2016-2017 Intel Corporation. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -54,6 +54,7 @@ typedef struct mcelog_config_s { pthread_t tid; /* poll thread id */ llist_t *dimms_list; /* DIMMs list */ /* lock for dimms cache */ + _Bool persist; pthread_mutex_t dimms_lock; } mcelog_config_t; @@ -88,7 +89,7 @@ static int socket_reinit(socket_adapter_t *self); static int socket_receive(socket_adapter_t *self, FILE **p_file); static mcelog_config_t g_mcelog_config = { - .logfile = "/var/log/mcelog", + .logfile = "/var/log/mcelog", .persist = 0, }; static socket_adapter_t socket_adapter = { @@ -112,7 +113,6 @@ static void mcelog_free_dimms_list_records(llist_t *dimms_list) { sfree(e->key); sfree(e->value); } - } /* Create or get dimm by dimm name/location */ @@ -161,27 +161,42 @@ static void mcelog_update_dimm_stats(llentry_t *dimm, pthread_mutex_lock(&g_mcelog_config.dimms_lock); memcpy(dimm->value, rec, sizeof(mcelog_memory_rec_t)); pthread_mutex_unlock(&g_mcelog_config.dimms_lock); - } static int mcelog_config(oconfig_item_t *ci) { for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; - if (strcasecmp("McelogClientSocket", child->key) == 0) { - if (cf_util_get_string_buffer(child, socket_adapter.unix_sock.sun_path, - sizeof(socket_adapter.unix_sock.sun_path)) < - 0) { - ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".", - child->key); - return (-1); - } - } else if (strcasecmp("McelogLogfile", child->key) == 0) { + if (strcasecmp("McelogLogfile", child->key) == 0) { if (cf_util_get_string_buffer(child, g_mcelog_config.logfile, sizeof(g_mcelog_config.logfile)) < 0) { ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".", child->key); return (-1); } + } else if (strcasecmp("Memory", child->key) == 0) { + oconfig_item_t *mem_child = child->children; + for (int j = 0; j < child->children_num; j++) { + mem_child += j; + if (strcasecmp("McelogClientSocket", mem_child->key) == 0) { + if (cf_util_get_string_buffer( + mem_child, socket_adapter.unix_sock.sun_path, + sizeof(socket_adapter.unix_sock.sun_path)) < 0) { + ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".", + mem_child->key); + return (-1); + } + } else if (strcasecmp("PersistentNotification", mem_child->key) == 0) { + if (cf_util_get_boolean(mem_child, &g_mcelog_config.persist) < 0) { + ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".", + mem_child->key); + return (-1); + } + } else { + ERROR(MCELOG_PLUGIN ": Invalid Memory configuration option: \"%s\".", + mem_child->key); + return (-1); + } + } } else { ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".", child->key); @@ -292,23 +307,28 @@ static int mcelog_dispatch_mem_notifications(const mcelog_memory_rec_t *mr) { llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list); if (dimm == NULL) { - ERROR(MCELOG_PLUGIN ": Error adding/getting dimm memory item to/from cache"); - return -1; + ERROR(MCELOG_PLUGIN + ": Error adding/getting dimm memory item to/from cache"); + return (-1); } - mcelog_memory_rec_t *mr_old = dimm->value; + if (!g_mcelog_config.persist) { - if (mr_old->corrected_err_total != mr->corrected_err_total || - mr_old->corrected_err_timed != mr->corrected_err_timed) - dispatch_corrected_notifs = 1; + if (mr_old->corrected_err_total != mr->corrected_err_total || + mr_old->corrected_err_timed != mr->corrected_err_timed) + dispatch_corrected_notifs = 1; - if (mr_old->uncorrected_err_total != mr->uncorrected_err_total || - mr_old->uncorrected_err_timed != mr->uncorrected_err_timed) - dispatch_uncorrected_notifs = 1; + if (mr_old->uncorrected_err_total != mr->uncorrected_err_total || + mr_old->uncorrected_err_timed != mr->uncorrected_err_timed) + dispatch_uncorrected_notifs = 1; - if (!dispatch_corrected_notifs && !dispatch_uncorrected_notifs) { - DEBUG("%s: No new notifications to dispatch", MCELOG_PLUGIN); - return (0); + if (!dispatch_corrected_notifs && !dispatch_uncorrected_notifs) { + DEBUG("%s: No new notifications to dispatch", MCELOG_PLUGIN); + return (0); + } + } else { + dispatch_corrected_notifs = 1; + dispatch_uncorrected_notifs = 1; } sstrncpy(n.host, hostname_g, sizeof(n.host)); @@ -384,8 +404,9 @@ static int mcelog_submit(const mcelog_memory_rec_t *mr) { llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list); if (dimm == NULL) { - ERROR(MCELOG_PLUGIN ": Error adding/getting dimm memory item to/from cache"); - return -1; + ERROR(MCELOG_PLUGIN + ": Error adding/getting dimm memory item to/from cache"); + return (-1); } value_list_t vl = {