public GetHostStatsAnswer(GetHostStatsCommand cmd, double cpuUtilization, double freeMemoryKBs, double totalMemoryKBs, double networkReadKBs, double networkWriteKBs, String entityType) { super(cmd); hostStats = new HostStatsEntry(); hostStats.setCpuUtilization(cpuUtilization); hostStats.setFreeMemoryKBs(freeMemoryKBs); hostStats.setTotalMemoryKBs(totalMemoryKBs); hostStats.setNetworkReadKBs(networkReadKBs); hostStats.setNetworkWriteKBs(networkWriteKBs); hostStats.setEntityType(entityType); }
@Override public double getCpuUtilization() { return hostStats.getCpuUtilization(); }
@Override public double getFreeMemoryKBs() { return hostStats.getFreeMemoryKBs(); }
public HostStatsEntry getHostStats(final Connection conn, final GetHostStatsCommand cmd, final String hostGuid, final long hostId) { final HostStatsEntry hostStats = new HostStatsEntry(hostId, 0, 0, 0, "host", 0, 0, 0, 0); final Object[] rrdData = getRRDData(conn, 1); // call rrd method with 1 hostStats.setNetworkReadKBs(getDataAverage(dataNode, col, numRows) / 1000); } else if (param.matches("pif_eth0_tx")) { hostStats.setNetworkWriteKBs(getDataAverage(dataNode, col, numRows) / 1000); } else if (param.contains("memory_total_kib")) { hostStats.setTotalMemoryKBs(getDataAverage(dataNode, col, numRows)); } else if (param.contains("memory_free_kib")) { hostStats.setFreeMemoryKBs(getDataAverage(dataNode, col, numRows)); } else if (param.matches("cpu_avg")) { hostStats.setCpuUtilization(hostStats.getCpuUtilization() + getDataAverage(dataNode, col, numRows));
/** * Sends host metrics to a configured InfluxDB host. The metrics respects the following specification.</br> * <b>Tags:</b>vm_id, uuid, instance_name, data_center_id, host_id</br> * <b>Fields:</b>memory_total_kb, memory_internal_free_kbs, memory_target_kbs, cpu_utilization, cpus, network_write_kb, disk_read_iops, disk_read_kbs, disk_write_iops, disk_write_kbs */ protected Point createInfluxDbPointForHostMetrics(Object metricsObject) { HostStatsEntry hostStatsEntry = (HostStatsEntry)metricsObject; Map<String, String> tagsToAdd = new HashMap<>(); tagsToAdd.put(UUID_TAG, hostStatsEntry.getHostVo().getUuid()); Map<String, Object> fieldsToAdd = new HashMap<>(); fieldsToAdd.put(TOTAL_MEMORY_KBS_FIELD, hostStatsEntry.getTotalMemoryKBs()); fieldsToAdd.put(FREE_MEMORY_KBS_FIELD, hostStatsEntry.getFreeMemoryKBs()); fieldsToAdd.put(CPU_UTILIZATION_FIELD, hostStatsEntry.getCpuUtilization()); fieldsToAdd.put(CPUS_FIELD, hostStatsEntry.getHostVo().getCpus()); fieldsToAdd.put(CPU_SOCKETS_FIELD, hostStatsEntry.getHostVo().getCpuSockets()); fieldsToAdd.put(NETWORK_READ_KBS_FIELD, hostStatsEntry.getNetworkReadKBs()); fieldsToAdd.put(NETWORK_WRITE_KBS_FIELD, hostStatsEntry.getNetworkWriteKBs()); return Point.measurement(INFLUXDB_HOST_MEASUREMENT).tag(tagsToAdd).time(System.currentTimeMillis(), TimeUnit.MILLISECONDS).fields(fieldsToAdd).build(); }
protected GetHostStatsAnswer() { hostStats = new HostStatsEntry(); }
@Override public double getNetworkWriteKBs() { return hostStats.getNetworkWriteKBs(); }
@Override public double getTotalMemoryKBs() { return hostStats.getTotalMemoryKBs(); }
@Override public double getNetworkReadKBs() { return hostStats.getNetworkReadKBs(); }
protected Answer execute(GetHostStatsCommand cmd) { try { Map<String, String> res = OvmHost.getPerformanceStats(_conn, _publicNetworkName); Double cpuUtil = Double.parseDouble(res.get("cpuUtil")); Double rxBytes = Double.parseDouble(res.get("rxBytes")); Double txBytes = Double.parseDouble(res.get("txBytes")); Double totalMemory = Double.parseDouble(res.get("totalMemory")); Double freeMemory = Double.parseDouble(res.get("freeMemory")); HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rxBytes, txBytes, "host", totalMemory, freeMemory, 0, 0); return new GetHostStatsAnswer(cmd, hostStats); } catch (Exception e) { s_logger.debug("Get host stats of " + cmd.getHostName() + " failed", e); return new Answer(cmd, false, e.getMessage()); } }
public Answer execute(GetHostStatsCommand cmd) { try { CloudstackPlugin cSp = new CloudstackPlugin(c); Map<String, String> stats = cSp.ovsDom0Stats(config .getAgentPublicNetworkName()); Double cpuUtil = Double.parseDouble(stats.get("cpu")); Double rxBytes = Double.parseDouble(stats.get("rx")); Double txBytes = Double.parseDouble(stats.get("tx")); Double totalMemory = Double.parseDouble(stats.get("total")); Double freeMemory = Double.parseDouble(stats.get("free")); HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rxBytes, txBytes, "host", totalMemory, freeMemory, 0, 0); return new GetHostStatsAnswer(cmd, hostStats); } catch (Exception e) { LOGGER.debug("Unable to get host stats for: " + cmd.getHostName(), e); return new Answer(cmd, false, e.getMessage()); } }
@Override public Answer execute(final GetHostStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { CPUStat cpuStat = libvirtComputingResource.getCPUStat(); MemStat memStat = libvirtComputingResource.getMemStat(); final double cpuUtil = cpuStat.getCpuUsedPercent(); final Pair<Double, Double> nicStats = libvirtComputingResource.getNicStats(libvirtComputingResource.getPublicBridgeName()); final HostStatsEntry hostStats = new HostStatsEntry(command.getHostId(), cpuUtil, nicStats.first() / 1024, nicStats.second() / 1024, "host", memStat.getTotal() / 1024, memStat.getAvailable() / 1024, 0, 0); return new GetHostStatsAnswer(command, hostStats); } }