NjmonCollector

njmon collector Details

This is an alternative to the use of ssh to stream njmon data straight to a server to save as a file or to real-time inject into one of the databases like ELK, Splunk or InfluxDB. to inject using a Python program you will, of course, have to have Python 3 installed and find the matching Python client module for your database. The below diagram covers the basics that are detailed further below:

Examples starting the collector

  • /usr/local/bin/njmon_collector -p 8282 -d /home/njmon -X abcd1234

Notes:

  1. /usr/local/bin is a suitable place to put njmon_collector on my Ubuntu server
  2. -p 8282
    • This is the port that njmon connects too to make a socket connection. You choose the port number other might like 80, 8080, 8181
    • Use the same port number when starting njmon (see below)
    • The port is similar to that used in a web server.
    • njmon_collector started out as my nweb nano size 200 lines of C code web server to demo the principles.
    • nmon_collect cannot serve out files.
  3. -d /home/njmon
    • This is the directory where it will save the JSON files
    • Free free to use any directory you like.
    • You could make it a separate filesystem mount so filling it does no OS damage.
  4. -X abcd1234
    • This is the secret magic token/secret shared between njmon and njmon_collector. A shared secret is like a password.
    • When you start njmon you have to supply the same secret.
    • When njmon connect, the request is encrypted (nothing too fancy but will stop packet sniffing people reading it) and includes the hostname, time and this secret.
    • You can use any set of printable alpha-numeric characters you like (don't include spaces or tabs)
  5. Note there is another parameter needed to start injector - it is covered below (-i).
  6. njmon_collector disconnects from the user terminal session (some rookies will think it crashed) but this means it continues to run if you log out. This is normal daemon behaviour.

Now using njmon v12 and higher add some parameters to request it to connect to the njmon_collector

  • %blue/usr/lbin/njmon -s60 -c 1440 -p 8282 -i 9.137.62.10 -X abcd1234

Key:

  1. /usr/lbin/njmon This is a sensible directory for admin commands on AIX - it is up to you.
  2. -s 60
    • Save stats every 60 seconds (1 minute).
  3. -c 1440
    • Count of the number of snapshots you want.
  4. -p 8282
    • The port number you used when starting the njmon_collector (above)
  5. -i 9.137.62.10
    • This is the IP Address of the server running the njmon_collector (may add hostname support in a later release).
    • This 9.137.62.10 will NOT work for you!
    • If you don't know the hostname use ping to find it.
  6. -X abcd1234
    • As explained above this si the shared magic token/secret used to start the njmon_collector

Suitable crontab entry to start njmon once a day:

0 0 * * * /usr/lbin/njmon -s60 -c1440 -p 8282 -i 9.137.62.10 -X abcd1234

The above is enough to get the JSON file created and saved at the njmon_collector server in the directory named.

If you do not want to type the secret on the command line then you can set it in a shell script variable

  • export NJMON_SECRET=abcd1234

The njmon_collector saves the JSON files but can also run an injector program to load the data into your stats database of choice.

  • The injector it uses has to be placed at /usr/local/bin/injector.py and be executable. The injectors so far are written in Python hence the .py

and should automatically with a hashbang start the right program. Below highlights the extra flag you need to request the injector - njmon_collector -i Note: the JSON data is saved to file AND injected.

Collector Restart Warning

The collector is a cheap and cheerful solution for those not willing to set up ssh. If you want to start a new version of the collector then it might not be obvious but killing the collector will break the sockets to the njmon processes sending data! Two approaches:

  1. I start all the njmon commands on all the virtual machines via local cron at midnight and to run for 24 hours. So I stop and restart the collector at 5 minutes to midnight. Five minutes later new fresh njmon commands start and find the new collector
  2. An alternative is starting the new collector on a different port. For example, using 8181 and 8282. Then go round all the virtual machines and change the port number in the crontab setup they will use the new collector next time they are started. the following day I check no njmon is using the old port number and then kill the old collector.