Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Server Monitoring with Java [closed]

I'm trying to find a solution that allows me to monitor resource consumption of a server. Preferably, the metrics I'm wanting to obtain are network utilisation IO, and if possible CPU usage/load average and disk IO.

The only other requirement I have is that this information be obtainable by Java so it can be manipulated, and at least work on Linux (Fedora).

I've heard about a few monitoring tools but I'm just not sure of the best way of going about this. I would probably want to be gathering the information about every 30 seconds.

Thanks

Update: Just to re-iterate, I am referring to system-wide monitoring NOT Java specific monitoring. I just want to use Java to access to these metrics

like image 702
MSR Avatar asked Sep 10 '09 12:09

MSR


People also ask

What is Java performance monitoring?

By using a Java performance monitoring tool, you can use predefined metrics or custom metrics for databases, JVMs, and web servers—and automatically alert on problems. Include JVMs. It's useful to collect log data on JVM metrics to determine whether JVM resource use is impacting application performance.


2 Answers

You could choose to delegate the monitoring to a dedicated tool like Cacti, Centreon, or Zenoss but this might be a bit overkill for a single application.

For a simple solution, JMX might indeed be a better solution. As starting point, I suggest reading the following article: Monitoring Local and Remote Applications Using JMX 1.2 and JConsole. Then, have a look at Using JConsole to Monitor Applications, a very detailed article that shows how to use JConsole to access several core monitoring and management functionalities provided by the Java platform including:

  • Detect low memory
  • Enable or disable GC and class loading verbose tracing
  • Detect deadlocks
  • Control the log level of any loggers in an application
  • Access OS resources—Sun's platform extension
  • Manage an application's Managed Beans (MBeans)

But, AFAIK, JMX won't give you access to network IO so you might need a combination of these tools. Luckily, many tools (e.g. Cacti, SmokePing) use the RDD format that you can easily manipulate with Java APIs like JRobin or rdd4j.

like image 136
Pascal Thivent Avatar answered Sep 23 '22 02:09

Pascal Thivent


I'm growing fond of collectd, a modular C daemon focusing on monitoring (rather than graphing) with a multitude of plugins:

  • Read - the usual CPU, I/O, network, load, memory and JMX as well as some more interesting ones like the ability to monitor DNS requests by sniffing packets, monitor latency/connectivity, and 'tail' a logfile to monitor things like SSH login attempts or incoming emails
  • Write - send readings to a CSV file, remote host, RRDtool, Unix socket, webserver
  • Notify - via libnotify or email
  • Bindings - to Perl, Python and (most importantly for your purposes) Java

There would seem to be several options for getting metrics into your Java code:

  • in-process, using the aforementioned Java plugin to register a write callback to receive data from the various other plugins
  • over the network, by embedding jcollectd (a Java implementation of collectd's protocol) into your app
  • indirectly, by writing to a CSV or RRD file and using one of the various RRD implementations for Java
like image 44
SimonJ Avatar answered Sep 23 '22 02:09

SimonJ