Skip to content

Commit

Permalink
Improve boostrap info
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Dec 18, 2024
1 parent 6074d9e commit d5c086d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/groovy/io/seqera/wave/Application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import io.seqera.wave.util.RuntimeInfo
class Application {

static void main(String[] args) {
log.info( "Starting ${BuildInfo.name} - version: ${BuildInfo.fullVersion} - ${RuntimeInfo.info('; ')} - CPUs ${Runtime.runtime.availableProcessors()}" )
log.info( "Starting ${BuildInfo.name} - version: ${BuildInfo.fullVersion} - ${RuntimeInfo.info('; ')}" )
setupConfig()
Micronaut.build(args)
.banner(false)
Expand Down
55 changes: 55 additions & 0 deletions src/main/groovy/io/seqera/wave/util/RuntimeInfo.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@

package io.seqera.wave.util

import java.lang.management.ManagementFactory

import com.sun.management.OperatingSystemMXBean
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.micronaut.core.version.VersionUtils;

/**
* Helper class to find out runtime info
*
* @author Paolo Di Tommaso <[email protected]>
*/
@Slf4j
@CompileStatic
class RuntimeInfo {

Expand All @@ -44,7 +49,57 @@ class RuntimeInfo {
result << "Micronaut: ${getMicronautVersion()}" << newline
result << "Runtime: Groovy ${groovyVersion} on ${jvmName} ${jvmVersion}" << newline
result << "Encoding: ${fileEncoding} (${fileNameEncoding})" << newline
final os = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()
result << "Process: ${ManagementFactory.getRuntimeMXBean().getName()}" << newline
result << "CPUs: ${Runtime.runtime.availableProcessors()} - Mem: ${totMem(os)} (free: ${freeMem(os)}) - Swap: ${totSwap(os)} (free: ${freeSwap(os)})" << newline

return result.toString()
}

static private String totMem(OperatingSystemMXBean os) {
try {
return formatBytes(os.totalMemorySize)
}
catch (Throwable t) {
log.debug "Unable to fetch totalMemorySize - ${t.message ?: t}"
return '-'
}
}

static private String freeMem(OperatingSystemMXBean os) {
try {
return formatBytes(os.freeMemorySize)
}
catch (Throwable t) {
log.debug "Unable to fetch freeMemorySize - ${t.message ?: t}"
return '-'
}
}

static private String totSwap(OperatingSystemMXBean os) {
try {
formatBytes(os.totalSwapSpaceSize)
}
catch (Throwable t) {
log.debug "Unable to fetch totalSwapSpaceSize - ${t.message ?: t}"
return '-'
}
}

static private String freeSwap(OperatingSystemMXBean os) {
try {
return formatBytes(os.freeSwapSpaceSize)
}
catch (Throwable t) {
log.debug "Unable to fetch freeSwapSpaceSize - ${t.message ?: t}"
return '-'
}
}

static private String formatBytes(long bytes) {
if (bytes < 1024) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(1024));
String units = "KMGTPE"; // Kilobyte, Megabyte, Gigabyte, etc.
return String.format("%.2f %sB", bytes / Math.pow(1024, exp), units.charAt(exp - 1));
}
}

0 comments on commit d5c086d

Please sign in to comment.