Report tunnel status in status file

This commit is contained in:
Daniel Poelzleithner 2022-03-17 02:25:27 +01:00
parent c543a21162
commit f66b7147fd
2 changed files with 72 additions and 6 deletions

View File

@ -1923,6 +1923,33 @@ l_jiffies_add( lua_State *L )
}
}
/*
| Adds a number in seconds to a jiffy timestamp.
*/
static int
l_jiffies_concat( lua_State *L )
{
char buf[1024];
clock_t *p1 = ( clock_t * ) lua_touserdata( L, 1 );
clock_t *p2 = ( clock_t * ) lua_touserdata( L, 2 );
if( p1 && p2 )
{
logstring( "Error", "Cannot add two timestamps!" );
exit( -1 );
}
{
if (p1) {
snprintf( buf, sizeof(buf), "%Lf", (long double)(*p1));
lua_pushfstring(L, "%s%s", &buf, luaL_checkstring( L, 2));
} else {
snprintf( buf, sizeof(buf), "%Lf", (long double)(*p2));
lua_pushfstring(L, "%s%s", luaL_checkstring( L, 1), &buf);
}
return 1;
}
}
/*
| Subracts two jiffy timestamps resulting in a number in seconds
@ -2029,6 +2056,9 @@ register_lsyncd( lua_State *L )
lua_pushcfunction( L, l_jiffies_eq );
lua_setfield( L, mt, "__eq" );
lua_pushcfunction( L, l_jiffies_concat );
lua_setfield( L, mt, "__concat" );
lua_pop( L, 1 ); // pop(mt)
#ifdef WITH_INOTIFY

View File

@ -3232,11 +3232,12 @@ Tunnel = (function()
}
local TUNNEL_STATUS = {
DOWN = 0,
DISABLED = 1,
CONNECTING = 2,
UP = 3,
RETRY_TIMEOUT = 4,
UNKNOWN = 0,
DOWN = 1,
DISABLED = 2,
CONNECTING = 3,
UP = 4,
RETRY_TIMEOUT = 5,
}
local nextTunnelName = 1
@ -3286,6 +3287,16 @@ Tunnel = (function()
return rv
end
-- Returns the status of tunnel as text
function Tunnel:statusText()
for n, i in pairs(TUNNEL_STATUS) do
if self.status == i then
return n
end
end
return TUNNEL_STATUS.UNKNOWN
end
--
-- Returns next alarm
--
@ -3555,7 +3566,24 @@ Tunnel = (function()
return self.status == TUNNEL_STATUS.UP
end
--
-- Writes a status report about this tunnel
--
function Tunnel:statusReport(f)
f:write( 'Tunnel: name=', self.options.name, ' status=', self:statusText(), '\n' )
f:write( 'Running processes: ', self.processes:size( ), '\n')
for pid, prc in self.processes:walk( )
do
f:write(" pid=", pid, " type=", prc.type, " started=", ''..prc.started, '\n')
end
f:write( '\n' )
end
return Tunnel
end)() -- Tunnel scope
--
@ -3659,7 +3687,8 @@ local Tunnels = ( function
size = size,
invoke = invoke,
getAlarm = getAlarm,
killAll = killAll
killAll = killAll,
statusReport = statusReport
}
end )( )
@ -4878,6 +4907,13 @@ local StatusFile = ( function
f:write( '\n' )
end
for i, t in Tunnels.iwalk( )
do
t:statusReport( f )
f:write( '\n' )
end
Inotify.statusReport( f )
f:close( )