-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Backend jmx metrics #64
Merged
Merged
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d46a39e
Start doing endpoint for jmx metrics
914360e
Merge branch 'master' into backend-jmx-metrics
a562c98
Merge branch 'master' into backend-jmx-metrics
f427d01
Added endpoint for getting jmx metric per broker
a24b218
Cluster jmx metrics sum endpoit added
90df65b
Added endpoints for cluster metrics and broker metrics
b320aa6
Cleared some code
319d027
Fixed jmxmetrics names
0c72e07
Changed to all values in metrics
e5c1bb8
Removed redundant imports
4e624c1
Renamed param constant
65bc33e
Merge branch 'master' into backend-jmx-metrics
40e21c4
Changed to calculate brokers and clusters metrics in one place
6035003
Removed redundant imports
bceb161
Fixed some mistakes
c64579c
Replaced multiple method usage into single
51a6a74
Fixed mulptiple call
b218600
Removed cluster level metrics, now only broker-level metrics in cluster
21ca9a0
Just small fixes
04ca14d
removed redundant variable
105ef89
Renamed method for cluster level metrics
4edc5f8
Fixed after PR and added sum for number cluster metrics by num and pe…
5beb6ae
Added metricdto object
5ef0269
Added list of metrics to enum
9b04938
Renames and optimizings
c81c51d
Renamed jmxmetrics objects param to metrics
3e212aa
Fixed some issues
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.provectus.kafka.ui.cluster.util; | ||
|
||
import com.provectus.kafka.ui.model.JmxMetric; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.pool2.KeyedObjectPool; | ||
|
@@ -10,10 +11,11 @@ | |
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import java.net.MalformedURLException; | ||
import java.util.Arrays; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
@Slf4j | ||
|
@@ -24,26 +26,46 @@ public class JmxClusterUtil { | |
|
||
private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://"; | ||
private static final String JMX_SERVICE_TYPE = "jmxrmi"; | ||
private static final String KAFKA_SERVER_PARAM = "kafka.server"; | ||
|
||
public static final String BYTES_IN_PER_SEC = "BytesInPerSec"; | ||
public static final String BYTES_OUT_PER_SEC = "BytesOutPerSec"; | ||
private static final String BYTES_IN_PER_SEC_MBEAN_OBJECT_NAME = "kafka.server:type=BrokerTopicMetrics,name=" + BYTES_IN_PER_SEC; | ||
private static final String BYTES_OUT_PER_SEC_MBEAN_OBJECT_NAME = "kafka.server:type=BrokerTopicMetrics,name=" + BYTES_OUT_PER_SEC; | ||
|
||
private static final List<String> attrNames = Arrays.asList("OneMinuteRate", "FiveMinuteRate", "FifteenMinuteRate"); | ||
public List<JmxMetric> getJmxMetrics(int jmxPort, String jmxHost) { | ||
String jmxUrl = JMX_URL + jmxHost + ":" + jmxPort + "/" + JMX_SERVICE_TYPE; | ||
List<JmxMetric> result = new ArrayList<>(); | ||
JMXConnector srv = null; | ||
try { | ||
srv = pool.borrowObject(jmxUrl); | ||
MBeanServerConnection msc = srv.getMBeanServerConnection(); | ||
var jmxMetrics = msc.queryNames(null, null).stream().filter(q -> q.getCanonicalName().startsWith(KAFKA_SERVER_PARAM)).collect(Collectors.toList()); | ||
jmxMetrics.forEach(j -> { | ||
JmxMetric metric = new JmxMetric(); | ||
metric.setCanonicalName(j.getCanonicalName()); | ||
metric.setValue(getJmxMetric(jmxPort, jmxHost, j.getCanonicalName())); | ||
result.add(metric); | ||
}); | ||
pool.returnObject(jmxUrl, srv); | ||
} catch (IOException ioe) { | ||
log.error("Cannot get jmxMetricsNames, {}", jmxUrl, ioe); | ||
closeConnectionExceptionally(jmxUrl, srv); | ||
} catch (Exception e) { | ||
log.error("Cannot get JmxConnection from pool, {}", jmxUrl, e); | ||
closeConnectionExceptionally(jmxUrl, srv); | ||
} | ||
return result; | ||
} | ||
|
||
public Map<String, Number> getJmxTrafficMetrics(int jmxPort, String jmxHost, String metricName) { | ||
private Map<String, Object> getJmxMetric(int jmxPort, String jmxHost, String canonicalName) { | ||
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. Why object here? |
||
String jmxUrl = JMX_URL + jmxHost + ":" + jmxPort + "/" + JMX_SERVICE_TYPE; | ||
Map<String, Number> result = new HashMap<>(); | ||
|
||
Map<String, Object> resultAttr = new HashMap<>(); | ||
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. I think it's better to collect metrics once, instead of doing it cluster-wide and then per broker |
||
JMXConnector srv = null; | ||
try { | ||
srv = pool.borrowObject(jmxUrl); | ||
MBeanServerConnection msc = srv.getMBeanServerConnection(); | ||
ObjectName name = metricName.equals(BYTES_IN_PER_SEC) ? new ObjectName(BYTES_IN_PER_SEC_MBEAN_OBJECT_NAME) : | ||
new ObjectName(BYTES_OUT_PER_SEC_MBEAN_OBJECT_NAME); | ||
for (String attrName : attrNames) { | ||
Number value = (Number) msc.getAttribute(name, attrName); | ||
result.put(attrName, value instanceof Double ? BigDecimal.valueOf((Double) value) : Integer.valueOf(value.toString())); | ||
|
||
ObjectName name = new ObjectName(canonicalName); | ||
var attrNames = msc.getMBeanInfo(name).getAttributes(); | ||
for (MBeanAttributeInfo attrName : attrNames) { | ||
resultAttr.put(attrName.getName(), msc.getAttribute(name, attrName.getName())); | ||
} | ||
pool.returnObject(jmxUrl, srv); | ||
} catch (MalformedURLException url) { | ||
|
@@ -62,7 +84,7 @@ public Map<String, Number> getJmxTrafficMetrics(int jmxPort, String jmxHost, Str | |
log.error("Error while retrieving connection {} from pool", jmxUrl); | ||
closeConnectionExceptionally(jmxUrl, srv); | ||
} | ||
return result; | ||
return resultAttr; | ||
} | ||
|
||
private void closeConnectionExceptionally(String url, JMXConnector srv) { | ||
|
@@ -72,4 +94,12 @@ private void closeConnectionExceptionally(String url, JMXConnector srv) { | |
log.error("Cannot invalidate object in pool, {}", url); | ||
} | ||
} | ||
|
||
public static Object metricValueReduce(Object value1, Object value2) { | ||
if (value1 instanceof Number) { | ||
return new BigDecimal(value1.toString()).add(new BigDecimal(value2.toString())); | ||
} else { | ||
return value1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
kafka-ui-api/src/main/java/com/provectus/kafka/ui/zookeeper/ZookeeperService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Looks strange