Tutorial

You can use nats-top to monitor in realtime NATS server connections and message statistics.

Prerequisites

1. Install nats-top

go install github.com/nats-io/nats-top@latest

You may need to run the following instead:

sudo -E go install github.com/nats-io/nats-top

2. Start the NATS server with monitoring enabled

nats-server -m 8222

3. Start nats-top

nats-top

Result:

nats-server version 0.6.6 (uptime: 2m2s)
Server:
  Load: CPU:  0.0%  Memory: 6.3M  Slow Consumers: 0
  In:   Msgs: 0  Bytes: 0  Msgs/Sec: 0.0  Bytes/Sec: 0
  Out:  Msgs: 0  Bytes: 0  Msgs/Sec: 0.0  Bytes/Sec: 0

Connections: 0
  HOST                 CID      SUBS    PENDING     MSGS_TO     MSGS_FROM   BYTES_TO    BYTES_FROM  LANG     VERSION

4. Run NATS client programs

Run some NATS client programs and exchange messages.

For the best experience, you will want to run multiple subscribers, at least 2 or 3. Refer to the example pub-sub clients.

5. Check nats-top for statistics

6. Sort nats-top statistics

In nats-top, enter the command o followed by the option, such as bytes_to. You see that nats-top sorts the BYTES_TO column in ascending order.

7. Use different sort options

Use some different sort options to explore nats-top, such as:

cid, subs, pending, msgs_to, msgs_from, bytes_to, bytes_from, lang, version

You can also set the sort option on the command line using the -sort flag. For example: nats-top -sort bytes_to.

8. Display the registered subscriptions.

In nats-top, enter the command s to toggle displaying connection subscriptions. When enabled, you see the subscription subject in nats-top table:

9. Quit nats-top

Use the q command to quit nats-top.

10. Restart nats-top with a specified query

For example, to query for the connection with largest number of subscriptions:

Result: nats-top displays only the client connection with the largest number of subscriptions:

Last updated

Was this helpful?