Search in sources :

Example 1 with NodeMemoryUsage

use of org.onosproject.nodemetrics.NodeMemoryUsage in project onos by opennetworkinglab.

the class ShowNodeMemoryUsageCommand method doExecute.

@Override
protected void doExecute() {
    if (nodeId != null) {
        NodeMemoryUsage memory = nodeService.memory(NodeId.nodeId(nodeId));
        if (Objects.nonNull(memory)) {
            print("Memory usage : %s", memory.toString());
        } else {
            print("Node %s doesn't exists");
        }
    } else {
        Collection<NodeMemoryUsage> memory = nodeService.memory().values();
        printMemoryUsage(memory);
    }
}
Also used : NodeMemoryUsage(org.onosproject.nodemetrics.NodeMemoryUsage)

Example 2 with NodeMemoryUsage

use of org.onosproject.nodemetrics.NodeMemoryUsage 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);
    }
}
Also used : SigarException(org.hyperic.sigar.SigarException) NodeDiskUsage(org.onosproject.nodemetrics.NodeDiskUsage) Mem(org.hyperic.sigar.Mem) NodeCpuUsage(org.onosproject.nodemetrics.NodeCpuUsage) CpuPerc(org.hyperic.sigar.CpuPerc) FileSystemUsage(org.hyperic.sigar.FileSystemUsage) NodeMemoryUsage(org.onosproject.nodemetrics.NodeMemoryUsage)

Example 3 with NodeMemoryUsage

use of org.onosproject.nodemetrics.NodeMemoryUsage 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();
}
Also used : METRIC_POLL_FREQUENCY_SECONDS(org.onosproject.nodemetrics.impl.OsgiPropertyConstants.METRIC_POLL_FREQUENCY_SECONDS) ScheduledFuture(java.util.concurrent.ScheduledFuture) Tools(org.onlab.util.Tools) Mem(org.hyperic.sigar.Mem) CoreService(org.onosproject.core.CoreService) ComponentContext(org.osgi.service.component.ComponentContext) LoggerFactory(org.slf4j.LoggerFactory) Tools.getIntegerProperty(org.onlab.util.Tools.getIntegerProperty) KryoNamespace(org.onlab.util.KryoNamespace) METRIC_POLL_FREQUENCY_SECONDS_DEFAULT(org.onosproject.nodemetrics.impl.OsgiPropertyConstants.METRIC_POLL_FREQUENCY_SECONDS_DEFAULT) CpuPerc(org.hyperic.sigar.CpuPerc) NodeCpuUsage(org.onosproject.nodemetrics.NodeCpuUsage) Component(org.osgi.service.component.annotations.Component) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NodeDiskUsage(org.onosproject.nodemetrics.NodeDiskUsage) Activate(org.osgi.service.component.annotations.Activate) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) NodeId(org.onosproject.cluster.NodeId) SigarException(org.hyperic.sigar.SigarException) NodeMemoryUsage(org.onosproject.nodemetrics.NodeMemoryUsage) Logger(org.slf4j.Logger) FileSystemUsage(org.hyperic.sigar.FileSystemUsage) NodeMetricsService(org.onosproject.nodemetrics.NodeMetricsService) Deactivate(org.osgi.service.component.annotations.Deactivate) LogicalClockService(org.onosproject.store.service.LogicalClockService) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Modified(org.osgi.service.component.annotations.Modified) ClusterService(org.onosproject.cluster.ClusterService) Units(org.onosproject.nodemetrics.Units) Reference(org.osgi.service.component.annotations.Reference) Sigar(org.hyperic.sigar.Sigar) Dictionary(java.util.Dictionary) Sigar(org.hyperic.sigar.Sigar) NodeCpuUsage(org.onosproject.nodemetrics.NodeCpuUsage) NodeMemoryUsage(org.onosproject.nodemetrics.NodeMemoryUsage) KryoNamespace(org.onlab.util.KryoNamespace) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

NodeMemoryUsage (org.onosproject.nodemetrics.NodeMemoryUsage)3 CpuPerc (org.hyperic.sigar.CpuPerc)2 FileSystemUsage (org.hyperic.sigar.FileSystemUsage)2 Mem (org.hyperic.sigar.Mem)2 SigarException (org.hyperic.sigar.SigarException)2 NodeCpuUsage (org.onosproject.nodemetrics.NodeCpuUsage)2 NodeDiskUsage (org.onosproject.nodemetrics.NodeDiskUsage)2 Dictionary (java.util.Dictionary)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Sigar (org.hyperic.sigar.Sigar)1 KryoNamespace (org.onlab.util.KryoNamespace)1 Tools (org.onlab.util.Tools)1 Tools.getIntegerProperty (org.onlab.util.Tools.getIntegerProperty)1 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)1