Permalink
Browse files

Added information to messages.log:

  * Disk space on store partition
  * Local time zone
  * Store file modification dates
  * IP addresses on interfaces
  • Loading branch information...
1 parent 7f68721 commit 868afd8ed01ffa38029d126fbe1f45f920ac5ea3 @systay committed Aug 28, 2012
@@ -61,7 +61,6 @@
import org.neo4j.kernel.guard.Guard;
import org.neo4j.kernel.impl.cache.Cache;
import org.neo4j.kernel.impl.cache.CacheProvider;
-import org.neo4j.kernel.impl.cache.MeasureDoNothing;
import org.neo4j.kernel.impl.cache.MonitorGc;
import org.neo4j.kernel.impl.core.Caches;
import org.neo4j.kernel.impl.core.DefaultCaches;
@@ -181,8 +180,6 @@
protected RecoveryVerifier recoveryVerifier;
protected Guard guard;
- protected MeasureDoNothing monitorGc;
-
protected NodeAutoIndexerImpl nodeAutoIndexer;
protected RelationshipAutoIndexerImpl relAutoIndexer;
protected KernelData extensions;
@@ -255,10 +252,10 @@ private void create()
for( Map.Entry<String, String> autoConfig : autoConfiguration.entrySet() )
{
// Don't override explicit settings
- if( !params.containsKey( autoConfig.getKey() ) )
+ String key = autoConfig.getKey();
+ if( !params.containsKey( key ) )
{
- String key = autoConfig.getKey();
- configParams.put( autoConfig.getKey(), autoConfig.getValue() );
+ configParams.put( key, autoConfig.getValue() );
}
}
@@ -20,6 +20,9 @@
package org.neo4j.kernel;
import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.helpers.Format;
@@ -68,28 +71,36 @@ void dump( StringLogger logger )
private static class StoreFiles extends KernelDiagnostics implements Visitor<StringLogger.LineLogger>
{
private final File storeDir;
+ private static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ssZ";
+ final private SimpleDateFormat dateFormat;
private StoreFiles( String storeDir )
{
- this.storeDir = new File(storeDir);
+ this.storeDir = new File( storeDir );
+ TimeZone tz = TimeZone.getDefault();
+ dateFormat = new SimpleDateFormat( FORMAT_DATE_ISO );
+ dateFormat.setTimeZone( tz );
}
@Override
void dump( StringLogger logger )
{
- logger.logLongMessage( "Storage files:", this, true );
+ logger.logLongMessage( getDiskSpace( storeDir ) + "\nStorage files: (filename : modification date - size)", this, true );
}
@Override
public boolean visit( StringLogger.LineLogger logger )
{
- logStoreFiles( logger, "", storeDir );
+ logStoreFiles( logger, " ", storeDir );
return false;
}
- private static long logStoreFiles( StringLogger.LineLogger logger, String prefix, File dir )
+ private long logStoreFiles( StringLogger.LineLogger logger, String prefix, File dir )
{
- if ( !dir.isDirectory() ) return 0;
+ if ( !dir.isDirectory() )
+ {
+ return 0;
+ }
File[] files = dir.listFiles();
if ( files == null )
{
@@ -106,18 +117,37 @@ private static long logStoreFiles( StringLogger.LineLogger logger, String prefix
logger.logLine( prefix + filename + ":" );
size = logStoreFiles( logger, prefix + " ", file );
filename = "- Total";
- }
- else
+ } else
{
size = file.length();
}
- logger.logLine( prefix + filename + ": " + Format.bytes( size ) );
+
+ String fileModificationDate = getFileModificationDate( file );
+ String bytes = Format.bytes( size );
+ String format = String.format( "%s%s: %s - %s", prefix, filename, fileModificationDate, bytes );
+ logger.logLine( format );
+
total += size;
}
return total;
}
+
+ private String getFileModificationDate( File file )
+ {
+ Date modifiedDate = new Date( file.lastModified() );
+ return dateFormat.format( modifiedDate );
+ }
+
+ private String getDiskSpace( File storeDir )
+ {
+ long free = storeDir.getFreeSpace();
+ long total = storeDir.getTotalSpace();
+ long percentage = ((total - free) * 100 / total);
+ return String.format( "Disk space on partition (Total / Free / Free %%): %s / %s / %s", total, free, percentage );
+ }
}
+
@Override
public String getDiagnosticsIdentifier()
{
@@ -19,6 +19,7 @@
*/
package org.neo4j.kernel.info;
+import static java.net.NetworkInterface.getNetworkInterfaces;
import static org.neo4j.helpers.Format.bytes;
import java.io.BufferedReader;
@@ -32,15 +33,21 @@
import java.lang.management.MemoryUsage;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.Collection;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
import org.neo4j.helpers.collection.Visitor;
import org.neo4j.kernel.impl.util.StringLogger;
@@ -105,13 +112,21 @@ void dump( StringLogger.LineLogger logger )
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
logger.logLine( String.format( "Operating System: %s; version: %s; arch: %s; cpus: %s", os.getName(),
- os.getVersion(), os.getArch(), Integer.valueOf( os.getAvailableProcessors() ) ) );
+ os.getVersion(), os.getArch(), os.getAvailableProcessors() ) );
logBeanProperty( logger, "Max number of file descriptors: ", os, SUN_UNIX_BEAN, "getMaxFileDescriptorCount" );
logBeanProperty( logger, "Number of open file descriptors: ", os, SUN_UNIX_BEAN, "getOpenFileDescriptorCount" );
logger.logLine( "Process id: " + runtime.getName() );
logger.logLine( "Byte order: " + ByteOrder.nativeOrder() );
+ logger.logLine( "Local timezone: " + getLocalTimeZone() );
}
+ private String getLocalTimeZone()
+ {
+ TimeZone tz = Calendar.getInstance().getTimeZone();
+ return tz.getID();
+ }
+
+
private void logBeanProperty( StringLogger.LineLogger logger, String message, Object bean, String type, String method )
{
Object value = getBeanProperty( bean, type, method, null );
@@ -271,6 +286,42 @@ public boolean accept( File path )
}
}
},
+ NETWORK( "Network information:" )
+ {
+ @Override
+ void dump( LineLogger logger )
+ {
+ logger.logLine( getIPAddresses() );
+ }
+
+ private String getIPAddresses()
+ {
+ StringBuilder mess = new StringBuilder();
+ try
+ {
+ Enumeration<NetworkInterface> networkInterfaces = getNetworkInterfaces();
+
+ while ( networkInterfaces.hasMoreElements() )
+ {
+ NetworkInterface iface = networkInterfaces.nextElement();
+ mess.append( String.format( "Interface %s:\n", iface.getDisplayName() ) );
+
+ Enumeration<InetAddress> addresses = iface.getInetAddresses();
+ while ( addresses.hasMoreElements() )
+ {
+ InetAddress address = addresses.nextElement();
+ String hostAddress = address.getHostAddress();
+ mess.append( String.format( " address: %s\n", hostAddress ) );
+ }
+ }
+ return mess.toString();
+ } catch ( SocketException e )
+ {
+ return "ERROR: failed to inspect network interfaces and addresses: " + e.getMessage();
+ }
+ }
+
+ },
;
private final String message;
@@ -0,0 +1,104 @@
+package org.neo4j.kernel;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+import org.junit.Test;
+import org.neo4j.helpers.collection.Visitor;
+import org.neo4j.kernel.impl.util.StringLogger;
+import org.neo4j.kernel.logging.Loggers;
+import org.neo4j.kernel.logging.Logging;
+import org.neo4j.test.ImpermanentGraphDatabase;
+
+
+public class DiagnosticsLoggingTest
+{
+ @Test
+ public void shouldSeeHelloWorld()
+ {
+ FakeDatabase db = new FakeDatabase();
+ FakeLogger logger = db.getLogger();
+ assertThat( logger.messages, containsString( "Network information" ) );
+ assertThat( logger.messages, containsString( "Disk space on partition" ) );
+ assertThat( logger.messages, containsString( "Local timezone" ) );
+ db.shutdown();
+ }
+
+ private class FakeLogger extends StringLogger implements Logging
+ {
+ public String messages = "";
+
+ @Override
+ public void logLongMessage( String msg, Visitor<LineLogger> source, boolean flush )
+ {
+ messages = messages + msg + "\n";
+ source.visit( new LineLogger()
+ {
+ @Override
+ public void logLine( String line )
+ {
+ messages = messages + line + "\n";
+ }
+ } );
+ }
+
+ @Override
+ public void logMessage( String msg, boolean flush )
+ {
+ messages = messages + msg + "\n";
+ }
+
+ @Override
+ public void logMessage( String msg, Throwable cause, boolean flush )
+ {
+ messages = messages + msg + "\n";
+ }
+
+ @Override
+ public void addRotationListener( Runnable listener )
+ {
+ }
+
+ @Override
+ public void flush()
+ {
+ }
+
+ @Override
+ public void close()
+ {
+ }
+
+ @Override
+ protected void logLine( String line )
+ {
+ messages = messages + line;
+ }
+
+ @Override
+ public StringLogger getLogger( String name )
+ {
+ if ( name.equals( Loggers.DIAGNOSTICS ) )
+ {
+ return this;
+ } else
+ {
+ return StringLogger.DEV_NULL;
+ }
+ }
+ }
+
+ private class FakeDatabase extends ImpermanentGraphDatabase
+ {
+ @Override
+ protected Logging createStringLogger()
+ {
+ return new FakeLogger();
+ }
+
+ public FakeLogger getLogger()
+ {
+ return (FakeLogger) logging;
+ }
+ }
+}

0 comments on commit 868afd8

Please sign in to comment.