Merge pull request #123 from stevenvanrossem/master
[osm/vim-emu.git] / utils / ci / test_sdk_monitor.sh
1 #!/bin/bash
2 # test if a vnf can be deployed and monitored
3
4 #start test emulator topology
5 #python src/emuvim/examples/monitoring_demo_topology.py &
6
7 # start a vnf
8 son-emu-cli compute-zapi start -d datacenter1 -n vnf1 --net '(id=input,ip=10.0.10.3/24),(id=output,ip=10.0.10.4/24)'
9
10 sleep 1
11
12 # monitor a metric
13 son-emu-cli monitor setup_metric -vnf vnf1:output --metric tx_packets
14
15 sleep 5
16
17 # check if metric is monitored as expected (exported by son-emu, has vnf name as metric id)
18 tx_rate=$(son-emu-cli monitor prometheus -d datacenter1 -vnf vnf1 -q 'rate(sonemu_tx_count_packets{vnf_name="vnf1"}[1m])')
19
20
21 # test if prometheus query worked
22 echo $tx_rate
23
24 regex='\[[0-9.]*, .*\]'
25
26 if [[ $tx_rate =~ $regex ]] ; then
27 echo " tx_rate monitor test OK"
28 else
29 echo "tx_rate monitor test not OK"
30 exit 1
31 fi
32
33
34 # check if cpu load can be monitored (exported by cAdvisor, needs uuid)
35 cpu_load=$(son-emu-cli monitor prometheus -d datacenter1 -vnf vnf1 -q 'sum(rate(container_cpu_usage_seconds_total{id="/docker/<uuid>"}[10s]))')
36
37 sleep 1
38
39
40 # test if prometheus query worked
41 echo $cpu_load
42
43 regex='\[[0-9.]*, .*\]'
44
45 if [[ $cpu_load =~ $regex ]] ; then
46 echo " cpu monitor test OK"
47 else
48 echo "cpu monitor test not OK"
49 exit 1
50 fi
51
52 exit 0
53
54