org.elasticsearch.monitor.os.OsStats Java Examples

The following examples show how to use org.elasticsearch.monitor.os.OsStats. 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: NodeStats.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: SystemMonitorTarget.java    From fess with Apache License 2.0 6 votes vote down vote up
private void appendOsStats(final StringBuilder buf) {
    buf.append("\"os\":{");
    final OsProbe osProbe = OsProbe.getInstance();
    buf.append("\"memory\":{");
    buf.append("\"physical\":{");
    append(buf, "free", () -> osProbe.getFreePhysicalMemorySize()).append(',');
    append(buf, "total", () -> osProbe.getTotalPhysicalMemorySize());
    buf.append("},");
    buf.append("\"swap_space\":{");
    append(buf, "free", () -> osProbe.getFreeSwapSpaceSize()).append(',');
    append(buf, "total", () -> osProbe.getTotalSwapSpaceSize());
    buf.append('}');
    buf.append("},");
    buf.append("\"cpu\":{");
    append(buf, "percent", () -> osProbe.getSystemCpuPercent());
    final OsStats osStats = osProbe.osStats();
    buf.append("},");
    append(buf, "load_averages", () -> osStats.getCpu().getLoadAverage());
    buf.append("},");
}
 
Example #3
Source File: GraphiteReporter.java    From elasticsearch-graphite-plugin with Do What The F*ck You Want To Public License 6 votes vote down vote up
private void sendNodeOsStats(OsStats osStats) {
    String type = buildMetricName("node.os");

    if (osStats.cpu() != null) {
        sendInt(type + ".cpu", "sys", osStats.cpu().sys());
        sendInt(type + ".cpu", "idle", osStats.cpu().idle());
        sendInt(type + ".cpu", "user", osStats.cpu().user());
    }

    if (osStats.mem() != null) {
        sendInt(type + ".mem", "freeBytes", osStats.mem().free().bytes());
        sendInt(type + ".mem", "usedBytes", osStats.mem().used().bytes());
        sendInt(type + ".mem", "freePercent", osStats.mem().freePercent());
        sendInt(type + ".mem", "usedPercent", osStats.mem().usedPercent());
        sendInt(type + ".mem", "actualFreeBytes", osStats.mem().actualFree().bytes());
        sendInt(type + ".mem", "actualUsedBytes", osStats.mem().actualUsed().bytes());
    }

    if (osStats.swap() != null) {
        sendInt(type + ".swap", "freeBytes", osStats.swap().free().bytes());
        sendInt(type + ".swap", "usedBytes", osStats.swap().used().bytes());
    }
}
 
Example #4
Source File: NodeStatsContextFieldResolverTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws UnknownHostException {
    final OsService osService = mock(OsService.class);
    final OsStats osStats = mock(OsStats.class);
    final MonitorService monitorService = mock(MonitorService.class);

    when(monitorService.osService()).thenReturn(osService);
    when(osService.stats()).thenReturn(osStats);
    DiscoveryNode discoveryNode = newNode("node_name", "node_id");

    postgresAddress = new TransportAddress(Inet4Address.getLocalHost(), 5432);
    resolver = new NodeStatsContextFieldResolver(
        () -> discoveryNode,
        monitorService,
        () -> null,
        () -> new HttpStats(20L, 30L),
        mock(ThreadPool.class),
        new ExtendedNodeInfo(),
        () -> new ConnectionStats(2L, 4L),
        () -> postgresAddress,
        () -> 12L,
        () -> 1L
    );
}
 
Example #5
Source File: NodeMemoryExpression.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public NodeMemoryExpression(final OsStats stats) {
    addChildImplementations(stats.getMem());
    childImplementations.put(PROBE_TIMESTAMP, new SysNodeExpression<Long>() {
        @Override
        public Long value() {
            return stats.getTimestamp();
        }
    });
}
 
Example #6
Source File: NodeMemoryExpression.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void addChildImplementations(final OsStats.Mem mem) {
    childImplementations.put(FREE, new MemoryExpression() {
        @Override
        public Long value() {
            if (mem != null) {
                return mem.getFree().bytes();
            }
            return -1L;
        }
    });
    childImplementations.put(USED, new MemoryExpression() {
        @Override
        public Long value() {
            if (mem != null) {
                return mem.getUsed().bytes();
            }
            return -1L;
        }
    });
    childImplementations.put(FREE_PERCENT, new MemoryExpression() {
        @Override
        public Short value() {
            if (mem != null) {
                return mem.getFreePercent();
            }
            return -1;
        }
    });
    childImplementations.put(USED_PERCENT, new MemoryExpression() {
        @Override
        public Short value() {
            if (mem != null) {
                return mem.getUsedPercent();
            }
            return -1;
        }
    });
}
 
Example #7
Source File: NodeStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@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());

}
 
Example #8
Source File: PrometheusMetricsCollector.java    From elasticsearch-prometheus-exporter with Apache License 2.0 5 votes vote down vote up
private void updateOsMetrics(OsStats os) {
    if (os != null) {
        if (os.getCpu() != null) {
            catalog.setNodeGauge("os_cpu_percent", os.getCpu().getPercent());
            double[] loadAverage = os.getCpu().getLoadAverage();
            if (loadAverage != null && loadAverage.length == 3) {
                catalog.setNodeGauge("os_load_average_one_minute", os.getCpu().getLoadAverage()[0]);
                catalog.setNodeGauge("os_load_average_five_minutes", os.getCpu().getLoadAverage()[1]);
                catalog.setNodeGauge("os_load_average_fifteen_minutes", os.getCpu().getLoadAverage()[2]);
            }
        }

        if (os.getMem() != null) {
            catalog.setNodeGauge("os_mem_free_bytes", os.getMem().getFree().getBytes());
            catalog.setNodeGauge("os_mem_free_percent", os.getMem().getFreePercent());
            catalog.setNodeGauge("os_mem_used_bytes", os.getMem().getUsed().getBytes());
            catalog.setNodeGauge("os_mem_used_percent", os.getMem().getUsedPercent());
            catalog.setNodeGauge("os_mem_total_bytes", os.getMem().getTotal().getBytes());
        }

        if (os.getSwap() != null) {
            catalog.setNodeGauge("os_swap_free_bytes", os.getSwap().getFree().getBytes());
            catalog.setNodeGauge("os_swap_used_bytes", os.getSwap().getUsed().getBytes());
            catalog.setNodeGauge("os_swap_total_bytes", os.getSwap().getTotal().getBytes());
        }
    }
}
 
Example #9
Source File: NodeStatsContext.java    From crate with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #10
Source File: ExtendedOsStats.java    From crate with Apache License 2.0 5 votes vote down vote up
public ExtendedOsStats(long timestamp, Cpu cpu, double[] load, long uptime, OsStats osStats) {
    this.timestamp = timestamp;
    this.cpu = cpu;
    this.loadAverage = load;
    this.uptime = uptime;
    this.osStats = osStats;
}
 
Example #11
Source File: ExtendedOsStats.java    From crate with Apache License 2.0 5 votes vote down vote up
public ExtendedOsStats(StreamInput in) throws IOException {
    timestamp = in.readLong();
    uptime = in.readLong();
    loadAverage = in.readDoubleArray();
    cpu = in.readOptionalWriteable(Cpu::new);
    osStats = in.readOptionalWriteable(OsStats::new);
}
 
Example #12
Source File: ExtendedNodeInfo.java    From crate with Apache License 2.0 5 votes vote down vote up
private ExtendedOsStats osStatsProbe() {
    OsStats osStats = OsProbe.getInstance().osStats();
    OsStats.Cpu cpuProbe = osStats.getCpu();
    ExtendedOsStats.Cpu cpu = new ExtendedOsStats.Cpu(cpuProbe.getPercent());
    return new ExtendedOsStats(
        System.currentTimeMillis(),
        cpu,
        cpuProbe.getLoadAverage() == null ? NA_LOAD : cpuProbe.getLoadAverage(),
        SysInfo.getSystemUptime(),
        osStats);
}
 
Example #13
Source File: NodeStats.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Operating System level statistics.
 */
@Nullable
public OsStats getOs() {
    return this.os;
}
 
Example #14
Source File: OsStatsMonitor.java    From Raigad with Apache License 2.0 4 votes vote down vote up
@Override
public void execute() throws Exception {

    // If Elasticsearch is started then only start the monitoring
    if (!ElasticsearchProcessMonitor.isElasticsearchRunning()) {
        String exceptionMsg = "Elasticsearch is not yet started, check back again later";
        logger.info(exceptionMsg);
        return;
    }

    OsStatsBean osStatsBean = new OsStatsBean();
    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("OS stats is not available (node stats is not available)");
            return;
        }

        OsStats osStats = nodeStats.getOs();
        if (osStats == null) {
            logger.info("OS stats is not available");
            return;
        }

        //Memory
        osStatsBean.freeInBytes = osStats.getMem().getFree().getBytes();
        osStatsBean.usedInBytes = osStats.getMem().getUsed().getBytes();
        osStatsBean.actualFreeInBytes = osStats.getMem().getFree().getBytes();
        osStatsBean.actualUsedInBytes = osStats.getMem().getUsed().getBytes();
        osStatsBean.freePercent = osStats.getMem().getFreePercent();
        osStatsBean.usedPercent = osStats.getMem().getUsedPercent();

        //CPU
        osStatsBean.cpuSys = osStats.getCpu().getPercent();
        osStatsBean.cpuUser = 0;
        osStatsBean.cpuIdle = 0;
        osStatsBean.cpuStolen = 0;

        //Swap
        osStatsBean.swapFreeInBytes = osStats.getSwap().getFree().getBytes();
        osStatsBean.swapUsedInBytes = osStats.getSwap().getUsed().getBytes();

        //Uptime
        osStatsBean.uptimeInMillis = 0;

        //Timestamp
        osStatsBean.osTimestamp = osStats.getTimestamp();
    } catch (Exception e) {
        logger.warn("Failed to load OS stats data", e);
    }

    osStatsReporter.osStatsBean.set(osStatsBean);
}
 
Example #15
Source File: NodeStatsContext.java    From crate with Apache License 2.0 4 votes vote down vote up
public OsStats osStats() {
    return osStats;
}
 
Example #16
Source File: ExtendedOsStats.java    From crate with Apache License 2.0 4 votes vote down vote up
public OsStats osStats() {
    return osStats;
}