Java源码示例:org.elasticsearch.monitor.fs.FsInfo
示例1
@Override
public void readFrom(StreamInput in) throws IOException {
counts = Counts.readCounts(in);
int size = in.readVInt();
versions = new HashSet<>(size);
for (; size > 0; size--) {
versions.add(Version.readVersion(in));
}
os = OsStats.readOsStats(in);
process = ProcessStats.readStats(in);
jvm = JvmStats.readJvmStats(in);
fs = FsInfo.Path.readInfoFrom(in);
size = in.readVInt();
plugins = new HashSet<>(size);
for (; size > 0; size--) {
plugins.add(PluginInfo.readFromStream(in));
}
}
示例2
public NodeStats(DiscoveryNode node, long timestamp, @Nullable NodeIndicesStats indices,
@Nullable OsStats os, @Nullable ProcessStats process, @Nullable JvmStats jvm, @Nullable ThreadPoolStats threadPool,
@Nullable FsInfo fs, @Nullable TransportStats transport, @Nullable HttpStats http,
@Nullable AllCircuitBreakerStats breaker,
@Nullable ScriptStats scriptStats) {
super(node);
this.timestamp = timestamp;
this.indices = indices;
this.os = os;
this.process = process;
this.jvm = jvm;
this.threadPool = threadPool;
this.fs = fs;
this.transport = transport;
this.http = http;
this.breaker = breaker;
this.scriptStats = scriptStats;
}
示例3
private List<NodeStats> adjustNodesStats(List<NodeStats> nodesStats) {
BiFunction<DiscoveryNode, FsInfo.Path, FsInfo.Path> diskUsageFunction = this.diskUsageFunction;
if (diskUsageFunction == null) {
return nodesStats;
}
return nodesStats.stream().map(nodeStats -> {
final DiscoveryNode discoveryNode = nodeStats.getNode();
final FsInfo oldFsInfo = nodeStats.getFs();
return new NodeStats(
discoveryNode,
nodeStats.getTimestamp(),
new FsInfo(
oldFsInfo.getTimestamp(),
oldFsInfo.getIoStats(),
StreamSupport.stream(oldFsInfo.spliterator(), false)
.map(fsInfoPath -> diskUsageFunction.apply(discoveryNode, fsInfoPath))
.toArray(FsInfo.Path[]::new)
));
}).collect(Collectors.toList());
}
示例4
public void checkDiskSpace(FsService fsService) {
Path shardRootDataPath = shardPath().getRootDataPath();
FsInfo.Path fsPath = fsService.stats().getPath(shardRootDataPath.toString());
if (fsPath.getFree().bytes() < 10) {
throw new ElasticsearchException("the shard path {} is full, with total space {} and already used {}",
path.getDataPath().toString(), fsPath.getTotal().bytes(), fsPath.getTotal().bytes() - fsPath.getFree().bytes());
}
return;
}
示例5
public ClusterStatsNodes(ClusterStatsNodeResponse[] nodeResponses) {
this.counts = new Counts();
this.versions = new HashSet<>();
this.os = new OsStats();
this.jvm = new JvmStats();
this.fs = new FsInfo.Path();
this.plugins = new HashSet<>();
this.process = new ProcessStats();
Set<InetAddress> seenAddresses = new HashSet<>(nodeResponses.length);
for (ClusterStatsNodeResponse nodeResponse : nodeResponses) {
counts.addNodeInfo(nodeResponse.nodeInfo());
versions.add(nodeResponse.nodeInfo().getVersion());
process.addNodeStats(nodeResponse.nodeStats());
jvm.addNodeInfoStats(nodeResponse.nodeInfo(), nodeResponse.nodeStats());
plugins.addAll(nodeResponse.nodeInfo().getPlugins().getPluginInfos());
// now do the stats that should be deduped by hardware (implemented by ip deduping)
TransportAddress publishAddress = nodeResponse.nodeInfo().getTransport().address().publishAddress();
InetAddress inetAddress = null;
if (publishAddress.uniqueAddressTypeId() == 1) {
inetAddress = ((InetSocketTransportAddress) publishAddress).address().getAddress();
}
if (!seenAddresses.add(inetAddress)) {
continue;
}
os.addNodeInfoStats(nodeResponse.nodeInfo(), nodeResponse.nodeStats());
if (nodeResponse.nodeStats().getFs() != null) {
fs.add(nodeResponse.nodeStats().getFs().total());
}
}
}
示例6
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
timestamp = in.readVLong();
if (in.readBoolean()) {
indices = NodeIndicesStats.readIndicesStats(in);
}
if (in.readBoolean()) {
os = OsStats.readOsStats(in);
}
if (in.readBoolean()) {
process = ProcessStats.readProcessStats(in);
}
if (in.readBoolean()) {
jvm = JvmStats.readJvmStats(in);
}
if (in.readBoolean()) {
threadPool = ThreadPoolStats.readThreadPoolStats(in);
}
if (in.readBoolean()) {
fs = FsInfo.readFsInfo(in);
}
if (in.readBoolean()) {
transport = TransportStats.readTransportStats(in);
}
if (in.readBoolean()) {
http = HttpStats.readHttpStats(in);
}
breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in);
scriptStats = in.readOptionalStreamable(new ScriptStats());
}
示例7
private void updateFsMetrics(FsInfo fs) {
if (fs != null) {
catalog.setNodeGauge("fs_total_total_bytes", fs.getTotal().getTotal().getBytes());
catalog.setNodeGauge("fs_total_available_bytes", fs.getTotal().getAvailable().getBytes());
catalog.setNodeGauge("fs_total_free_bytes", fs.getTotal().getFree().getBytes());
if (fs.getMostDiskEstimate() != null) {
catalog.setNodeGauge("fs_most_usage_free_bytes", fs.getMostDiskEstimate().getFreeBytes(),
fs.getMostDiskEstimate().getPath());
catalog.setNodeGauge("fs_most_usage_total_bytes", fs.getMostDiskEstimate().getTotalBytes(),
fs.getMostDiskEstimate().getPath());
}
if (fs.getLeastDiskEstimate() != null) {
catalog.setNodeGauge("fs_least_usage_free_bytes", fs.getLeastDiskEstimate().getFreeBytes(),
fs.getLeastDiskEstimate().getPath());
catalog.setNodeGauge("fs_least_usage_total_bytes", fs.getLeastDiskEstimate().getTotalBytes(),
fs.getLeastDiskEstimate().getPath());
}
for (FsInfo.Path fspath : fs) {
String path = fspath.getPath();
String mount = fspath.getMount();
String type = fspath.getType();
catalog.setNodeGauge("fs_path_total_bytes", fspath.getTotal().getBytes(), path, mount, type);
catalog.setNodeGauge("fs_path_available_bytes", fspath.getAvailable().getBytes(), path, mount, type);
catalog.setNodeGauge("fs_path_free_bytes", fspath.getFree().getBytes(), path, mount, type);
}
FsInfo.IoStats ioStats = fs.getIoStats();
if (ioStats != null) {
catalog.setNodeGauge("fs_io_total_operations", fs.getIoStats().getTotalOperations());
catalog.setNodeGauge("fs_io_total_read_operations", fs.getIoStats().getTotalReadOperations());
catalog.setNodeGauge("fs_io_total_write_operations", fs.getIoStats().getTotalWriteOperations());
catalog.setNodeGauge("fs_io_total_read_bytes", fs.getIoStats().getTotalReadKilobytes() * 1024);
catalog.setNodeGauge("fs_io_total_write_bytes", fs.getIoStats().getTotalWriteKilobytes() * 1024);
}
}
}
示例8
public NodeStatsContext(StreamInput in, boolean complete) throws IOException {
this.complete = complete;
this.id = DataTypes.STRING.readValueFrom(in);
this.name = DataTypes.STRING.readValueFrom(in);
this.hostname = DataTypes.STRING.readValueFrom(in);
this.timestamp = in.readLong();
this.version = in.readBoolean() ? Version.readVersion(in) : null;
this.build = in.readBoolean() ? Build.readBuild(in) : null;
this.restUrl = DataTypes.STRING.readValueFrom(in);
this.pgPort = in.readOptionalVInt();
this.httpPort = in.readOptionalVInt();
this.transportPort = in.readOptionalVInt();
this.jvmStats = in.readOptionalWriteable(JvmStats::new);
this.osInfo = in.readOptionalWriteable(OsInfo::new);
this.processStats = in.readOptionalWriteable(ProcessStats::new);
this.osStats = in.readOptionalWriteable(OsStats::new);
this.fsInfo = in.readOptionalWriteable(FsInfo::new);
this.extendedOsStats = in.readOptionalWriteable(ExtendedOsStats::new);
this.threadPools = in.readOptionalWriteable(ThreadPoolStats::new);
this.httpStats = in.readOptionalWriteable(HttpStats::new);
this.psqlStats = in.readOptionalWriteable(ConnectionStats::new);
this.openTransportConnections = in.readLong();
this.clusterStateVersion = in.readLong();
this.osName = DataTypes.STRING.readValueFrom(in);
this.osArch = DataTypes.STRING.readValueFrom(in);
this.osVersion = DataTypes.STRING.readValueFrom(in);
this.javaVersion = DataTypes.STRING.readValueFrom(in);
this.jvmName = DataTypes.STRING.readValueFrom(in);
this.jvmVendor = DataTypes.STRING.readValueFrom(in);
this.jvmVersion = DataTypes.STRING.readValueFrom(in);
}
示例9
public FsInfo.Path getFs() {
return fs;
}
示例10
/**
* File system level stats.
*/
@Nullable
public FsInfo getFs() {
return fs;
}
示例11
@Override
public void execute() throws Exception {
// Only start monitoring if Elasticsearch is started
if (!ElasticsearchProcessMonitor.isElasticsearchRunning()) {
String exceptionMsg = "Elasticsearch is not yet started, check back again later";
logger.info(exceptionMsg);
return;
}
FsStatsBean fsStatsBean = new FsStatsBean();
try {
NodesStatsResponse nodesStatsResponse = ElasticsearchTransportClient.getNodesStatsResponse(config);
NodeStats nodeStats = null;
List<NodeStats> nodeStatsList = nodesStatsResponse.getNodes();
if (nodeStatsList.size() > 0) {
nodeStats = nodeStatsList.get(0);
}
if (nodeStats == null) {
logger.info("File system info is not available (node stats are not available)");
return;
}
FsInfo fsInfo = nodeStats.getFs();
if (fsInfo == null) {
logger.info("File system info is not available");
return;
}
fsStatsBean.total = fsInfo.getTotal().getTotal().getBytes();
fsStatsBean.free = fsInfo.getTotal().getFree().getBytes();
fsStatsBean.available = fsInfo.getTotal().getAvailable().getBytes();
fsStatsBean.availableDiskPercent = (fsStatsBean.available * 100) / fsStatsBean.total;
} catch (Exception e) {
logger.warn("Failed to load file system stats data", e);
}
fsStatsReporter.fsStatsBean.set(fsStatsBean);
}
示例12
public NodeStats(DiscoveryNode node, long timestamp, FsInfo fs) {
super(node);
this.timestamp = timestamp;
this.fs = fs;
}
示例13
public NodeStats(StreamInput in) throws IOException {
super(in);
timestamp = in.readVLong();
fs = in.readOptionalWriteable(FsInfo::new);
}
示例14
public FsInfo getFs() {
return fs;
}
示例15
public FsInfo fsInfo() {
return fsInfo;
}
示例16
public static String dev(FsInfo.Path path) {
return path.getMount() == null ? "" : path.getMount();
}
示例17
public static Long size(FsInfo.Path path) {
return path.getTotal().getBytes();
}
示例18
public static Long used(FsInfo.Path path) {
return path.getTotal().getBytes() == -1L || path.getAvailable().getBytes() == -1L ? -1L : path.getTotal().getBytes() - path.getAvailable().getBytes();
}
示例19
public static Long available(FsInfo.Path path) {
return path.getAvailable().getBytes();
}
示例20
public static Long readOperations(FsInfo.IoStats ioStats) {
if (ioStats != null) {
return ioStats.getTotalReadOperations();
}
return -1L;
}
示例21
public static Long bytesRead(FsInfo.IoStats ioStats) {
if (ioStats != null) {
return ioStats.getTotalReadKilobytes() * 1024L;
}
return -1L;
}
示例22
public static Long writeOperations(FsInfo.IoStats ioStats) {
if (ioStats != null) {
return ioStats.getTotalWriteOperations();
}
return -1L;
}
示例23
public static Long bytesWritten(FsInfo.IoStats ioStats) {
if (ioStats != null) {
return ioStats.getTotalWriteKilobytes() * 1024L;
}
return -1L;
}
示例24
private static FsInfo.Path setDiskUsage(FsInfo.Path original, long totalBytes, long freeBytes) {
return new FsInfo.Path(original.getPath(), original.getMount(), totalBytes, freeBytes, freeBytes);
}