-
Notifications
You must be signed in to change notification settings - Fork 324
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
Add basic metrics support #360
Conversation
93d1e42
to
156db92
Compare
84a8d05
to
49a0efd
Compare
Adds the following system metrics:
And some heap metrics:
|
@kuisathaverat Do you know why pipeline Jenkins does not like this PR? I probably confused it with my wild force pushes 😬 |
it looks like JENKINS-44598, probably is related to the force push, I never see it before. |
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.
Great!
Most importantly - used getNonHeapMemoryUsage
twice.
Other than that, I am really missing some documentation about central classes role and data structures.
And some cosmetic suggestions.
apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
public void serialize(long epochMicros, StringBuilder replaceBuilder, JsonWriter jw) { | ||
jw.writeByte(JsonWriter.OBJECT_START); |
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.
Same - serialization better be colocated
apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java
Show resolved
Hide resolved
import java.lang.management.MemoryUsage; | ||
import java.util.Collections; | ||
|
||
public class JvmMemoryMetrics implements LifecycleListener { |
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.
Not sure why this is a LifecycleListener if the MBeans are just registered on startup. Not very important but if there is no reason- consider changing.
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.
We already have the concept of LifecycleListener
s which provide a callback on application start and on shutdown. I did not create an SPI for metrics as I could just use the already existing one. If you think it would make things more clear, I can add a special SPI just for metrics.
* This implementation is based on io.micrometer.core.instrument.binder.system.ProcessorMetrics, | ||
* under Apache License 2.0 | ||
*/ | ||
public class SystemMetrics implements LifecycleListener { |
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.
Same- consider not making a listener. I assume it is enough that the metrics collected thread is shut down when required.
apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetrics.java
Outdated
Show resolved
Hide resolved
I have also added GC metrics:
|
I have manually checked that |
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.
Some minor comments-
- Suggesting small serialization-dependency erasure
- Can we remove
PayloadSender
? - It just occurred to me that the entire metrics harvesting is going to be done on the disruptor publishing thread. Do you think this may be problematic and be better done offline, so not to hold down other event publishing?
apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Override | ||
public String toString() { |
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.
Moving the serialization code to the serialize
package is great, so I think having this JsonWriter
residual here is a shame. Sorry for nagging, I have future refactors in mind...
What do you say adding a static asString(MetricsRegistry)
to the serializer?
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 you want to create a separate module for serialization?
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.
Not at the moment :)
I just think it makes sense to avoid dependency on serialization lib here.
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'm all about keeping package dependencies uni-directional!
registry.addUnlessNegative("jvm.gc.count", tags, new DoubleSupplier() { | ||
@Override | ||
public double get() { | ||
return garbageCollectorMXBean.getCollectionCount(); |
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.
What would be more interesting - collection count or collection count since last measurement? For graphs, an ever increasing one is not as informative as a mostly-stagnant one where spikes are easier to spot. This is something that can be calculated in the server or Kibana as well, but since it is not a global metric, I don't think it would be.
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.
It's quite common to report counters and use a derivative aggregation to graph the deltas.
registry.addUnlessNegative("jvm.gc.time", tags, new DoubleSupplier() { | ||
@Override | ||
public double get() { | ||
return garbageCollectorMXBean.getCollectionTime(); |
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.
same
I'd think that getting and serializing the metrics is not something that would hold down the reporter thread. I think the bottleneck there is the network anyway.
Do you have an idea how to do this without serializing the metrics to a buffer which becomes garbage afterwards and without establishing another connection to the APM Server? |
I am not talking about serialization, I am just talking about metrics collection from all MBeans. Anyway, as long as we don't have evidence that this is a problem - it is not. |
No description provided.