-
Notifications
You must be signed in to change notification settings - Fork 58
[monitoring] Impl metrics #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6fc7e1a
e3e6b72
8a8f2ed
db3326b
ac017c0
1521e64
69d2b66
b9e11f1
ead37d6
9539a50
8dbfabd
3b8bd42
e8be6d2
6faac11
9d19bdf
cc30055
f3993bf
f99f1b5
a440ace
7568a41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.clickhouse.kafka.connect.util.jmx; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| /** | ||
| * Not thread-safe Simple Moving Average implementation. | ||
| * This class accumulates sum of values and calculates average on demand. | ||
| * Values are stored in circular buffer to guarantee only last N values are used. | ||
| * It is needed to keep metric responsive after long periods of measurement. | ||
| * | ||
| */ | ||
| public class SimpleMovingAverage { | ||
|
|
||
| public static final int DEFAULT_WINDOW_SIZE = 60; | ||
|
|
||
| private final long[] values; | ||
| private final AtomicInteger head; | ||
| private final AtomicLong sum; | ||
|
|
||
| public SimpleMovingAverage(int numOfValues) { | ||
| this.values = new long[numOfValues]; | ||
| this.head = new AtomicInteger(); | ||
| this.sum = new AtomicLong(); | ||
| } | ||
|
|
||
| public void add(long value) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain the logic here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getting index where to write a new value It is what I think you are suggesting. The oldest element is that we are going to replace.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it is - just let's explain the algoritim in source code (for future referance) |
||
| int insertIndex = head.getAndIncrement() % values.length; | ||
| // update sum by subtracting the oldest value (at insertIndex) and adding new value. | ||
| sum.addAndGet(value - values[insertIndex]); | ||
| values[insertIndex] = value; | ||
| } | ||
|
|
||
| public double get() { | ||
| return (double) sum.get() / values.length; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know where the timestamp comes from? Record metadata, or when created, just want to validate since we can have clock skew in some siuations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will find out.
As for time skew - this would be a problem. But it can be normalized I think if skew stays in the range.