summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-06-17 14:16:30 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-06-17 14:16:30 +0300
commitdf246405de7a4cf96c53b39e7af36ebe6e146559 (patch)
treebb45db6389f7eb69893b89acddb6b2d256cfdc10 /contrib
parentaebfee919c485c4d70b0d04518977c95e85f8a9b (diff)
nc-backend.sh uses tee to show the metrics on console
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/nc-backend.sh22
1 files changed, 16 insertions, 6 deletions
diff --git a/contrib/nc-backend.sh b/contrib/nc-backend.sh
index 2ad427fbb1..b5a89840e0 100755
--- a/contrib/nc-backend.sh
+++ b/contrib/nc-backend.sh
@@ -10,6 +10,18 @@ log() {
logger --stderr --id=$$ --tag "netdata-nc-backend" "${*}"
}
+mync() {
+ local ret
+
+ log "Running: nc ${*}"
+ nc "${@}"
+ ret=$?
+
+ log "nc stopped with return code ${ret}."
+
+ return ${ret}
+}
+
listen_save_replay_forever() {
local file="${1}" port="${2}" real_backend_host="${3}" real_backend_port="${4}" ret delay=1 started ended
@@ -18,19 +30,16 @@ listen_save_replay_forever() {
log "Starting nc to listen on port ${port} and save metrics to ${file}"
started=$(date +%s)
- nc -l "${port}" >>"${file}"
- ret=$?
+ mync -l "${port}" | tee -a -p --output-error=exit "${file}"
ended=$(date +%s)
- log "nc stopped with return code ${ret}."
-
if [ -s "${file}" ]
then
if [ ! -z "${real_backend_host}" -a ! -z "${real_backend_port}" ]
then
log "Attempting to send the metrics to the real backend at ${real_backend_host}:${real_backend_port}"
- nc "${real_backend_host}" "${real_backend_port}" <"${file}"
+ mync "${real_backend_host}" "${real_backend_port}" <"${file}"
ret=$?
if [ ${ret} -eq 0 ]
@@ -50,12 +59,13 @@ listen_save_replay_forever() {
# if nc cannot listen to port
if [ $((ended - started)) -lt 5 ]
then
- log "nc has been stopped too fast. Waiting 30 secs."
+ log "nc has been stopped too fast."
delay=30
else
delay=1
fi
+ log "Waiting ${delay} seconds before listening again for data."
sleep ${delay}
done
}