1

I need to get the cpu usage of the current process using jsp.

My scenario is like when user navigate from one page to other I need to check the cpu utilization, memory usage of the process.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Santhosh
  • 19,616
  • 22
  • 63
  • 74
  • Duplicate of http://stackoverflow.com/questions/634580/cpu-load-from-java – skaffman Feb 04 '10 at 19:48
  • One difference to the similar issue is that the process running JSP may have very restricted rights. – Eric J. Feb 04 '10 at 19:53
  • @Eric J.: JSP runs at server machine, not at client machine. – BalusC Feb 04 '10 at 20:18
  • @BalusC: Yes, but it's good security practice to run internet-facing services with the minimum set of privileges they need to get the job done. I don't know what permissions are required to directly read CPU utilization, but I'm guessing it's more than the minimum to serve JSP pages. – Eric J. Feb 04 '10 at 20:25
  • 1
    @Eric J.: That's more an issue of JVM privileges at the host machine. You may indeed be prohibited from accessing this information at "3rd party" hosting. But at dedicated/colocated host this shouldn't be an issue. And this applies to Java in general, not just JSP. – BalusC Feb 04 '10 at 20:30

1 Answers1

1

If you want to do this on every request, also in production (although I highly question the need for this, it would only make it more CPU-expensive), then grab JMX. If you want to do this for testing/profiling purposes (which would make more sense), then grab a Java profiler.

As to the JSP-targeted question, JSP is just a Java based view technology. Raw Java code belongs in a real Java class. If you want to go for JMX, then you rather want to do this in a Filter which is mapped on the url-pattern of interest, e.g. *.jsp.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555