1

The usecase

We got multiple changelogs stored in the database, and want to create a histogram monitoring the duration between changes.

The problem

There doesn't seem to be a way to set the start time of a Historgram.Timer, e.g we want to set it to lastUpdated given the current changelog.

Avenues of approach

1 Subclassing Histogram

Should work. However the java-lib use protected/package-private extensively, thus making it hard without copying large portions of the library.

2 Using reflection

After a Histogram.Timer is created it should be possible to use reflection to set the start field. The field is marked as private final, and thus a SecurityManager could stop us in some environments.

Ideas?

Neither of the solutions seems like the correct way to go, and I suspect that I'm overlooking a simpler solution (but could find anything at SO or google). We're using grafana to visualize our metrics, if thats at all helpful in this scenario.

Community
  • 1
  • 1
atomman
  • 2,510
  • 1
  • 16
  • 27

1 Answers1

2

You don't need to subclass Histogram, as you don't need to use Histogram.Timer only because your histogram is measuring times.

Simply call myHistogram.observe(System.now() - lastUpdated) every time you record a new change in the database.

Alin Sînpălean
  • 8,774
  • 1
  • 25
  • 29
  • Thx, I actually figured it out after posting, but forgot to close this post. Anyways, I'll leave the post her now. – atomman Sep 20 '18 at 08:06