From 16e717ce90795ffb78ccbb9d0fba65521337a496 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Sat, 26 Jan 2019 01:01:12 +0100 Subject: [PATCH] F #2095 Send HUP to collectd-client TM=(SSH|LVM) (#2839) --- .../remotes/common.d/collectd-client.rb | 19 +++++++++++++++---- src/mad/sh/scripts_common.sh | 6 ++++++ src/tm_mad/common/delete | 2 +- src/tm_mad/common/mkimage | 1 + src/tm_mad/common/resize | 1 + src/tm_mad/fs_lvm/clone | 1 + src/tm_mad/fs_lvm/cpds | 1 + src/tm_mad/fs_lvm/delete | 2 ++ src/tm_mad/fs_lvm/mv | 3 +++ src/tm_mad/fs_lvm/mvds | 1 + src/tm_mad/ssh/clone | 1 + src/tm_mad/ssh/cpds | 1 + src/tm_mad/ssh/mv | 2 ++ src/tm_mad/ssh/mvds | 1 + src/tm_mad/ssh/snap_create | 1 + src/tm_mad/ssh/snap_delete | 1 + src/tm_mad/ssh/snap_revert | 1 + 17 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/im_mad/remotes/common.d/collectd-client.rb b/src/im_mad/remotes/common.d/collectd-client.rb index 9830aca97b..b2d218f35c 100644 --- a/src/im_mad/remotes/common.d/collectd-client.rb +++ b/src/im_mad/remotes/common.d/collectd-client.rb @@ -88,13 +88,12 @@ class CollectdClient # Collect the Data ts = Time.now - data = run_probes + + # Send signal to itself to run probes and send the data + Process.kill('HUP', $$) run_probes_time = (Time.now - ts).to_i - # Send the Data - send data - # Sleep during the Cycle sleep_time = @monitor_push_period - run_probes_time sleep_time = 0 if sleep_time < 0 @@ -130,4 +129,16 @@ sleep rand monitor_push_period # Start push monitorization client = CollectdClient.new(hypervisor, number, host, port, probes_args, monitor_push_period) + +Signal.trap('HUP') do + # ignore another HUP until we handle this one + this_handler = Signal.trap('HUP', 'IGNORE') + + data = client.run_probes + client.send data + + # set the handler back + Signal.trap('HUP', this_handler) +end + client.monitor diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index e44b7d5d75..1f540b323a 100644 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -994,3 +994,9 @@ function get_nic_information { OUTBOUND_PEAK_KB="${XPATH_ELEMENTS[j++]}" ORDER="${XPATH_ELEMENTS[j++]}" } + +function hup_collectd +{ + SEND_HUP='kill -HUP `cat /tmp/one-collectd-client.pid` || true' + ssh_exec_and_log_no_error $1 "$SEND_HUP" +} diff --git a/src/tm_mad/common/delete b/src/tm_mad/common/delete index 8f5888d64e..d8b00337b4 100755 --- a/src/tm_mad/common/delete +++ b/src/tm_mad/common/delete @@ -67,4 +67,4 @@ EOF ) ssh_exec_and_log $DST_HOST "$delete_file" "Error deleting $DST_PATH" - +hup_collectd $DST_HOST diff --git a/src/tm_mad/common/mkimage b/src/tm_mad/common/mkimage index 7129d9ec3a..7e153a6ff0 100755 --- a/src/tm_mad/common/mkimage +++ b/src/tm_mad/common/mkimage @@ -70,5 +70,6 @@ EOF log "Making filesystem of ${SIZE}M and type $FSTYPE at $DST" ssh_exec_and_log $DST_HOST "$MKSCRIPT" "Could not create image $DST_PATH" +hup_collectd $DST_HOST exit 0 diff --git a/src/tm_mad/common/resize b/src/tm_mad/common/resize index 896807bf37..8b7ac73ffb 100755 --- a/src/tm_mad/common/resize +++ b/src/tm_mad/common/resize @@ -43,3 +43,4 @@ fi ssh_exec_and_log "${SRC_HOST}" "qemu-img resize ${SRC_PATH} ${SIZE}M" \ "Error resizing image ${SRC_PATH}" +hup_collectd $SRC_HOST diff --git a/src/tm_mad/fs_lvm/clone b/src/tm_mad/fs_lvm/clone index afb50eafc3..af0e42db08 100755 --- a/src/tm_mad/fs_lvm/clone +++ b/src/tm_mad/fs_lvm/clone @@ -142,4 +142,5 @@ EOF ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" \ "Error cloning $SRC_PATH to $LV_NAME" +hup_collectd $DST_HOST exit 0 diff --git a/src/tm_mad/fs_lvm/cpds b/src/tm_mad/fs_lvm/cpds index e6791fd4b5..2730bd1d8c 100755 --- a/src/tm_mad/fs_lvm/cpds +++ b/src/tm_mad/fs_lvm/cpds @@ -66,5 +66,6 @@ log "Dumping $SRC to $DST" ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \ "Error dumping $SRC to $DST" +hup_collectd $SRC_HOST exit 0 diff --git a/src/tm_mad/fs_lvm/delete b/src/tm_mad/fs_lvm/delete index b2969d7ae7..13c12571db 100755 --- a/src/tm_mad/fs_lvm/delete +++ b/src/tm_mad/fs_lvm/delete @@ -84,3 +84,5 @@ else ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \ "Error deleting $DST_PATH" fi + +hup_collectd $DST_HOST diff --git a/src/tm_mad/fs_lvm/mv b/src/tm_mad/fs_lvm/mv index e7e9b0556e..3276be55eb 100755 --- a/src/tm_mad/fs_lvm/mv +++ b/src/tm_mad/fs_lvm/mv @@ -154,3 +154,6 @@ fi ssh_exec_and_log "$DST_HOST" "mv $SRC_PATH $DST_PATH" \ "Error moving VM files to another System DS: $SRC_PATH to $DST_PATH in $DST_HOST" + +hup_collectd $DST_HOST +hup_collectd $SRC_HOST diff --git a/src/tm_mad/fs_lvm/mvds b/src/tm_mad/fs_lvm/mvds index 627eca734e..e471e9d959 100755 --- a/src/tm_mad/fs_lvm/mvds +++ b/src/tm_mad/fs_lvm/mvds @@ -75,5 +75,6 @@ ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \ LOCK="tm-fs_lvm-${DS_SYS_ID}.lock" exclusive "${LOCK}" 120 ssh_exec_and_log "$SRC_HOST" "$DELETE_CMD" \ "Error dumping $SRC to $DST" +hup_collectd $SRC_HOST exit 0 diff --git a/src/tm_mad/ssh/clone b/src/tm_mad/ssh/clone index d84a2d0dd5..dc4beb1a43 100755 --- a/src/tm_mad/ssh/clone +++ b/src/tm_mad/ssh/clone @@ -93,3 +93,4 @@ if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then "Error resizing image $DST" fi +hup_collectd $DST_HOST diff --git a/src/tm_mad/ssh/cpds b/src/tm_mad/ssh/cpds index b58c772285..1896d758cb 100755 --- a/src/tm_mad/ssh/cpds +++ b/src/tm_mad/ssh/cpds @@ -120,5 +120,6 @@ fi log "Moving $SRC to datastore as $DST" exec_and_log "$SCP -r $SRC $DST" "Error copying $SRC to $DST" +hup_collectd $SRC_HOST exit 0 diff --git a/src/tm_mad/ssh/mv b/src/tm_mad/ssh/mv index be7253c1b0..859152eede 100755 --- a/src/tm_mad/ssh/mv +++ b/src/tm_mad/ssh/mv @@ -85,5 +85,7 @@ EOF ) ssh_exec_and_log "$SRC_HOST" "$TAR_SSH" "Error copying disk directory to target host" +hup_collectd $DST_HOST +hup_collectd $SRC_HOST exit 0 diff --git a/src/tm_mad/ssh/mvds b/src/tm_mad/ssh/mvds index ae3bdff892..88f97424f6 100755 --- a/src/tm_mad/ssh/mvds +++ b/src/tm_mad/ssh/mvds @@ -53,6 +53,7 @@ exec_and_log "$SCP -r $SRC $DST" "Error copying $SRC to $DST" if $SSH $SRC_HOST ls ${SRC_PATH_SNAP} >/dev/null 2>&1; then exec_and_log "rsync -r --delete ${SRC_HOST}:${SRC_PATH_SNAP}/ ${DST_SNAP}" + hup_collectd $SRC_HOST fi exit 0 diff --git a/src/tm_mad/ssh/snap_create b/src/tm_mad/ssh/snap_create index 4d58faafc7..97a9abde31 100755 --- a/src/tm_mad/ssh/snap_create +++ b/src/tm_mad/ssh/snap_create @@ -82,4 +82,5 @@ EOT ssh_exec_and_log "${SRC_HOST}" "${CMD}" \ "Error creating snapshot ${SNAP_PATH}" +hup_collectd $SRC_HOST diff --git a/src/tm_mad/ssh/snap_delete b/src/tm_mad/ssh/snap_delete index 931d976759..f57d539def 100755 --- a/src/tm_mad/ssh/snap_delete +++ b/src/tm_mad/ssh/snap_delete @@ -70,4 +70,5 @@ CURRENT_PATH=${DISK_PATH} ssh_exec_and_log "${SRC_HOST}" "rm ${SNAP_PATH}" \ "Error deleting snapshot ${SNAP_PATH}" +hup_collectd $SRC_HOST diff --git a/src/tm_mad/ssh/snap_revert b/src/tm_mad/ssh/snap_revert index 506f9e3e19..8ac296cdfb 100755 --- a/src/tm_mad/ssh/snap_revert +++ b/src/tm_mad/ssh/snap_revert @@ -77,4 +77,5 @@ EOF ssh_exec_and_log "${SRC_HOST}" "${CMD}" \ "Error reverting snapshot to ${SNAP_PATH}" +hup_collectd $SRC_HOST