@echo off

rem #  --------------------------------------------------------------
rem #  Company: Software- und Organisations-Service GmbH
rem #  Purpose: Java metrics by jstat for JS7 Controller
rem #  --------------------------------------------------------------

SETLOCAL

rem ##########################
rem # jstat metrics
rem # see https://docs.oracle.com/en/java/javase/17/docs/specs/man/jstat.html
rem # set this value of JS7_METRICS to 1 if jstat is to be called when the Controller starts
rem # Set JAVA_HOME in controller_instance.cmd because jstat is usually not in the path 
set /A JS7_METRICS=0

if %JS7_METRICS% equ 1 goto call_jstat
goto finally

:call_jstat
set JSTATLOG=%JS7_CONTROLLER_LOGS%\jstat.log
set JSTATBIN=%JAVA_HOME%\bin\jstat.exe

if not exist "%JSTATBIN%" (
  echo ...could not find "%JSTATBIN%"
  echo ...could not find "%JSTATBIN%">>"%JSTATLOG%"
  exit 1
)

echo.>>"%JSTATLOG%"
echo ------------ %DATE% %TIME% - PID %JS7_CONTROLLER_PID_FROMWMIC% ------------------------------------------------------------------------------------>>"%JSTATLOG%"
echo "%JSTATBIN%" -gc -t %JS7_CONTROLLER_PID_FROMWMIC% 60000 ^>^>"%JSTATLOG%" 2^>^&1
"%JSTATBIN%" -gc -t %JS7_CONTROLLER_PID_FROMWMIC% 60000 >>"%JSTATLOG%" 2>&1

:finally
exit 0

ENDLOCAL
