Merge pull request #124 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 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 # allow some time to gather metrics
16 sleep 20
17
18 # check if metric is monitored as expected (exported by son-emu, has vnf name as metric id)
19 tx_rate=$(son-emu-cli monitor-zapi prometheus -d datacenter1 -vnf vnf1 -q 'rate(sonemu_tx_count_packets{vnf_name="vnf1"}[10s])')
20
21 sleep 1
22
23 # test if prometheus query worked
24 echo $tx_rate
25
26 regex='\[[0-9.]*, .*\]'
27
28 if [[ $tx_rate =~ $regex ]] ; then
29 echo " tx_rate monitor test OK"
30 else
31 echo "tx_rate monitor test not OK"
32 exit 1
33 fi
34
35
36 # check if cpu load can be monitored (exported by cAdvisor, needs uuid)
37 cpu_load=$(son-emu-cli monitor-zapi prometheus -d datacenter1 -vnf vnf1 -q 'sum(rate(container_cpu_usage_seconds_total{id="/docker/<uuid>"}[10s]))')
38
39 sleep 1
40
41
42 # test if prometheus query worked
43 echo $cpu_load
44
45 regex='\[[0-9.]*, .*\]'
46
47 if [[ $cpu_load =~ $regex ]] ; then
48 echo " cpu monitor test OK"
49 else
50 echo "cpu monitor test not OK"
51 exit 1
52 fi
53
54 exit 0
55
56