11

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

MSR
  • 510
  • 3
  • 5
  • 13
  • Your question is not clear. Do you mean "a server process" or do you mean the server itself, when you say "server". It sounds like you mean the latter but the JMX answer (below) if written from the perspective of you meaning the former – oxbow_lakes Sep 10 '09 at 14:16
  • I'm sorry if that wasn't clear -- I'm talking about the whole server as I essentially want to know the health of the server for scaling purposes. The most important metric is network utilisation. – MSR Sep 10 '09 at 14:44
  • 2
    If network utilization is the most important metric, I'm not sure JMX will help you and I'd consider using Cacti and a Java API to read RDD datas. – Pascal Thivent Sep 10 '09 at 21:44

7 Answers7

3

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.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
2

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

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
SimonJ
  • 21,076
  • 1
  • 35
  • 50
2

Just want to throw RHQ (http://rhq-project.org/ ) in the mix :-)

Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
1

You could look into using the Ganglia monitoring tool. It uses XML for its data representation and so I imagine it would be fairly straightforward to access the data from Java, and there are the added advantages that it's been designed to be highly scaleable, with the potential to record server metrics across a large number of machines.

Adamski
  • 54,009
  • 15
  • 113
  • 152
0

Your best bet would probably look in /proc for all your systems resource usage /proc/cpuinfo and /proc/net/ are a good place to start.

nelsonslament
  • 537
  • 1
  • 9
  • 24
0

What's wrong with Runtime.exec("some command")?

Eamorr
  • 9,872
  • 34
  • 125
  • 209
-1

I am not sure if this would assist in your query. IMHO Cacti and Centreon seem to be too complex to invest time into for a requirement as simple as yours. There are simpler tools out there for server monitoring such as New Relic and SeaLion. SeaLion is the my current favourite. It gives simple default commands which cover most basic requirements (will probably cover yours as well). It's also extremely simple to setup and is free. You could try these out.

Benno
  • 5,640
  • 2
  • 26
  • 31
Kevin
  • 566
  • 2
  • 5
  • 13