COSM MQTT subscribe does not get latest update value - cosm

I expect mosquitto_sub should got the latest value sent from mosquitto_pub.
But seems it is not true, subscribe always got the value before latest update one.
Here is my test steps:
I start mosquitto_sub first:
mosquitto_sub: got value 5 (last good known, it's ok)
Then use mosquitto_pub to send value and check mosquitto_sub side:
mosquitto_pub: send value 1
mosquitto_sub: still got value 5
mosquitto_pub: send value 2
mosquitto_sub: got value 1
mosquitto_pub: send value 3
mosquitto_sub: got value 2
mosquitto_pub: send value 4
mosquitto_sub: got value 3
Here is the commands to reproduce this issue:
(remember to change YOUR_API_KEY/YOUR_FEED_ID/YOUR_DATASTREAM to your setting)
The subscribe side:
$ mosquitto_sub -h api.cosm.com -t YOUR_API_KEY/v2/feeds/YOUR_FEED_ID/datastreams/YOUR_DATASTREAM.csv
The publish side:
$ for i in 0 1 2 3 4 5 6 7 8 9 10; do mosquitto_pub -h api.cosm.com -t YOUR_API_KEY/v2/feeds/YOUR_FEED_ID/datastreams/YOUR_DATASTREAM.csv -m "$i"; sleep 1; done
It's obviously the subscribe side does not show 10 0 1 2 3 4 5 6 7 8 9 10.
Below is what I got in my test:
2013-05-09T00:40:20.009034Z,10
2013-05-09T00:40:20.009034Z,10
2013-05-09T00:47:52.062114Z,1
2013-05-09T00:47:54.325130Z,2
2013-05-09T00:47:54.325130Z,2
2013-05-09T00:47:58.398895Z,4
2013-05-09T00:47:58.398895Z,4
2013-05-09T00:48:02.680777Z,6
2013-05-09T00:48:04.721811Z,7
2013-05-09T00:48:06.813412Z,8
2013-05-09T00:48:06.813412Z,8
2013-05-09T00:48:11.278083Z,10

This is probably best handled by mailing Cosm support, as it sounds like it could be some sort of issue at their end (probably something being cached when it shouldn't be)

Related

bash: arithmetic expressions inside of variables

I have a simple code to assign variables in loop based on simple ariphmetic equaltion
# assign initial value
restr_start='25'
# assign a new variable, which is a number that will decrease initial value by 5
# keeping always the value of previous variable as restr_prev
for step in {1..4}; do
let "restr=(${restr_start} - (5 * ${step}))"
let "restr_prev=(${restr} + (5 * ${step}))"
echo this is $restr current restart
echo this is $restr_prev previous restart
done
From this script I am expecting to have:
this is 20 current restart
this is 25 previous restart
this is 15 current restart
this is 20 previous restart
this is 10 current restart
this is 15 previous restart
this is 5 current restart
this is 10 previous restart
however what I actually do have
this is 20 current restart
this is 25 previous restart
this is 15 current restart
this is 25 previous restart
this is 10 current restart
this is 25 previous restart
this is 5 current restart
this is 25 previous restart
why $restr_prev is usually unchanged? how I could modify the code, e.g. using something instead of let?
This is rather a mathematical problem than an issue with your bash code. Look at the formula for $restr_prev:
restr_prev= ${restr} + (5 * ${step})
For step 1 the formula calculates to 20 + 5 * 1 = 25, for step 2 the formula leads to 15 + 5 * 2 = 25, and so on...
In order to get the results you're actually expecting, you simply need to add 5 to the restr value. Hence, the corresponding line in your script should look like this:
let "restr_prev=(${restr} + 5)"
As it was already suggested within the comments, you should use $((expression)) for arithmetic expansion instead of let since the latter is a bash builtin and not covered by the POSIX standard. Heeding the suggestions leads to the following code:
#!/bin/bash
# assign initial value
restr_start='25'
# assign a new variable, which is a number that will decrease initial value by 5
# keeping always the value of previous variable as restr_prev
for step in {1..4}; do
restr=$((restr_start - (5 * step)))
restr_prev=$((restr + 5))
echo "this is $restr current restart"
echo "this is $restr_prev previous restart"
done

Shell Scripting to compare the value of current iteration with that of the previous iteration

I have an infinite loop which uses aws cli to get the microservice names, it's parameters like desired tasks,number of running task etc for an environment.
There are 100's of microservices running in an environment. I have a requirement to compare the value of aws ecs metric running task for a particular microservice in the current loop and with that of the previous loop.
Say name a microservice X has the metric running task 5. As it is an infinite loop, after some time, again the loop come for the microservice X. Now, let's assume the value of running task is 4. I want to compare the running task for currnet loop, which is 4 with the value of the running task for the previous run, which is 5.
If you are asking a generic question of how to keep a previous value around so it can be compared to the current value, just store it in a variable. You can use the following as a starting point:
#!/bin/bash
previousValue=0
while read v; do
echo "Previous value=${previousValue}; Current value=${v}"
previousValue=${v}
done
exit 0
If the above script is called testval.sh. And you have an input file called test.in with the following values:
2
1
4
6
3
0
5
Then running
./testval.sh <test.in
will generate the following output:
Previous value=0; Current value=2
Previous value=2; Current value=1
Previous value=1; Current value=4
Previous value=4; Current value=6
Previous value=6; Current value=3
Previous value=3; Current value=0
Previous value=0; Current value=5
If the skeleton script works for you, feel free to modify it for however you need to do comparisons.
Hope this helps.
I dont know how your input looks exactly, but something like this might be useful for you :
The script
#!/bin/bash
declare -A app_stats
while read app tasks
do
if [[ ${app_stats[$app]} -ne $tasks && ! -z ${app_stats[$app]} ]]
then
echo "Number of tasks for $app has changed from ${app_stats[$app]} to $tasks"
app_stats[$app]=$tasks
else
app_stats[$app]=$tasks
fi
done <<< "$( cat input.txt)"
The input
App1 2
App2 5
App3 6
App1 6
The output
Number of tasks for App1 has changed from 2 to 6
Regards!

Is there a way of predefining input when running a shell?

When using a shell script file i want to be able to prewrite the input for the configuration.
how can i give the answers automatically?
there are multiple questions with short answers required for example- 'Please select an option: 1, 2 or 3' and provide answer 2. I considered using a heredoc but would this be the most appropriate option?
My example script:
./install.sh <<HERE
1
1
2
1
1 2 3
1 2
2
HERE
thanks for any help given.

net-snmp snmptrap sending samples

I'm new in SNMP and I just configured the agent and the manager and I'm
able to receive the traps sent by the agent. But I noticed that the traps
received by the manager are captured between 10 seconds, but I need to
receive the traps as soon as I generate them not between 10 sec.
I'll show you my script which is intended to capture the signal avg power
that a client has with an Access Point, the samples are taking between 1
sec and I need to send that trap to the manager in less time than 1 sec.
while :
do
valor=$(iw dev wlan0 station dump \
| grep 'signal avg': | awk '{print $3}')
snmptrap -v 1 -c public 192.168.1.25 '1.2.3.4.5.6' \
'192.168.1.1' 6 99 '55' 1.11.12.13.14.15 s "$valor"
echo $valor >> muestras.txt
sleep 1
done
But surprisingly the traps seems to be generated between 10 sec or maybe
the manager is receive them in an elapsed time of 10 sec. I don't know
where is the problem, in the agent or in the manager, but I'm sure that the
agent generates samples in 1 sec because "muestras.txt" shows that.
Hope you can help me!.
Greetings!
I found the answer.
The problem was in the server who executes snmptrapd. Simply I passed the argument -n to the snmptrapd and that solved all!.

Linpack sometimes starting, sometimes not, but nothing changed

I installed Linpack on a 2-Node cluster with Xeon processors. Sometimes if I start Linpack with this command:
mpiexec -np 28 -print-rank-map -f /root/machines.HOSTS ./xhpl_intel64
linpack starts and prints the output, sometimes I only see the mpi mappings printed and then nothing following. To me this seems like random behaviour because I don't change anything between the calls and as already mentioned, Linpack sometimes starts, sometimes not.
In top I can see that xhpl_intel64processes have been created and they are heavily using the CPU but when watching the traffic between the nodes, iftop is telling me that it nothing is sent.
I am using MPICH2 as MPI implementation. This is my HPL.dat:
# cat HPL.dat
HPLinpack benchmark input file
Innovative Computing Laboratory, University of Tennessee
HPL.out output file name (if any)
6 device out (6=stdout,7=stderr,file)
1 # of problems sizes (N)
10000 Ns
1 # of NBs
250 NBs
0 PMAP process mapping (0=Row-,1=Column-major)
1 # of process grids (P x Q)
2 Ps
14 Qs
16.0 threshold
1 # of panel fact
2 PFACTs (0=left, 1=Crout, 2=Right)
1 # of recursive stopping criterium
4 NBMINs (>= 1)
1 # of panels in recursion
2 NDIVs
1 # of recursive panel fact.
1 RFACTs (0=left, 1=Crout, 2=Right)
1 # of broadcast
1 BCASTs (0=1rg,1=1rM,2=2rg,3=2rM,4=Lng,5=LnM)
1 # of lookahead depth
1 DEPTHs (>=0)
2 SWAP (0=bin-exch,1=long,2=mix)
64 swapping threshold
0 L1 in (0=transposed,1=no-transposed) form
0 U in (0=transposed,1=no-transposed) form
1 Equilibration (0=no,1=yes)
8 memory alignment in double (> 0)
edit2:
I now just let the program run for a while and after 30min it tells me:
# mpiexec -np 32 -print-rank-map -f /root/machines.HOSTS ./xhpl_intel64
(node-0:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
(node-1:16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)
Assertion failed in file ../../socksm.c at line 2577: (it_plfd->revents & 0x008) == 0
internal ABORT - process 0
APPLICATION TERMINATED WITH THE EXIT STRING: Hangup (signal 1)
Is this a mpi problem?
Do you know what type of problem this could be?
I figured out what the problem was: MPICH2 uses different random ports each time it starts and if these are blocked your application wont start up correctly.
The solution for MPICH2 is to set the environment variable MPICH_PORT_RANGE to START:END, like this:
export MPICH_PORT_RANGE=50000:51000
Best,
heinrich

Resources