|
@@ -25,17 +25,18 @@ package password.pwm.http.servlet.configmanager;
|
|
|
import lombok.Builder;
|
|
|
import lombok.Value;
|
|
|
import org.apache.commons.csv.CSVPrinter;
|
|
|
+import org.apache.commons.io.output.CountingOutputStream;
|
|
|
import password.pwm.AppProperty;
|
|
|
import password.pwm.PwmAboutProperty;
|
|
|
import password.pwm.PwmApplication;
|
|
|
import password.pwm.PwmConstants;
|
|
|
+import password.pwm.bean.SessionLabel;
|
|
|
import password.pwm.bean.UserIdentity;
|
|
|
import password.pwm.config.Configuration;
|
|
|
import password.pwm.config.stored.StoredConfigurationImpl;
|
|
|
import password.pwm.error.PwmUnrecoverableException;
|
|
|
import password.pwm.health.HealthRecord;
|
|
|
import password.pwm.http.ContextManager;
|
|
|
-import password.pwm.http.PwmRequest;
|
|
|
import password.pwm.http.servlet.admin.AppDashboardData;
|
|
|
import password.pwm.http.servlet.admin.UserDebugDataBean;
|
|
|
import password.pwm.http.servlet.admin.UserDebugDataReader;
|
|
@@ -43,7 +44,11 @@ import password.pwm.ldap.LdapDebugDataGenerator;
|
|
|
import password.pwm.svc.PwmService;
|
|
|
import password.pwm.svc.cache.CacheService;
|
|
|
import password.pwm.svc.node.NodeService;
|
|
|
+import password.pwm.svc.stats.EpsStatistic;
|
|
|
+import password.pwm.svc.stats.Statistic;
|
|
|
+import password.pwm.svc.stats.StatisticsManager;
|
|
|
import password.pwm.util.LDAPPermissionCalculator;
|
|
|
+import password.pwm.util.java.DebugOutputBuilder;
|
|
|
import password.pwm.util.java.FileSystemUtility;
|
|
|
import password.pwm.util.java.JavaHelper;
|
|
|
import password.pwm.util.java.JsonUtil;
|
|
@@ -67,6 +72,7 @@ import java.io.StringWriter;
|
|
|
import java.io.Writer;
|
|
|
import java.lang.management.ManagementFactory;
|
|
|
import java.lang.management.ThreadInfo;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.Instant;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
@@ -74,6 +80,7 @@ import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.Properties;
|
|
|
import java.util.Set;
|
|
@@ -106,54 +113,85 @@ public class DebugItemGenerator
|
|
|
LdapRecentUserDebugGenerator.class,
|
|
|
ClusterInfoDebugGenerator.class,
|
|
|
CacheServiceDebugItemGenerator.class,
|
|
|
- RootFileSystemDebugItemGenerator.class
|
|
|
+ RootFileSystemDebugItemGenerator.class,
|
|
|
+ StatisticsDataDebugItemGenerator.class,
|
|
|
+ StatisticsEpsDataDebugItemGenerator.class
|
|
|
) );
|
|
|
|
|
|
- static void outputZipDebugFile(
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final ZipOutputStream zipOutput,
|
|
|
- final String pathPrefix
|
|
|
- )
|
|
|
- throws IOException, PwmUnrecoverableException
|
|
|
+ private final PwmApplication pwmApplication;
|
|
|
+ private final Configuration obfuscatedConfiguration;
|
|
|
+ private final SessionLabel sessionLabel;
|
|
|
+
|
|
|
+ private static final Locale LOCALE = PwmConstants.DEFAULT_LOCALE;
|
|
|
+
|
|
|
+ public DebugItemGenerator( final PwmApplication pwmApplication, final SessionLabel sessionLabel )
|
|
|
+ throws PwmUnrecoverableException
|
|
|
{
|
|
|
- final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
|
|
|
- final String debugFileName = "zipDebugGeneration.csv";
|
|
|
+ this.pwmApplication = pwmApplication;
|
|
|
+ this.sessionLabel = sessionLabel;
|
|
|
|
|
|
- final ByteArrayOutputStream debugGeneratorLogBaos = new ByteArrayOutputStream();
|
|
|
- final CSVPrinter debugGeneratorLogFile = JavaHelper.makeCsvPrinter( debugGeneratorLogBaos );
|
|
|
+ final StoredConfigurationImpl storedConfiguration = StoredConfigurationImpl.copy( pwmApplication.getConfig().getStoredConfiguration() );
|
|
|
+ storedConfiguration.resetAllPasswordValues( "value removed from " + getFilenameBase() + " configuration export" );
|
|
|
+ this.obfuscatedConfiguration = new Configuration( storedConfiguration );
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getFilenameBase()
|
|
|
+ {
|
|
|
+ return PwmConstants.PWM_APP_NAME + "-Support";
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getFilename()
|
|
|
+ {
|
|
|
+ return getFilenameBase() + ".zip";
|
|
|
+ }
|
|
|
+
|
|
|
+ public void outputZipDebugFile( final ZipOutputStream zipOutput )
|
|
|
+ throws IOException
|
|
|
+ {
|
|
|
+ final String debugFileName = "zipDebugGeneration.csv";
|
|
|
+ final Instant startTime = Instant.now();
|
|
|
+ final DebugOutputBuilder debugGeneratorLogFile = new DebugOutputBuilder();
|
|
|
+ final DebugItemInput debugItemInput = new DebugItemInput( pwmApplication, sessionLabel, obfuscatedConfiguration );
|
|
|
+ debugGeneratorLogFile.appendLine( "beginning debug output" );
|
|
|
+ final String pathPrefix = getFilenameBase() + "/";
|
|
|
|
|
|
for ( final Class<? extends DebugItemGenerator.Generator> serviceClass : DEBUG_ZIP_ITEM_GENERATORS )
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- final Instant startTime = Instant.now();
|
|
|
- LOGGER.trace( pwmRequest, () -> "beginning output of item " + serviceClass.getSimpleName() );
|
|
|
+ final Instant itemStartTime = Instant.now();
|
|
|
+ LOGGER.trace( sessionLabel, () -> "beginning output of item " + serviceClass.getSimpleName() );
|
|
|
final DebugItemGenerator.Generator newGeneratorItem = serviceClass.getDeclaredConstructor().newInstance();
|
|
|
zipOutput.putNextEntry( new ZipEntry( pathPrefix + newGeneratorItem.getFilename() ) );
|
|
|
- newGeneratorItem.outputItem( pwmApplication, pwmRequest, zipOutput );
|
|
|
+ newGeneratorItem.outputItem( debugItemInput, zipOutput );
|
|
|
zipOutput.closeEntry();
|
|
|
zipOutput.flush();
|
|
|
final String finishMsg = "completed output of " + newGeneratorItem.getFilename()
|
|
|
- + " in " + TimeDuration.fromCurrent( startTime ).asCompactString();
|
|
|
- LOGGER.trace( pwmRequest, () -> finishMsg );
|
|
|
- debugGeneratorLogFile.printRecord( JavaHelper.toIsoDate( Instant.now() ), finishMsg );
|
|
|
+ + " in " + TimeDuration.fromCurrent( itemStartTime ).asCompactString();
|
|
|
+ LOGGER.trace( sessionLabel, () -> finishMsg );
|
|
|
+ debugGeneratorLogFile.appendLine( finishMsg );
|
|
|
}
|
|
|
catch ( Throwable e )
|
|
|
{
|
|
|
final String errorMsg = "unexpected error executing debug item output class '" + serviceClass.getName() + "', error: " + e.toString();
|
|
|
- LOGGER.error( pwmRequest, errorMsg );
|
|
|
- debugGeneratorLogFile.printRecord( JavaHelper.toIsoDate( Instant.now() ), errorMsg );
|
|
|
+ LOGGER.error( sessionLabel, errorMsg, e );
|
|
|
+ debugGeneratorLogFile.appendLine( errorMsg );
|
|
|
final Writer stackTraceOutput = new StringWriter();
|
|
|
e.printStackTrace( new PrintWriter( stackTraceOutput ) );
|
|
|
- debugGeneratorLogFile.printRecord( stackTraceOutput );
|
|
|
+ debugGeneratorLogFile.appendLine( stackTraceOutput.toString() );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ {
|
|
|
+ final String msg = "completed in " + TimeDuration.compactFromCurrent( startTime );
|
|
|
+ debugGeneratorLogFile.appendLine( msg );
|
|
|
+ LOGGER.trace( sessionLabel, () -> msg );
|
|
|
+ }
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
zipOutput.putNextEntry( new ZipEntry( pathPrefix + debugFileName ) );
|
|
|
- debugGeneratorLogFile.flush();
|
|
|
- zipOutput.write( debugGeneratorLogBaos.toByteArray() );
|
|
|
+ zipOutput.write( debugGeneratorLogFile.toString().getBytes( PwmConstants.DEFAULT_CHARSET ) );
|
|
|
zipOutput.closeEntry();
|
|
|
}
|
|
|
catch ( Exception e )
|
|
@@ -173,10 +211,9 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
- final StoredConfigurationImpl storedConfiguration = ConfigManagerServlet.readCurrentConfiguration( pwmRequest );
|
|
|
- storedConfiguration.resetAllPasswordValues( "value removed from " + PwmConstants.PWM_APP_NAME + "-Support configuration export" );
|
|
|
+ final StoredConfigurationImpl storedConfiguration = debugItemInput.getObfuscatedConfiguration().getStoredConfiguration();
|
|
|
final String jsonOutput = JsonUtil.serialize( storedConfiguration.toJsonDebugObject(), JsonUtil.Flag.PrettyPrint );
|
|
|
outputStream.write( jsonOutput.getBytes( PwmConstants.DEFAULT_CHARSET ) );
|
|
|
}
|
|
@@ -191,10 +228,9 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
- final StoredConfigurationImpl storedConfiguration = ConfigManagerServlet.readCurrentConfiguration( pwmRequest );
|
|
|
- storedConfiguration.resetAllPasswordValues( "value removed from " + PwmConstants.PWM_APP_NAME + "-Support configuration export" );
|
|
|
+ final StoredConfigurationImpl storedConfiguration = debugItemInput.getObfuscatedConfiguration().getStoredConfiguration();
|
|
|
|
|
|
final StringWriter writer = new StringWriter();
|
|
|
writer.write( "Configuration Debug Output for "
|
|
@@ -205,7 +241,7 @@ public class DebugItemGenerator
|
|
|
|
|
|
writer.write( "\n" );
|
|
|
final Map<String, String> modifiedSettings = new TreeMap<>(
|
|
|
- storedConfiguration.getModifiedSettingDebugValues( PwmConstants.DEFAULT_LOCALE, true )
|
|
|
+ storedConfiguration.getModifiedSettingDebugValues( LOCALE, true )
|
|
|
);
|
|
|
|
|
|
for ( final Map.Entry<String, String> entry : modifiedSettings.entrySet() )
|
|
@@ -232,15 +268,14 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
- final StoredConfigurationImpl storedConfiguration = ConfigManagerServlet.readCurrentConfiguration( pwmRequest );
|
|
|
- storedConfiguration.resetAllPasswordValues( "value removed from " + PwmConstants.PWM_APP_NAME + "-Support configuration export" );
|
|
|
+ final StoredConfigurationImpl storedConfiguration = debugItemInput.getObfuscatedConfiguration().getStoredConfiguration();
|
|
|
|
|
|
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
- storedConfiguration.toXml( baos );
|
|
|
- outputStream.write( baos.toByteArray() );
|
|
|
- }
|
|
|
+ // temporary output stream required because .toXml closes stream.
|
|
|
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
+ storedConfiguration.toXml( byteArrayOutputStream );
|
|
|
+ outputStream.write( byteArrayOutputStream.toByteArray() ); }
|
|
|
}
|
|
|
|
|
|
static class AboutItemGenerator implements Generator
|
|
@@ -252,10 +287,10 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
final Properties outputProps = new JavaHelper.SortedProperties();
|
|
|
- final Map<PwmAboutProperty, String> infoBean = PwmAboutProperty.makeInfoBean( pwmApplication );
|
|
|
+ final Map<PwmAboutProperty, String> infoBean = PwmAboutProperty.makeInfoBean( debugItemInput.getPwmApplication() );
|
|
|
outputProps.putAll( PwmAboutProperty.toStringMap( infoBean ) );
|
|
|
outputProps.store( outputStream, JavaHelper.toIsoDate( Instant.now() ) );
|
|
|
}
|
|
@@ -270,7 +305,7 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
final Properties outputProps = new JavaHelper.SortedProperties();
|
|
|
outputProps.putAll( System.getenv() );
|
|
@@ -287,10 +322,10 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
|
|
|
- final Configuration config = pwmRequest.getConfig();
|
|
|
+ final Configuration config = debugItemInput.getObfuscatedConfiguration();
|
|
|
final Properties outputProps = new JavaHelper.SortedProperties();
|
|
|
|
|
|
for ( final AppProperty appProperty : AppProperty.values() )
|
|
@@ -311,9 +346,9 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream )
|
|
|
- throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
final LinkedHashMap<String, Object> outputMap = new LinkedHashMap<>();
|
|
|
|
|
|
{
|
|
@@ -346,8 +381,9 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
final Set<HealthRecord> records = pwmApplication.getHealthMonitor().getHealthRecords();
|
|
|
final String recordJson = JsonUtil.serializeCollection( records, JsonUtil.Flag.PrettyPrint );
|
|
|
outputStream.write( recordJson.getBytes( PwmConstants.DEFAULT_CHARSET ) );
|
|
@@ -363,18 +399,18 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
|
|
|
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
- final PrintWriter writer = new PrintWriter( new OutputStreamWriter( baos, PwmConstants.DEFAULT_CHARSET ) );
|
|
|
+ final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
+ final PrintWriter writer = new PrintWriter( new OutputStreamWriter( byteArrayOutputStream, PwmConstants.DEFAULT_CHARSET ) );
|
|
|
final ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads( true, true );
|
|
|
for ( final ThreadInfo threadInfo : threads )
|
|
|
{
|
|
|
writer.write( JavaHelper.threadInfoToString( threadInfo ) );
|
|
|
}
|
|
|
writer.flush();
|
|
|
- outputStream.write( baos.toByteArray() );
|
|
|
+ outputStream.write( byteArrayOutputStream.toByteArray() );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -387,13 +423,13 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
final List<LdapDebugDataGenerator.LdapDebugInfo> ldapDebugInfos = LdapDebugDataGenerator.makeLdapDebugInfos(
|
|
|
- pwmApplication,
|
|
|
- pwmRequest.getSessionLabel(),
|
|
|
- pwmApplication.getConfig(),
|
|
|
- pwmRequest.getLocale()
|
|
|
+ debugItemInput.getPwmApplication(),
|
|
|
+ debugItemInput.getSessionLabel(),
|
|
|
+ debugItemInput.getObfuscatedConfiguration(),
|
|
|
+ LOCALE
|
|
|
);
|
|
|
final Writer writer = new OutputStreamWriter( outputStream, PwmConstants.DEFAULT_CHARSET );
|
|
|
writer.write( JsonUtil.serializeCollection( ldapDebugInfos, JsonUtil.Flag.PrettyPrint ) );
|
|
@@ -411,9 +447,10 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem( final PwmApplication pwmApplication, final PwmRequest pwmRequest, final OutputStream outputStream ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
final List<FileSystemUtility.FileSummaryInformation> fileSummaryInformations = new ArrayList<>();
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
final File applicationPath = pwmApplication.getPwmEnvironment().getApplicationPath();
|
|
|
|
|
|
if ( pwmApplication.getPwmEnvironment().getContextManager() != null )
|
|
@@ -433,7 +470,7 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
catch ( Exception e )
|
|
|
{
|
|
|
- LOGGER.error( pwmRequest, "unable to generate webInfPath fileMd5sums during zip debug building: " + e.getMessage() );
|
|
|
+ LOGGER.error( debugItemInput.getSessionLabel(), "unable to generate webInfPath fileMd5sums during zip debug building: " + e.getMessage() );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -445,7 +482,7 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
catch ( Exception e )
|
|
|
{
|
|
|
- LOGGER.error( pwmRequest, "unable to generate appPath fileMd5sums during zip debug building: " + e.getMessage() );
|
|
|
+ LOGGER.error( debugItemInput.getSessionLabel(), "unable to generate appPath fileMd5sums during zip debug building: " + e.getMessage() );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -457,7 +494,7 @@ public class DebugItemGenerator
|
|
|
headerRow.add( "Filename" );
|
|
|
headerRow.add( "Last Modified" );
|
|
|
headerRow.add( "Size" );
|
|
|
- headerRow.add( "sha1sum" );
|
|
|
+ headerRow.add( "Checksum" );
|
|
|
csvPrinter.printComment( StringUtil.join( headerRow, "," ) );
|
|
|
}
|
|
|
for ( final FileSystemUtility.FileSummaryInformation fileSummaryInformation : fileSummaryInformations )
|
|
@@ -469,7 +506,7 @@ public class DebugItemGenerator
|
|
|
dataRow.add( fileSummaryInformation.getFilename() );
|
|
|
dataRow.add( JavaHelper.toIsoDate( fileSummaryInformation.getModified() ) );
|
|
|
dataRow.add( String.valueOf( fileSummaryInformation.getSize() ) );
|
|
|
- dataRow.add( fileSummaryInformation.getSha1sum() );
|
|
|
+ dataRow.add( Long.toString( fileSummaryInformation.getChecksum() ) );
|
|
|
csvPrinter.printRecord( dataRow );
|
|
|
}
|
|
|
catch ( Exception e )
|
|
@@ -491,40 +528,36 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
-
|
|
|
- final int maxCount = Integer.parseInt( pwmRequest.getConfig().readAppProperty( AppProperty.CONFIG_MANAGER_ZIPDEBUG_MAXLOGLINES ) );
|
|
|
- final int maxSeconds = Integer.parseInt( pwmRequest.getConfig().readAppProperty( AppProperty.CONFIG_MANAGER_ZIPDEBUG_MAXLOGSECONDS ) );
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
+ final long maxByteCount = JavaHelper.silentParseLong( pwmApplication.getConfig().readAppProperty( AppProperty.CONFIG_MANAGER_ZIPDEBUG_MAXLOGBYTES ), 10_000_000 );
|
|
|
+ final int maxSeconds = JavaHelper.silentParseInt( pwmApplication.getConfig().readAppProperty( AppProperty.CONFIG_MANAGER_ZIPDEBUG_MAXLOGSECONDS ), 60 );
|
|
|
final LocalDBSearchQuery searchParameters = LocalDBSearchQuery.builder()
|
|
|
.minimumLevel( PwmLogLevel.TRACE )
|
|
|
- .maxEvents( maxCount )
|
|
|
+ .maxEvents( Integer.MAX_VALUE )
|
|
|
.maxQueryTime( TimeDuration.of( maxSeconds, TimeDuration.Unit.SECONDS ) )
|
|
|
.build();
|
|
|
|
|
|
- final LocalDBSearchResults searchResults = pwmApplication.getLocalDBLogger().readStoredEvents(
|
|
|
- searchParameters );
|
|
|
- int counter = 0;
|
|
|
- while ( searchResults.hasNext() )
|
|
|
+ final LocalDBSearchResults searchResults = pwmApplication.getLocalDBLogger().readStoredEvents( searchParameters );
|
|
|
+ final CountingOutputStream countingOutputStream = new CountingOutputStream( outputStream );
|
|
|
+
|
|
|
+ final Writer writer = new OutputStreamWriter( countingOutputStream, PwmConstants.DEFAULT_CHARSET );
|
|
|
{
|
|
|
- final PwmLogEvent event = searchResults.next();
|
|
|
- outputStream.write( event.toLogString().getBytes( PwmConstants.DEFAULT_CHARSET ) );
|
|
|
- outputStream.write( "\n".getBytes( PwmConstants.DEFAULT_CHARSET ) );
|
|
|
- counter++;
|
|
|
- if ( counter % 1000 == 0 )
|
|
|
+ while ( searchResults.hasNext() && countingOutputStream.getByteCount() < maxByteCount )
|
|
|
{
|
|
|
- outputStream.flush();
|
|
|
+ final PwmLogEvent event = searchResults.next();
|
|
|
+ writer.write( event.toLogString() );
|
|
|
+ writer.write( "\n" );
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- {
|
|
|
- final int finalCounter = counter;
|
|
|
- LOGGER.trace( () -> "output " + finalCounter + " lines to " + this.getFilename() );
|
|
|
+ final String outputMsg = "debug output " + searchResults.getReturnedEvents() + " lines in " + searchResults.getSearchTime().asCompactString();
|
|
|
+ writer.write( "\n#" + outputMsg + "\n" );
|
|
|
+ LOGGER.trace( () -> outputMsg );
|
|
|
}
|
|
|
+
|
|
|
+ // do not close writer because underlying stream should not be closed.
|
|
|
+ writer.flush();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -537,14 +570,10 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
|
|
|
- final StoredConfigurationImpl storedConfiguration = ConfigManagerServlet.readCurrentConfiguration( pwmRequest );
|
|
|
+ final StoredConfigurationImpl storedConfiguration = debugItemInput.getObfuscatedConfiguration().getStoredConfiguration();
|
|
|
final LDAPPermissionCalculator ldapPermissionCalculator = new LDAPPermissionCalculator( storedConfiguration );
|
|
|
|
|
|
final CSVPrinter csvPrinter = JavaHelper.makeCsvPrinter( outputStream );
|
|
@@ -581,13 +610,9 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- ) throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
- final LocalDB localDB = pwmApplication.getLocalDB();
|
|
|
+ final LocalDB localDB = debugItemInput.getPwmApplication().getLocalDB();
|
|
|
final Map<String, Serializable> serializableMap = localDB.debugInfo();
|
|
|
outputStream.write( JsonUtil.serializeMap( serializableMap, JsonUtil.Flag.PrettyPrint ).getBytes( PwmConstants.DEFAULT_CHARSET ) );
|
|
|
}
|
|
@@ -602,14 +627,10 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- )
|
|
|
- throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
- pwmApplication.getSessionTrackService().outputToCsv( pwmRequest.getLocale(), pwmRequest.getConfig(), outputStream );
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
+ pwmApplication.getSessionTrackService().outputToCsv( LOCALE, pwmApplication.getConfig(), outputStream );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -621,14 +642,9 @@ public class DebugItemGenerator
|
|
|
return "recentUserDebugData.json";
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- )
|
|
|
- throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
final List<UserIdentity> recentUsers = pwmApplication.getSessionTrackService().getRecentLogins();
|
|
|
final List<UserDebugDataBean> recentDebugBeans = new ArrayList<>();
|
|
|
|
|
@@ -636,8 +652,8 @@ public class DebugItemGenerator
|
|
|
{
|
|
|
final UserDebugDataBean dataBean = UserDebugDataReader.readUserDebugData(
|
|
|
pwmApplication,
|
|
|
- pwmRequest.getLocale(),
|
|
|
- pwmRequest.getSessionLabel(),
|
|
|
+ LOCALE,
|
|
|
+ debugItemInput.getSessionLabel(),
|
|
|
userIdentity
|
|
|
);
|
|
|
recentDebugBeans.add( dataBean );
|
|
@@ -656,13 +672,9 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- )
|
|
|
- throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
final NodeService nodeService = pwmApplication.getClusterService();
|
|
|
|
|
|
final Map<String, Serializable> debugOutput = new LinkedHashMap<>();
|
|
@@ -687,13 +699,9 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- )
|
|
|
- throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
final CacheService cacheService = pwmApplication.getCacheService();
|
|
|
|
|
|
final Map<String, Serializable> debugOutput = new LinkedHashMap<>( cacheService.debugInfo() );
|
|
@@ -710,24 +718,82 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- )
|
|
|
- throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
- final ContextManager contextManager = ContextManager.getContextManager( pwmRequest );
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
+ final ContextManager contextManager = pwmApplication.getPwmEnvironment().getContextManager();
|
|
|
final AppDashboardData appDashboardData = AppDashboardData.makeDashboardData(
|
|
|
pwmApplication,
|
|
|
contextManager,
|
|
|
- pwmRequest.getLocale()
|
|
|
+ LOCALE
|
|
|
);
|
|
|
|
|
|
outputStream.write( JsonUtil.serialize( appDashboardData, JsonUtil.Flag.PrettyPrint ).getBytes( PwmConstants.DEFAULT_CHARSET ) );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ static class StatisticsDataDebugItemGenerator implements Generator
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public String getFilename()
|
|
|
+ {
|
|
|
+ return "statistics.csv";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
+ {
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
+ final StatisticsManager statsManager = pwmApplication.getStatisticsManager();
|
|
|
+ statsManager.outputStatsToCsv( outputStream, LOCALE, true );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static class StatisticsEpsDataDebugItemGenerator implements Generator
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public String getFilename()
|
|
|
+ {
|
|
|
+ return "statistics-eps.csv";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
+ {
|
|
|
+ final PwmApplication pwmApplication = debugItemInput.getPwmApplication();
|
|
|
+ final StatisticsManager statsManager = pwmApplication.getStatisticsManager();
|
|
|
+ final CSVPrinter csvPrinter = JavaHelper.makeCsvPrinter( outputStream );
|
|
|
+ {
|
|
|
+ final List<String> headerRow = new ArrayList<>();
|
|
|
+ headerRow.add( "Counter" );
|
|
|
+ headerRow.add( "Duration" );
|
|
|
+ headerRow.add( "Events/Second" );
|
|
|
+ csvPrinter.printComment( StringUtil.join( headerRow, "," ) );
|
|
|
+ }
|
|
|
+ for ( final EpsStatistic epsStatistic : EpsStatistic.values() )
|
|
|
+ {
|
|
|
+ for ( final Statistic.EpsDuration epsDuration : Statistic.EpsDuration.values() )
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ final List<String> dataRow = new ArrayList<>();
|
|
|
+ final BigDecimal value = statsManager.readEps( epsStatistic, epsDuration );
|
|
|
+ final String sValue = value.toPlainString();
|
|
|
+ dataRow.add( epsStatistic.getLabel( LOCALE ) );
|
|
|
+ dataRow.add( epsDuration.getTimeDuration().asCompactString() );
|
|
|
+ dataRow.add( sValue );
|
|
|
+ csvPrinter.printRecord( dataRow );
|
|
|
+ }
|
|
|
+ catch ( Exception e )
|
|
|
+ {
|
|
|
+ LOGGER.trace( () -> "error generating csv-stats summary info: " + e.getMessage() );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ csvPrinter.flush();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
static class RootFileSystemDebugItemGenerator implements Generator
|
|
|
{
|
|
|
@Override
|
|
@@ -737,12 +803,7 @@ public class DebugItemGenerator
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void outputItem(
|
|
|
- final PwmApplication pwmApplication,
|
|
|
- final PwmRequest pwmRequest,
|
|
|
- final OutputStream outputStream
|
|
|
- )
|
|
|
- throws Exception
|
|
|
+ public void outputItem( final DebugItemInput debugItemInput, final OutputStream outputStream ) throws Exception
|
|
|
{
|
|
|
final Collection<RootFileSystemInfo> rootInfos = RootFileSystemInfo.forAllRootFileSystems();
|
|
|
outputStream.write( JsonUtil.serializeCollection( rootInfos, JsonUtil.Flag.PrettyPrint ).getBytes( PwmConstants.DEFAULT_CHARSET ) );
|
|
@@ -782,10 +843,17 @@ public class DebugItemGenerator
|
|
|
String getFilename( );
|
|
|
|
|
|
void outputItem(
|
|
|
- PwmApplication pwmApplication,
|
|
|
- PwmRequest pwmRequest,
|
|
|
+ DebugItemInput debugItemInput,
|
|
|
OutputStream outputStream
|
|
|
) throws Exception;
|
|
|
}
|
|
|
|
|
|
+ @Value
|
|
|
+ private static class DebugItemInput
|
|
|
+ {
|
|
|
+ private final PwmApplication pwmApplication;
|
|
|
+ private final SessionLabel sessionLabel;
|
|
|
+ private final Configuration obfuscatedConfiguration;
|
|
|
+ }
|
|
|
+
|
|
|
}
|