X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fsimulator-group%2Fsim-monitor.js;h=17d3205833e5db32307dac0f98e26fb97698f032;hb=bf3700b1064ec3526af205cab454bd1964ce8650;hp=76739f35eca309e55f90904c3902186a4154c071;hpb=72667f1d4b9e534b38b206f64f2ac67df01a2ed9;p=nonrtric.git diff --git a/test/simulator-group/sim-monitor.js b/test/simulator-group/sim-monitor.js index 76739f35..17d32058 100644 --- a/test/simulator-group/sim-monitor.js +++ b/test/simulator-group/sim-monitor.js @@ -21,20 +21,16 @@ // Presents a web page on localhost:9999/mon var LOCALHOST="http://127.0.0.1:" -var LOCALHOSTSECURE="https://127.0.0.1:" -//This var may switch between LOCALHOST and LOCALHOSTSECURE -var SIM_LOCALHOST=LOCALHOST var MRSTUB_PORT="3905" var AGENT_PORT="8081" var CR_PORT="8090" var http = require('http'); -var https = require('https'); var express = require('express'); var app = express(); var fieldSize=32; - +var flagstore={} //I am alive app.get("/",function(req, res){ @@ -42,15 +38,12 @@ app.get("/",function(req, res){ }) //Get parameter valuue from other server -function getSimCtr(httpx, url, index, cb) { +function getSimCtr(url, index, cb) { var data = ''; - var http_type=http - if (httpx=="https") { - http_type=https - } - console.log("URL: "+ url + " - " + httpx) + + //console.log("URL: "+ url + " - ") try { - http_type.get(url, (resp) => { + http.get(url, (resp) => { // A chunk of data has been recieved. resp.on('data', (chunk) => { data += chunk; @@ -133,6 +126,34 @@ function padding(val, fieldSize, pad) { return s; } +//Function to check if the previous call has returned, if so return true, if not return false +//For preventing multiple calls to slow containers. +function checkFunctionFlag(flag) { + if (flagstore.hasOwnProperty(flag)) { + if (flagstore[flag] == 0) { + flagstore[flag]=1 + return true + } else if (flagstore[flag] > 10) { + //Reset flag after ten attempts + console.log("Force release flag "+flag) + flagstore[flag]=1 + return true + } else { + //Previous call not returned + console.log("Flag not available "+flag) + flagstore[flag]=flagstore[flag]+1 + return false + } + } else { + flagstore[flag]=1 + return true + } +} +//Clear flag for parameter +function clearFlag(flag) { + flagstore[flag]=0 +} + //Status variables, for parameters values fetched from other simulators var mr1="", mr2="", mr3="", mr4="", mr5="", mr6=""; @@ -164,10 +185,7 @@ var getCtr=0 var refreshInterval=4000 -//Ignore self signed cert -process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; - -var sim_http_type="http" +var ricbasename="ricsim" function fetchAllMetrics() { setTimeout(() => { @@ -179,7 +197,7 @@ function fetchAllMetrics() { if (getCtr%3 == 0) { //Extract the port numbers from the running simulators, for every 3 calls const { exec } = require('child_process'); - exec('docker ps --filter "name=ricsim" --format "{{.Names}} {{.Ports}}" | sed s/0.0.0.0:// | cut -d \'>\' -f1 | sed \'s/[[-]]*$//\'', (err, stdout, stderr) => { + exec('docker ps --filter "name='+ricbasename+'" --format "{{.Names}} {{.Ports}}" | sed s/0.0.0.0:// | cut -d \'>\' -f1 | sed \'s/[[-]]*$//\'', (err, stdout, stderr) => { var simulators = "" simulators=`${stdout}`.replace(/(\r\n|\n|\r)/gm," "); @@ -197,124 +215,156 @@ function fetchAllMetrics() { //Get metric values from the simulators for(var index=0;index 1) { - ag2=ag2+", " + if (checkFunctionFlag("cr1")) { + getSimCtr(LOCALHOST+CR_PORT+"/counter/received_callbacks", 0, function(data, index) { + cr1 = data; + clearFlag("cr1") + }); + } + if (checkFunctionFlag("cr2")) { + getSimCtr(LOCALHOST+CR_PORT+"/counter/fetched_callbacks", 0, function(data, index) { + cr2 = data; + clearFlag("cr2") + }); + } + if (checkFunctionFlag("cr3")) { + getSimCtr(LOCALHOST+CR_PORT+"/counter/current_messages", 0, function(data, index) { + cr3 = data; + clearFlag("cr3") + }); + } + //Agent - more get metrics from the agent + if (checkFunctionFlag("ag1")) { + getSimCtr(LOCALHOST+AGENT_PORT+"/status", 0, function(data, index) { + ag1 = data; + clearFlag("ag1") + }); + } + if (checkFunctionFlag("ag2")) { + getSimCtr(LOCALHOST+AGENT_PORT+"/services", 0, function(data, index) { + ag2=""; + try { + var jd=JSON.parse(data); + for(var key in jd) { + if (ag2.length > 1) { + ag2=ag2+", " + } + ag2=ag2+(jd[key]["serviceName"]).trim() } - ag2=ag2+(jd[key]["serviceName"]).trim() } - } - catch (err) { - ag2=data - } - }); - getSimCtr("http", LOCALHOST+AGENT_PORT+"/policy_types", 0, function(data, index) { - ag3=""; - try { - var jd=JSON.parse(data); - for(var key in jd) { - if (ag3.length > 0) { - ag3=ag3+", " + catch (err) { + ag2=data + } + clearFlag("ag2") + }); + } + if (checkFunctionFlag("ag3")) { + getSimCtr(LOCALHOST+AGENT_PORT+"/policy_types", 0, function(data, index) { + ag3=""; + try { + var jd=JSON.parse(data); + for(var key in jd) { + if (ag3.length > 0) { + ag3=ag3+", " + } + ag3=ag3+jd[key].trim() } - ag3=ag3+jd[key].trim() } - } - catch (err) { - ag3="" - } - }); - getSimCtr("http", LOCALHOST+AGENT_PORT+"/policy_ids", 0, function(data, index) { - ag4="" - try { - var jd=JSON.parse(data); - ag4=""+jd.length - } - catch (err) { + catch (err) { + ag3="" + } + clearFlag("ag3") + }); + } + if (checkFunctionFlag("ag4")) { + getSimCtr(LOCALHOST+AGENT_PORT+"/policy_ids", 0, function(data, index) { ag4="" - } - }); - + try { + var jd=JSON.parse(data); + ag4=""+jd.length + } + catch (err) { + ag4="" + } + clearFlag("ag4") + }); + } fetchAllMetrics(); @@ -329,6 +379,14 @@ setInterval(() => { app.get("/mon",function(req, res){ + var bn=req.query.basename + + if (bn == undefined) { + getCtr=0 + return res.redirect('/mon?basename=ricsim'); + } else { + ricbasename=bn + } refreshInterval=2000 @@ -340,6 +398,9 @@ app.get("/mon",function(req, res){ "Policy Agent and simulator monitor"+ "" + "" + + "" + + "

Change basename in url if other ric sim prefix is used

" + + "
" + "

Policy agent

" + "" + "Status:..............................." + formatDataRow(ag1) + "
" +