-
-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
We got proposal on the email to add support for mqtt protocol. This was already in longterm plan so basic MQTT client should be added to Rye.
It's always much more motivating to work with real examples, so this is a first target example from the request. Using Rye to do the timing will also be interesting.
#!/usr/local/bin/lua54
function measureRespTime()
local sum = 0.0
for i=1,3,1 do
local handle = io.popen("curl -so /dev/null -w '%{time_total}\n' https://url/")
local result = handle:read("*a")
local res = result
local resp = res:gsub("[\n\r]", " ")
sum = sum + resp
handle:close()
end
local avg = sum/3
--print(avg)
publishMessage(avg)
end
function publishMessage(measurement)
local resptime = measurement
--local response = resptime:gsub("[-h]", " ")
local str1 = "nanomq_cli pub -t \"website/monitoring\" -q 2 -u ohab_client --password **** -m "
local str2 = " -h HOSTNAME -p PORT"
local str3 = str1 .. tostring(resptime)
local rtime = str3 .. str2
local handle = io.popen(rtime)
local result = handle:read("*a")
handle:close()
end
measureRespTime()
Thanks to mr. Serge for request and example.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels