Java源码示例:org.elasticsearch.monitor.jvm.JvmInfo

示例1
public NodeInfo(Version version, Build build, DiscoveryNode node, @Nullable ImmutableMap<String, String> serviceAttributes, @Nullable Settings settings,
                @Nullable OsInfo os, @Nullable ProcessInfo process, @Nullable JvmInfo jvm, @Nullable ThreadPoolInfo threadPool,
                @Nullable TransportInfo transport, @Nullable HttpInfo http, @Nullable PluginsAndModules plugins) {
    super(node);
    this.version = version;
    this.build = build;
    this.serviceAttributes = serviceAttributes;
    this.settings = settings;
    this.os = os;
    this.process = process;
    this.jvm = jvm;
    this.threadPool = threadPool;
    this.transport = transport;
    this.http = http;
    this.plugins = plugins;
}
 
示例2
private void logVersion(Logger logger, JvmInfo jvmInfo) {
    logger.info(
        "version[{}], pid[{}], build[{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]",
        Version.displayVersion(Version.CURRENT, Version.CURRENT.isSnapshot()),
        jvmInfo.pid(),
        Build.CURRENT.hashShort(),
        Build.CURRENT.timestamp(),
        Constants.OS_NAME,
        Constants.OS_VERSION,
        Constants.OS_ARCH,
        Constants.JVM_VENDOR,
        Constants.JVM_NAME,
        Constants.JAVA_VERSION,
        Constants.JVM_VERSION);
    warnIfPreRelease(Version.CURRENT, Version.CURRENT.isSnapshot(), logger);
}
 
示例3
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    version = Version.readVersion(in);
    build = Build.readBuild(in);
    if (in.readBoolean()) {
        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        int size = in.readVInt();
        for (int i = 0; i < size; i++) {
            builder.put(in.readString(), in.readString());
        }
        serviceAttributes = builder.build();
    }
    if (in.readBoolean()) {
        settings = Settings.readSettingsFromStream(in);
    }
    if (in.readBoolean()) {
        os = OsInfo.readOsInfo(in);
    }
    if (in.readBoolean()) {
        process = ProcessInfo.readProcessInfo(in);
    }
    if (in.readBoolean()) {
        jvm = JvmInfo.readJvmInfo(in);
    }
    if (in.readBoolean()) {
        threadPool = ThreadPoolInfo.readThreadPoolInfo(in);
    }
    if (in.readBoolean()) {
        transport = TransportInfo.readTransportInfo(in);
    }
    if (in.readBoolean()) {
        http = HttpInfo.readHttpInfo(in);
    }
    if (in.readBoolean()) {
        plugins = new PluginsAndModules();
        plugins.readFrom(in);
    }
}
 
示例4
static void tryVirtualLock() {
    JNAKernel32Library kernel = JNAKernel32Library.getInstance();
    Pointer process = null;
    try {
        process = kernel.GetCurrentProcess();
        // By default, Windows limits the number of pages that can be locked.
        // Thus, we need to first increase the working set size of the JVM by
        // the amount of memory we wish to lock, plus a small overhead (1MB).
        SizeT size = new SizeT(JvmInfo.jvmInfo().getMem().getHeapInit().getBytes() + (1024 * 1024));
        if (!kernel.SetProcessWorkingSetSize(process, size, size)) {
            logger.warn("Unable to lock JVM memory. Failed to set working set size. Error code " + Native.getLastError());
        } else {
            JNAKernel32Library.MemoryBasicInformation memInfo = new JNAKernel32Library.MemoryBasicInformation();
            long address = 0;
            while (kernel.VirtualQueryEx(process, new Pointer(address), memInfo, memInfo.size()) != 0) {
                boolean lockable = memInfo.State.longValue() == JNAKernel32Library.MEM_COMMIT
                        && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_NOACCESS) != JNAKernel32Library.PAGE_NOACCESS
                        && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_GUARD) != JNAKernel32Library.PAGE_GUARD;
                if (lockable) {
                    kernel.VirtualLock(memInfo.BaseAddress, new SizeT(memInfo.RegionSize.longValue()));
                }
                // Move to the next region
                address += memInfo.RegionSize.longValue();
            }
            LOCAL_MLOCKALL = true;
        }
    } catch (UnsatisfiedLinkError e) {
        // this will have already been logged by Kernel32Library, no need to repeat it
    } finally {
        if (process != null) {
            kernel.CloseHandle(process);
        }
    }
}
 
示例5
@Override
protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception {
    if (options.nonOptionArguments().isEmpty() == false) {
        throw new UserException(ExitCodes.USAGE, "Positional arguments not allowed, found " + options.nonOptionArguments());
    }
    if (options.has(versionOption)) {
        if (options.has(daemonizeOption) || options.has(pidfileOption)) {
            throw new UserException(ExitCodes.USAGE, "CrateDB version option is mutually exclusive with any other option");
        }
        terminal.println("Version: " + Version.CURRENT
                         + ", Build: " + Build.CURRENT.hashShort() + "/" + Build.CURRENT.timestamp()
                         + ", JVM: " + JvmInfo.jvmInfo().version());
        return;
    }

    final boolean daemonize = options.has(daemonizeOption);

    final Path pidFile = pidfileOption.value(options);
    env = addPidFileSetting(pidFile, env);

    final boolean quiet = options.has(quietOption);

    try {
        init(daemonize, quiet, env);
    } catch (NodeValidationException e) {
        throw new UserException(ExitCodes.CONFIG, e.getMessage());
    }
}
 
示例6
@SuppressForbidden(reason = "System.out.*")
public static void main(String[] args) {
    final String versionOutput = String.format(
            Locale.ROOT,
            "Version: %s, Build: %s/%s, JVM: %s",
            Version.displayVersion(Version.CURRENT, Version.CURRENT.isSnapshot()),
            Build.CURRENT.hashShort(),
            Build.CURRENT.timestamp(),
            JvmInfo.jvmInfo().version());
    System.out.println(versionOutput);
}
 
示例7
static void tryVirtualLock() {
    JNAKernel32Library kernel = JNAKernel32Library.getInstance();
    Pointer process = null;
    try {
        process = kernel.GetCurrentProcess();
        // By default, Windows limits the number of pages that can be locked.
        // Thus, we need to first increase the working set size of the JVM by
        // the amount of memory we wish to lock, plus a small overhead (1MB).
        SizeT size = new SizeT(JvmInfo.jvmInfo().getMem().getHeapInit().getBytes() + (1024 * 1024));
        if (!kernel.SetProcessWorkingSetSize(process, size, size)) {
            LOGGER.warn("Unable to lock JVM memory. Failed to set working set size. Error code {}", Native.getLastError());
        } else {
            JNAKernel32Library.MemoryBasicInformation memInfo = new JNAKernel32Library.MemoryBasicInformation();
            long address = 0;
            while (kernel.VirtualQueryEx(process, new Pointer(address), memInfo, memInfo.size()) != 0) {
                boolean lockable = memInfo.State.longValue() == JNAKernel32Library.MEM_COMMIT
                        && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_NOACCESS) != JNAKernel32Library.PAGE_NOACCESS
                        && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_GUARD) != JNAKernel32Library.PAGE_GUARD;
                if (lockable) {
                    kernel.VirtualLock(memInfo.BaseAddress, new SizeT(memInfo.RegionSize.longValue()));
                }
                // Move to the next region
                address += memInfo.RegionSize.longValue();
            }
            LOCAL_MLOCKALL = true;
        }
    } catch (UnsatisfiedLinkError e) {
        // this will have already been logged by Kernel32Library, no need to repeat it
    } finally {
        if (process != null) {
            kernel.CloseHandle(process);
        }
    }
}
 
示例8
@Override
public BootstrapCheckResult check(Settings settings) {
    if (getUseSerialGC().equals("true")) {
        final String message = String.format(
                Locale.ROOT,
                "JVM is using the serial collector but should not be for the best performance; " +
                        "either it's the default for the VM [%s] or -XX:+UseSerialGC was explicitly specified",
                JvmInfo.jvmInfo().getVmName());
        return BootstrapCheckResult.failure(message);
    } else {
        return BootstrapCheckResult.success();
    }
}
 
示例9
public void testMemorySize() {
    Setting<ByteSizeValue> memorySizeValueSetting = Setting.memorySizeSetting("a.byte.size", new ByteSizeValue(1024), Property.Dynamic,
            Property.NodeScope);

    assertFalse(memorySizeValueSetting.isGroupSetting());
    ByteSizeValue memorySizeValue = memorySizeValueSetting.get(Settings.EMPTY);
    assertEquals(memorySizeValue.getBytes(), 1024);

    memorySizeValueSetting = Setting.memorySizeSetting("a.byte.size", s -> "2048b", Property.Dynamic, Property.NodeScope);
    memorySizeValue = memorySizeValueSetting.get(Settings.EMPTY);
    assertEquals(memorySizeValue.getBytes(), 2048);

    memorySizeValueSetting = Setting.memorySizeSetting("a.byte.size", "50%", Property.Dynamic, Property.NodeScope);
    assertFalse(memorySizeValueSetting.isGroupSetting());
    memorySizeValue = memorySizeValueSetting.get(Settings.EMPTY);
    assertEquals(memorySizeValue.getBytes(), JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.5, 1.0);

    memorySizeValueSetting = Setting.memorySizeSetting("a.byte.size", s -> "25%", Property.Dynamic, Property.NodeScope);
    memorySizeValue = memorySizeValueSetting.get(Settings.EMPTY);
    assertEquals(memorySizeValue.getBytes(), JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.25, 1.0);

    AtomicReference<ByteSizeValue> value = new AtomicReference<>(null);
    ClusterSettings.SettingUpdater<ByteSizeValue> settingUpdater = memorySizeValueSetting.newUpdater(value::set, logger);

    assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "12").build(), Settings.EMPTY));
    assertEquals(new ByteSizeValue(12), value.get());

    assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "12b").build(), Settings.EMPTY));
    assertEquals(new ByteSizeValue(12), value.get());

    assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "20%").build(), Settings.EMPTY));
    assertEquals(new ByteSizeValue((int) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.2)), value.get());
}
 
示例10
@Test
public void testCircuitBreakerSettings() {
    double defaultTotalPercentage = 0.95d;
    assertMemorySizeSetting(HierarchyCircuitBreakerService.TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING, "indices.breaker.total.limit",
            new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * defaultTotalPercentage)));
    assertMemorySizeSetting(HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING, "indices.breaker.fielddata.limit",
                            new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.6)));
    assertMemorySizeSetting(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, "indices.breaker.request.limit",
            new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.6)));
    assertMemorySizeSetting(HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING,
            "network.breaker.inflight_requests.limit", new ByteSizeValue((JvmInfo.jvmInfo().getMem().getHeapMax().getBytes())));
}
 
示例11
private void assertMemorySizeSetting(Setting<ByteSizeValue> setting, String settingKey, ByteSizeValue defaultValue) {
    assertThat(setting, notNullValue());
    assertThat(setting.getKey(), equalTo(settingKey));
    assertThat(setting.getProperties(), hasItem(Property.NodeScope));
    assertThat(setting.getDefault(Settings.EMPTY),
            equalTo(defaultValue));
    Settings settingWithPercentage = Settings.builder().put(settingKey, "25%").build();
    assertThat(setting.get(settingWithPercentage),
            equalTo(new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.25))));
    Settings settingWithBytesValue = Settings.builder().put(settingKey, "1024b").build();
    assertThat(setting.get(settingWithBytesValue), equalTo(new ByteSizeValue(1024)));
}
 
示例12
public static void main(String[] args) {
    System.out.println("Version: " + Version.CURRENT + ", Build: " +
            Build.CURRENT.hashShort() + "/" + Build.CURRENT.timestamp() +
            ", ES: " + org.elasticsearch.Version.CURRENT +
            ", JVM: " + JvmInfo.jvmInfo().version() );
}
 
示例13
@Inject
public IndexingMemoryController(Settings settings, ThreadPool threadPool, IndicesService indicesService) {
    this(settings, threadPool, indicesService, JvmInfo.jvmInfo().getMem().getHeapMax().bytes());
}
 
示例14
@SuppressForbidden(reason = "System.out.*")
public static void main(String[] args) {
    System.out.println("Version: " + Version.CURRENT + ", Build: " + Build.CURRENT.hashShort() + "/" + Build.CURRENT.timestamp() + ", JVM: " + JvmInfo.jvmInfo().version());
}
 
示例15
private void maybeLogHeapDetails() {
    JvmInfo jvmInfo = JvmInfo.jvmInfo();
    ByteSizeValue maxHeapSize = jvmInfo.getMem().getHeapMax();
    String useCompressedOops = jvmInfo.useCompressedOops();
    logger.info("heap size [{}], compressed ordinary object pointers [{}]", maxHeapSize, useCompressedOops);
}
 
示例16
@Inject
public NettyTransport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, Version version, NamedWriteableRegistry namedWriteableRegistry) {
    super(settings);
    this.threadPool = threadPool;
    this.networkService = networkService;
    this.bigArrays = bigArrays;
    this.version = version;

    if (settings.getAsBoolean("netty.epollBugWorkaround", false)) {
        System.setProperty("org.jboss.netty.epollBugWorkaround", "true");
    }

    this.workerCount = settings.getAsInt(WORKER_COUNT, EsExecutors.boundedNumberOfProcessors(settings) * 2);
    this.blockingClient = settings.getAsBoolean("transport.netty.transport.tcp.blocking_client", settings.getAsBoolean(TCP_BLOCKING_CLIENT, settings.getAsBoolean(TCP_BLOCKING, false)));
    this.connectTimeout = this.settings.getAsTime("transport.netty.connect_timeout", settings.getAsTime("transport.tcp.connect_timeout", settings.getAsTime(TCP_CONNECT_TIMEOUT, TCP_DEFAULT_CONNECT_TIMEOUT)));
    this.maxCumulationBufferCapacity = this.settings.getAsBytesSize("transport.netty.max_cumulation_buffer_capacity", null);
    this.maxCompositeBufferComponents = this.settings.getAsInt("transport.netty.max_composite_buffer_components", -1);
    this.compress = settings.getAsBoolean(TransportSettings.TRANSPORT_TCP_COMPRESS, false);

    this.connectionsPerNodeRecovery = this.settings.getAsInt("transport.netty.connections_per_node.recovery", settings.getAsInt(CONNECTIONS_PER_NODE_RECOVERY, 2));
    this.connectionsPerNodeBulk = this.settings.getAsInt("transport.netty.connections_per_node.bulk", settings.getAsInt(CONNECTIONS_PER_NODE_BULK, 3));
    this.connectionsPerNodeReg = this.settings.getAsInt("transport.netty.connections_per_node.reg", settings.getAsInt(CONNECTIONS_PER_NODE_REG, 6));
    this.connectionsPerNodeState = this.settings.getAsInt("transport.netty.connections_per_node.high", settings.getAsInt(CONNECTIONS_PER_NODE_STATE, 1));
    this.connectionsPerNodePing = this.settings.getAsInt("transport.netty.connections_per_node.ping", settings.getAsInt(CONNECTIONS_PER_NODE_PING, 1));

    // we want to have at least 1 for reg/state/ping
    if (this.connectionsPerNodeReg == 0) {
        throw new IllegalArgumentException("can't set [connection_per_node.reg] to 0");
    }
    if (this.connectionsPerNodePing == 0) {
        throw new IllegalArgumentException("can't set [connection_per_node.ping] to 0");
    }
    if (this.connectionsPerNodeState == 0) {
        throw new IllegalArgumentException("can't set [connection_per_node.state] to 0");
    }

    long defaultReceiverPredictor = 512 * 1024;
    if (JvmInfo.jvmInfo().getMem().getDirectMemoryMax().bytes() > 0) {
        // we can guess a better default...
        long l = (long) ((0.3 * JvmInfo.jvmInfo().getMem().getDirectMemoryMax().bytes()) / workerCount);
        defaultReceiverPredictor = Math.min(defaultReceiverPredictor, Math.max(l, 64 * 1024));
    }

    // See AdaptiveReceiveBufferSizePredictor#DEFAULT_XXX for default values in netty..., we can use higher ones for us, even fixed one
    this.receivePredictorMin = this.settings.getAsBytesSize("transport.netty.receive_predictor_min", this.settings.getAsBytesSize("transport.netty.receive_predictor_size", new ByteSizeValue(defaultReceiverPredictor)));
    this.receivePredictorMax = this.settings.getAsBytesSize("transport.netty.receive_predictor_max", this.settings.getAsBytesSize("transport.netty.receive_predictor_size", new ByteSizeValue(defaultReceiverPredictor)));
    if (receivePredictorMax.bytes() == receivePredictorMin.bytes()) {
        receiveBufferSizePredictorFactory = new FixedReceiveBufferSizePredictorFactory((int) receivePredictorMax.bytes());
    } else {
        receiveBufferSizePredictorFactory = new AdaptiveReceiveBufferSizePredictorFactory((int) receivePredictorMin.bytes(), (int) receivePredictorMin.bytes(), (int) receivePredictorMax.bytes());
    }

    this.scheduledPing = new ScheduledPing();
    this.pingSchedule = settings.getAsTime(PING_SCHEDULE, DEFAULT_PING_SCHEDULE);
    if (pingSchedule.millis() > 0) {
        threadPool.schedule(pingSchedule, ThreadPool.Names.GENERIC, scheduledPing);
    }
    this.namedWriteableRegistry = namedWriteableRegistry;
}
 
示例17
JvmVersion(JvmInfo jvmInfo) {
    version = jvmInfo.version();
    vmName = jvmInfo.getVmName();
    vmVersion = jvmInfo.getVmVersion();
    vmVendor = jvmInfo.getVmVendor();
}
 
示例18
/**
 * JVM level information.
 */
@Nullable
public JvmInfo getJvm() {
    return jvm;
}
 
示例19
@Override
public ExitStatus execute(Settings settings, Environment env) throws Exception {
    terminal.println("Version: %s, Build: %s/%s, JVM: %s", org.elasticsearch.Version.CURRENT, Build.CURRENT.hashShort(), Build.CURRENT.timestamp(), JvmInfo.jvmInfo().version());
    return ExitStatus.OK_AND_EXIT;
}
 
示例20
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
    JvmInfo.jvmInfo();
}
 
示例21
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
    JvmInfo.jvmInfo();
}
 
示例22
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
    JvmInfo.jvmInfo();
}
 
示例23
@SuppressWarnings("unused")
public void execute() {
    console.println("elasticsearch version: " + Version.CURRENT + ", JVM: " + JvmInfo.jvmInfo().vmVersion());
}
 
示例24
static void initializeProbes() {
    // Force probes to be loaded
    ProcessProbe.getInstance();
    OsProbe.getInstance();
    JvmInfo.jvmInfo();
}
 
示例25
private void maybeLogHeapDetails() {
    JvmInfo jvmInfo = JvmInfo.jvmInfo();
    ByteSizeValue maxHeapSize = jvmInfo.getMem().getHeapMax();
    String useCompressedOops = jvmInfo.useCompressedOops();
    logger.info("heap size [{}], compressed ordinary object pointers [{}]", maxHeapSize, useCompressedOops);
}
 
示例26
long getInitialHeapSize() {
    return JvmInfo.jvmInfo().getConfiguredInitialHeapSize();
}
 
示例27
long getMaxHeapSize() {
    return JvmInfo.jvmInfo().getConfiguredMaxHeapSize();
}
 
示例28
String getVmName() {
    return JvmInfo.jvmInfo().getVmName();
}
 
示例29
String getUseSerialGC() {
    return JvmInfo.jvmInfo().useSerialGC();
}
 
示例30
String onError() {
    return JvmInfo.jvmInfo().onError();
}