mirror of
https://github.com/Graylog2/graylog2-server.git
synced 2026-03-13 09:32:21 +08:00
Code cleanup around opensearch process info (#15709)
* Code cleanup around opensearch process info * Code cleanup * fixed naming and test * fixed test * fixed test * code cleanup * code cleanup
This commit is contained in:
@@ -16,6 +16,5 @@
|
||||
*/
|
||||
package org.graylog.datanode.process;
|
||||
|
||||
public record ProcessInfo(long pid, String nodeName, ProcessState status, boolean isLeaderNode, java.time.Instant started, java.time.Duration totalCpuDuration, String user,
|
||||
String restBaseUrl) {
|
||||
public record OpensearchInfo(String nodeName, ProcessState state, boolean isLeaderNode, String restBaseUrl, ProcessInformation process) {
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Graylog, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the Server Side Public License, version 1,
|
||||
* as published by MongoDB, Inc.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* Server Side Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the Server Side Public License
|
||||
* along with this program. If not, see
|
||||
* <http://www.mongodb.com/licensing/server-side-public-license>.
|
||||
*/
|
||||
package org.graylog.datanode.process;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public record ProcessInformation(long pid, boolean alive, Instant started) {
|
||||
|
||||
public static ProcessInformation empty() {
|
||||
return new ProcessInformation(-1, false, null);
|
||||
}
|
||||
|
||||
public static ProcessInformation create(Process p) {
|
||||
return new ProcessInformation(p.pid(), p.isAlive(), p.info().startInstant().orElse(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Graylog, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the Server Side Public License, version 1,
|
||||
* as published by MongoDB, Inc.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* Server Side Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the Server Side Public License
|
||||
* along with this program. If not, see
|
||||
* <http://www.mongodb.com/licensing/server-side-public-license>.
|
||||
*/
|
||||
package org.graylog.datanode.process;
|
||||
|
||||
import org.apache.commons.exec.ExecuteWatchdog;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WatchdogWithProcessInfo extends ExecuteWatchdog {
|
||||
|
||||
private Process process;
|
||||
|
||||
public WatchdogWithProcessInfo(long timeout) {
|
||||
super(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void start(Process processToMonitor) {
|
||||
super.start(processToMonitor);
|
||||
this.process = processToMonitor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ProcessInformation processInfo() {
|
||||
return Optional.ofNullable(process)
|
||||
.map(ProcessInformation::create)
|
||||
.orElse(ProcessInformation.empty());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user