use of org.onosproject.nodemetrics.NodeCpuUsage in project onos by opennetworkinglab.
the class ShowNodeCpuUsageCommand method doExecute.
@Override
protected void doExecute() {
if (nodeId != null) {
NodeCpuUsage cpu = nodeService.cpu(NodeId.nodeId(nodeId));
if (Objects.nonNull(cpu)) {
print("CPU usage : %s ", cpu);
} else {
print("Node %s doesn't exists", nodeId);
}
} else {
Collection<NodeCpuUsage> cpu = nodeService.cpu().values();
printCpuUsage(cpu);
}
}
use of org.onosproject.nodemetrics.NodeCpuUsage in project onos by opennetworkinglab.
the class NodeMetricsManager method pollMetrics.
private void pollMetrics() {
try {
CpuPerc cpu = sigar.getCpuPerc();
Mem mem = sigar.getMem();
FileSystemUsage disk = sigar.getFileSystemUsage(SLASH);
NodeMemoryUsage memoryNode = new NodeMemoryUsage.Builder().free(mem.getFree()).used(mem.getUsed()).total(mem.getTotal()).withUnit(Units.BYTES).withNode(localNodeId).build();
NodeCpuUsage cpuNode = new NodeCpuUsage.Builder().withNode(localNodeId).usage(cpu.getCombined() * PERCENTAGE_MULTIPLIER).build();
NodeDiskUsage diskNode = new NodeDiskUsage.Builder().withNode(localNodeId).free(disk.getFree()).used(disk.getUsed()).withUnit(Units.KBYTES).total(disk.getTotal()).build();
diskStore.put(localNodeId, diskNode);
memoryStore.put(localNodeId, memoryNode);
cpuStore.put(localNodeId, cpuNode);
} catch (SigarException e) {
log.error("Exception occurred ", e);
}
}
use of org.onosproject.nodemetrics.NodeCpuUsage in project onos by opennetworkinglab.
the class NodeMetricsManager method activate.
@Activate
public void activate(ComponentContext context) {
appId = coreService.registerApplication("org.onosproject.nodemetrics");
cfgService.registerProperties(getClass());
metricsExecutor = Executors.newSingleThreadScheduledExecutor(Tools.groupedThreads("nodemetrics/pollingStatics", "statistics-executor-%d", log));
localNodeId = clusterService.getLocalNode().id();
KryoNamespace.Builder serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(NodeMemoryUsage.class).register(NodeDiskUsage.class).register(NodeCpuUsage.class).register(Units.class);
memoryStore = storageService.<NodeId, NodeMemoryUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, memory) -> clockService.getTimestamp()).withName("nodemetrics-memory").build();
diskStore = storageService.<NodeId, NodeDiskUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, disk) -> clockService.getTimestamp()).withName("nodemetrics-disk").build();
cpuStore = storageService.<NodeId, NodeCpuUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, cpu) -> clockService.getTimestamp()).withName("nodemetrics-cpu").build();
modified(context);
sigar = new Sigar();
pollMetrics();
}
Aggregations