Search in sources :

Example 1 with DiagnosticsReportSource

use of org.neo4j.kernel.diagnostics.DiagnosticsReportSource in project neo4j by neo4j.

the class JmxDump method systemProperties.

public DiagnosticsReportSource systemProperties() {
    return new DiagnosticsReportSource() {

        @Override
        public String destinationPath() {
            return "vm.prop";
        }

        @Override
        public InputStream newInputStream() {
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            systemProperties.list(new PrintStream(out, true));
            return new ByteArrayInputStream(out.toByteArray());
        }

        @Override
        public long estimatedSize() {
            return 0;
        }
    };
}
Also used : PrintStream(java.io.PrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DiagnosticsReportSource(org.neo4j.kernel.diagnostics.DiagnosticsReportSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with DiagnosticsReportSource

use of org.neo4j.kernel.diagnostics.DiagnosticsReportSource in project neo4j by neo4j.

the class JmxDump method heapDump.

public DiagnosticsReportSource heapDump() {
    return new DiagnosticsReportSource() {

        @Override
        public String destinationPath() {
            return "heapdump.hprof";
        }

        @Override
        public InputStream newInputStream() throws IOException {
            final Path heapdumpFile = createTempFile("neo4j-heapdump", ".hprof").toAbsolutePath();
            heapDump(heapdumpFile.toString());
            return new FileInputStream(heapdumpFile.toFile()) {

                @Override
                public void close() throws IOException {
                    super.close();
                    deleteIfExists(heapdumpFile);
                }
            };
        }

        @Override
        public long estimatedSize() {
            try {
                final MemoryMXBean bean = ManagementFactory.getPlatformMXBean(mBeanServer, MemoryMXBean.class);
                final long totalMemory = bean.getHeapMemoryUsage().getCommitted() + bean.getNonHeapMemoryUsage().getCommitted();
                // We first write raw to disk then write to archive, 5x compression is a reasonable worst case estimation
                return (long) (totalMemory * 1.2);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    };
}
Also used : Path(java.nio.file.Path) MemoryMXBean(java.lang.management.MemoryMXBean) DiagnosticsReportSource(org.neo4j.kernel.diagnostics.DiagnosticsReportSource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FileInputStream(java.io.FileInputStream)

Aggregations

DiagnosticsReportSource (org.neo4j.kernel.diagnostics.DiagnosticsReportSource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 UncheckedIOException (java.io.UncheckedIOException)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 Path (java.nio.file.Path)1