2

Im running a little web api and want to include some logging methods for debugging purposes. Therfor, i want to include http calls returning information like "api calls per hour", "successfull calls vs unseccessfull calls" and so on.

I searched the internet but didnt found lots of information about that topic. Can anyone provide me with a good source or strategie for doing that?

danijoo
  • 2,823
  • 4
  • 23
  • 43
  • You can implement this with `Filter` and custom counters/monitors. – Sotirios Delimanolis Aug 16 '13 at 15:36
  • @SotiriosDelimanolis I won't go easy on this. While the `Filter` will get before the servlet in the process chain, the counters won't be easy to maintain, remember that both filters and servlets are used in a multi thread environment. More info: [How do servlets work? Instantiation, session variables and multithreading](http://stackoverflow.com/q/3106452/1065197). – Luiggi Mendoza Aug 16 '13 at 15:41
  • @LuiggiMendoza Yeah. In no way is this easy. For OP, this type of data is useful in [OAM](http://en.wikipedia.org/wiki/Operations,_administration_and_management). You can either maintain (with all the problems of synchronizing) the counters in memory (bad) or do it in database and let it handle it. – Sotirios Delimanolis Aug 16 '13 at 15:43

1 Answers1

0

You could use a servlet filter to log statistics. Here's an example.

David Levesque
  • 22,181
  • 8
  • 67
  • 82
  • There are two problems with the provided link: 1) It doesn't provide a counter per servlet instance (or URL) that supports multi thread. 2) To measure real time performance you must use `System.nanoTime` instead of `System.currentTimeMillis` since the former is more accurate. – Luiggi Mendoza Aug 16 '13 at 15:42
  • Thank you. This link seems to be really helpful as a scaffold to work on. – danijoo Aug 16 '13 at 17:38