Provides convenient self-contained Sigar classes with native library deployment and provisioning mechanism with JDK-only dependencies for the following common use cases:
- Java Agent: automatic extract/load at JVM start time
- Programmatically: embedded library extraction
- Framework Contract: OSGI bundle activation
#
# Extract to default location: ${user.dir}/native
java -javaagent:/path/to/sigar-loader.jar ...
#
# Extract to provided library extract location.
java -javaagent:/path/to/sigar-loader.jar=kamon.sigar.folder=/path/to/library/extract/folder ...
Sigar loader agent can also be provided via JVM attach API
// Required imports.
import java.io.File;
import org.hyperic.sigar.Sigar;
import kamon.sigar.SigarProvisioner;
// Extract to default location: ${user.dir}/native
SigarProvisioner.provision();
final Sigar sigar = new Sigar();
// Extract to user provided library extract location.
final File location = new File("target/native");
SigarProvisioner.provision(location);
final Sigar sigar = new Sigar();
karaf@root()> bundle:install mvn:io.kamon/sigar-loader/1.6.5-rev001
Default library extract location used by
java -javaagent:/path/to/sigar-loader.jar
andSigarProvisioner.provision()
will be selected in the following priority order:
- environment variable
KAMON_SIGAR_FOLDER
- system property
kamon.sigar.folder
- hard coded
${user.dir}/native
Bundle activator will use framework persistent bundle storage location.
Sigar loader ensures that native library is loaded exactly once.
Using sigar loader to provision native sigar library at the same path location from different JVM instances running on the same host can lead to crash of first running JVM when sigar native library is overwritten by the second running JVM during the library extraction.
This is expected behaviour and the work around is to use extraction paths which are unique to each JVM. See akka/akka#20804