Java Code Examples for org.elasticsearch.monitor.fs.FsInfo#Path

The following examples show how to use org.elasticsearch.monitor.fs.FsInfo#Path . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockInternalClusterInfoService.java    From crate with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 2
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: ClusterStatsNodes.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 4
Source File: PrometheusMetricsCollector.java    From elasticsearch-prometheus-exporter with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 5
Source File: ClusterStatsNodes.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public FsInfo.Path getFs() {
    return fs;
}
 
Example 6
Source File: FsInfoHelpers.java    From crate with Apache License 2.0 4 votes vote down vote up
public static String dev(FsInfo.Path path) {
    return path.getMount() == null ? "" : path.getMount();
}
 
Example 7
Source File: FsInfoHelpers.java    From crate with Apache License 2.0 4 votes vote down vote up
public static Long size(FsInfo.Path path) {
    return path.getTotal().getBytes();
}
 
Example 8
Source File: FsInfoHelpers.java    From crate with Apache License 2.0 4 votes vote down vote up
public static Long used(FsInfo.Path path) {
    return path.getTotal().getBytes() == -1L || path.getAvailable().getBytes() == -1L ? -1L : path.getTotal().getBytes() - path.getAvailable().getBytes();
}
 
Example 9
Source File: FsInfoHelpers.java    From crate with Apache License 2.0 4 votes vote down vote up
public static Long available(FsInfo.Path path) {
    return path.getAvailable().getBytes();
}
 
Example 10
Source File: DiskUsagesITest.java    From crate with Apache License 2.0 4 votes vote down vote up
private static FsInfo.Path setDiskUsage(FsInfo.Path original, long totalBytes, long freeBytes) {
    return new FsInfo.Path(original.getPath(), original.getMount(), totalBytes, freeBytes, freeBytes);
}