Karaf CLI Cheatsheet

karaf
faq
cli
troubleshooting

#1

OpenNMS OSGi and Karaf

The OpenNMS project refactors legacy plain Java components into smaller modules which run in a Karaf OSGi container instead of a plain JVM. The Karaf container itself comes with a Karaf shell which can be accessed over SSH. During refactoring and development, the project introduces Karaf commands which help to diagnose and test features in OpenNMS. This Cheatsheet Post is a collection of useful Karaf commands and can be edited by any user.

Generic Commands

Accessing the Karaf Shell

By default, the shell is bound to port 8101/8201/8301 on the loopback address of the server. It uses the same authentication subsystem. On the OpenNMS server itself it allows only users with the ADMIN role to log-in.

Horizon:

ssh -p 8101 admin@localhost

Minion:

ssh -p 8201 admin@localhost

Sentinel:

ssh -p 8301 admin@localhost

:zap: If you have an older version of OpenNMS please see here: Can't connect to Karaf Shell with SSH

List all available Monitors which are installed and can be used in Pollerd

admin@opennms> poller:list-monitors

List all available Collectors which are installed and can be used in Collectd

admin@minion> collection:list-collectors

Run a specific collector against a node and IP interface manually

The location is used to collect the metrics for a host over a Minion. When location Default is used the collection is made from the OpenNMS Horizon instance. The Node ID -n is used identify which metrics need to be collected related to the data collection configuration.

admin@opennms> collect -l Default -n 120 org.opennms.netmgt.collectd.SnmpCollector 172.24.23.104

Just show the content of the karaf.log without following

admin@opennms> log:display

Show and follow the karaf.log file

admin@opennms> log:tail

Show the configured log level

admin@minion> log:get
Logger                              | Level
------------------------------------+------
ROOT                                | WARN
org.apache.aries.spifly             | WARN
org.apache.karaf.jaas.modules.audit | INFO
org.apache.sshd                     | INFO

Just show log entries in log level ERROR

admin@minion> log:display | grep ERROR

Show all started Karaf features (case insensitive)

admin@minion> feature:list | grep -i "started"

Execute bash command from Karaf

:radioactive: Make sure you run commands which ends otherwise you have to exit the Karaf shell to exit the shell command.

admin@opennms> shell:exec ping -c 5 www.google.de

Display health metrics for Events, Flows, Minion Heartbeats

The count value is increased when messages are received from a listener and are forwarded off to a a message queue.

admin@opennms> health:metrics-display
Metric set:
Eventd (Metrics related to event throughput and timings)
1/26/19 1:43:43 PM =============================================================

-- Gauges ----------------------------------------------------------------------
eventlogs.queued
             value = 0
eventutil.cache.avgloadpenalty
             value = 3548000.227272727
eventutil.cache.capacity
             value = 1000
eventutil.cache.evictioncount
             value = 0
eventutil.cache.size
             value = 44

-- Histograms ------------------------------------------------------------------
eventlogs.sizes
             count = 23742
               min = 1
               max = 1
              mean = 1.00
            stddev = 0.00
            median = 1.00
              75% <= 1.00
              95% <= 1.00
              98% <= 1.00
              99% <= 1.00
            99.9% <= 1.00

-- Meters ----------------------------------------------------------------------
events.process.broadcast
             count = 7914
         mean rate = 0.09 events/second
     1-minute rate = 0.16 events/second
     5-minute rate = 0.10 events/second
    15-minute rate = 0.09 events/second

-- Timers ----------------------------------------------------------------------
eventlogs.process
             count = 7914
         mean rate = 0.09 calls/second
     1-minute rate = 0.16 calls/second
     5-minute rate = 0.10 calls/second
    15-minute rate = 0.09 calls/second
               min = 0.09 milliseconds
               max = 394.41 milliseconds
              mean = 0.13 milliseconds
            stddev = 0.04 milliseconds
            median = 0.11 milliseconds
              75% <= 0.13 milliseconds
              95% <= 0.25 milliseconds
              98% <= 0.25 milliseconds
              99% <= 0.26 milliseconds
            99.9% <= 0.26 milliseconds
eventlogs.process.broadcast
             count = 7914
         mean rate = 0.09 calls/second
     1-minute rate = 0.16 calls/second
     5-minute rate = 0.10 calls/second
    15-minute rate = 0.09 calls/second
               min = 0.01 milliseconds
               max = 4.16 milliseconds
              mean = 0.05 milliseconds
            stddev = 0.04 milliseconds
            median = 0.04 milliseconds
              75% <= 0.04 milliseconds
              95% <= 0.18 milliseconds
              98% <= 0.18 milliseconds
              99% <= 0.18 milliseconds
            99.9% <= 0.18 milliseconds
eventlogs.process.expand
             count = 7914
         mean rate = 0.09 calls/second
     1-minute rate = 0.16 calls/second
     5-minute rate = 0.10 calls/second
    15-minute rate = 0.09 calls/second
               min = 0.02 milliseconds
               max = 15.59 milliseconds
              mean = 0.04 milliseconds
            stddev = 0.00 milliseconds
            median = 0.04 milliseconds
              75% <= 0.04 milliseconds
              95% <= 0.05 milliseconds
              98% <= 0.05 milliseconds
              99% <= 0.05 milliseconds
            99.9% <= 0.05 milliseconds
eventlogs.process.write
             count = 334
         mean rate = 0.00 calls/second
     1-minute rate = 0.00 calls/second
     5-minute rate = 0.00 calls/second
    15-minute rate = 0.00 calls/second
               min = 9.16 milliseconds
               max = 394.32 milliseconds
              mean = 42.96 milliseconds
            stddev = 2.73 milliseconds
            median = 43.26 milliseconds
              75% <= 43.26 milliseconds
              95% <= 43.26 milliseconds
              98% <= 43.26 milliseconds
              99% <= 43.26 milliseconds
            99.9% <= 43.26 milliseconds
Metric set:
Flow (Consolidated metrics for all telemetry adapters processing flows)
1/26/19 1:43:43 PM =============================================================

Show actual configurations

The config:list command will give you all actual configurations. Default configurations are not shown. You can filter with a PID with the following syntax: config:list "(service.pid=<config-pid>)".

admin@opennms> config:list

Horizon Commands

Test a service manually

The location is used to access the tested host over a Minion. When location Default is used the test is executed from the OpenNMS Horizon instance.

admin@opennms> poller:poll --location Default org.opennms.netmgt.poller.monitors.IcmpMonitor 192.168.1.200

Service is Up on 192.168.1.200 using org.opennms.netmgt.poller.monitors.IcmpMonitor:
	response-time: 923.0000

Show current ElasticSearch configuration

config:list "(service.pid=org.opennms.features.flows.persistence.elastic)"

Show all detectors in Provisiond

provision:list-detectors

Run a HTTPS detector manually

provision:detect HTTPS www.google.com
Trying to detect 'HTTPS' on 'www.google.com'
'HTTPS' WAS detected on www.google.com

Minion Commands

Test communication to Horizon

admin@minion> health:check
Verifying the health of the container

Connecting to OpenNMS ReST API                                                              [ Success  ]
Verifying installed bundles                                                                 [ Success  ]
Connecting to Kafka from RPC                                                                [ Success  ]
Connecting to Kafka from Sink                                                               [ Success  ]
Verifying Listener SFlow-UDP-6343 (org.opennms.netmgt.telemetry.listeners.sflow.Listener)   [ Success  ]

=> Everything is awesome

Show Minion configuration

admin@minion> config:list "(service.pid=org.opennms.minion.controller)"
----------------------------------------------------------------
Pid:            org.opennms.minion.controller
BundleLocation: ?
Properties:
   broker-url = tcp://127.0.0.1:61616
   felix.fileinstall.filename = file:/opt/minion/etc/org.opennms.minion.controller.cfg
   http-url = http://172.24.23.100:8980/opennms
   id = eu-de-hn-office-minion-01
   location = eu-de-hn-office
   service.pid = org.opennms.minion.controller

Accessing the Karaf shell