CODE
-----------------------------------------------------------------
-- Name: ApacheStatus.lua
-- Author: Robert Aronsson, Intellipool AB
-- Required INM version: 3.3
-- Version: 1.0
-- Date: 2008-02-29
-- Description: This script requires that mod_status is installed.
-- The script can check that the apache server have a minimum of
-- available idle worker threads.
--
-- The script stores statistics on how many idle and busy worker threads
-- there is each test.
--
-- Arguments:
-- 1) Minimum idle work threads
-----------------------------------------------------------------
-- Get the min number of idle threads
iMinIdleWorkers = tonumber(GetArgument(0));
iIdleWorkers = -1
iBusyWorkers = -1
-- Create the http object
http = TLuaHTTPClient()
iRet = http:Connect()
if iRet ~= 0 then
-- retrive the status page
iRet = http:Get("/server-status?auto")
iLen = http:GetHeaderContentLength()
-- Check returned HTTP status code
if iRet == 200 and iLen~=0 then
-- Server returned OK (200) , grab the page content
sHTTPData,iRet = http:GetContent(iRet)
-- Split the string
aStatusArray = {};
string.gsub(sHTTPData, "(%w+)", function(d) d = string.lower(d) table.insert(aStatusArray,d) end)
-- extract keywords
min = 1;
max = table.getn(aStatusArray);
for count = min, max do
-- extract ideworkers
if aStatusArray[count] == "idleworkers" then
iIdleWorkers = tonumber(aStatusArray[count+1])
end
-- extract busyworkers
if aStatusArray[count] == "busyworkers" then
iBusyWorkers = tonumber(aStatusArray[count+1])
end
end
else
-- Page was not found, probably not installed and/or enabled mod_status
if iRet == 404 then
sErrorString = string.format("/server-status?auto page not found (404 status returned). Have you installed mod_status ?")
SetExitStatus(sErrorString,false);
return;
else
-- Something whent wrong when connecting to the server
sErrorString = string.format("Could not connect to the server or extract information, status code %d, content length returned %d bytes",iRet,iLen);
SetExitStatus(sErrorString,false);
return;
end
end
else
-- Something whent wrong when connecting to the server
sErrorString = string.format("Failed to connect to server, error code %d",iRet);
SetExitStatus(sErrorString,false);
return;
end
sStatus = "";
bReturnStatus = true;
if iIdleWorkers == -1 or iBusyWorkers == -1 then
-- The script have not been able to extract the needed data
SetExitStatus("Failed to extract keywords from returned data",false);
else
-- evaluate
if iIdleWorkers < iMinIdleWorkers then
sStatus = string.format("%d idle worker threads available, minimum required %d",iIdleWorkers,iMinIdleWorkers);
bReturnStatus = false;
else
sStatus = string.format("%d idle worker threads available, %d busy worker threads",iIdleWorkers,iBusyWorkers)
end
-- Store statistics and set exit status
StoreStatisticalData(LUA_RECORDSET_1,iIdleWorkers,iMinIdleWorkers,"threads")
StoreStatisticalData(LUA_RECORDSET_2,iBusyWorkers,0,"threads")
SetExitStatus(sStatus,bReturnStatus);
end
-- Name: ApacheStatus.lua
-- Author: Robert Aronsson, Intellipool AB
-- Required INM version: 3.3
-- Version: 1.0
-- Date: 2008-02-29
-- Description: This script requires that mod_status is installed.
-- The script can check that the apache server have a minimum of
-- available idle worker threads.
--
-- The script stores statistics on how many idle and busy worker threads
-- there is each test.
--
-- Arguments:
-- 1) Minimum idle work threads
-----------------------------------------------------------------
-- Get the min number of idle threads
iMinIdleWorkers = tonumber(GetArgument(0));
iIdleWorkers = -1
iBusyWorkers = -1
-- Create the http object
http = TLuaHTTPClient()
iRet = http:Connect()
if iRet ~= 0 then
-- retrive the status page
iRet = http:Get("/server-status?auto")
iLen = http:GetHeaderContentLength()
-- Check returned HTTP status code
if iRet == 200 and iLen~=0 then
-- Server returned OK (200) , grab the page content
sHTTPData,iRet = http:GetContent(iRet)
-- Split the string
aStatusArray = {};
string.gsub(sHTTPData, "(%w+)", function(d) d = string.lower(d) table.insert(aStatusArray,d) end)
-- extract keywords
min = 1;
max = table.getn(aStatusArray);
for count = min, max do
-- extract ideworkers
if aStatusArray[count] == "idleworkers" then
iIdleWorkers = tonumber(aStatusArray[count+1])
end
-- extract busyworkers
if aStatusArray[count] == "busyworkers" then
iBusyWorkers = tonumber(aStatusArray[count+1])
end
end
else
-- Page was not found, probably not installed and/or enabled mod_status
if iRet == 404 then
sErrorString = string.format("/server-status?auto page not found (404 status returned). Have you installed mod_status ?")
SetExitStatus(sErrorString,false);
return;
else
-- Something whent wrong when connecting to the server
sErrorString = string.format("Could not connect to the server or extract information, status code %d, content length returned %d bytes",iRet,iLen);
SetExitStatus(sErrorString,false);
return;
end
end
else
-- Something whent wrong when connecting to the server
sErrorString = string.format("Failed to connect to server, error code %d",iRet);
SetExitStatus(sErrorString,false);
return;
end
sStatus = "";
bReturnStatus = true;
if iIdleWorkers == -1 or iBusyWorkers == -1 then
-- The script have not been able to extract the needed data
SetExitStatus("Failed to extract keywords from returned data",false);
else
-- evaluate
if iIdleWorkers < iMinIdleWorkers then
sStatus = string.format("%d idle worker threads available, minimum required %d",iIdleWorkers,iMinIdleWorkers);
bReturnStatus = false;
else
sStatus = string.format("%d idle worker threads available, %d busy worker threads",iIdleWorkers,iBusyWorkers)
end
-- Store statistics and set exit status
StoreStatisticalData(LUA_RECORDSET_1,iIdleWorkers,iMinIdleWorkers,"threads")
StoreStatisticalData(LUA_RECORDSET_2,iBusyWorkers,0,"threads")
SetExitStatus(sStatus,bReturnStatus);
end