Skip to content
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 27 commits into from
Jul 30, 2020
Merged

Backend jmx metrics #64

merged 27 commits into from
Jul 30, 2020

Conversation

yazebochan
Copy link
Contributor

WIP

@@ -303,14 +358,10 @@ components:
type: integer
topicCount:
type: integer
bytesInPerSec:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep these params here


public Map<String, Number> getJmxTrafficMetrics(int jmxPort, String jmxHost, String metricName) {
private Map<String, Object> getJmxMetric(int jmxPort, String jmxHost, String canonicalName) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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<>();
Copy link
Contributor

Choose a reason for hiding this comment

The 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

@apetrovs
Copy link
Contributor

apetrovs commented Jul 3, 2020 via email

.flatMapIterable(nodes -> nodes)
.map(broker -> {
var jmx = getJmxMetric(clusterName, broker);
Map<Integer, InternalBrokerMetrics> result = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map.of ?

Copy link
Contributor

@germanosin germanosin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove package-lock from commit

})
.collectList()
.map(s -> { var brokerMetrics = ClusterUtil.toSingleMap(s.stream());
return internalClusterMetrics.toBuilder().internalBrokerMetrics(brokerMetrics).build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it one line

.internalBrokerMetrics((brokers.stream().map(Node::id).collect(Collectors.toMap(k -> k, v -> InternalBrokerMetrics.builder().build()))))
.bytesOutPerSec(bytesOutPerSec)
.bytesInPerSec(bytesInPerSec);
.internalBrokerMetrics((brokers.stream().map(Node::id).collect(Collectors.toMap(k -> k, v -> InternalBrokerMetrics.builder().build()))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you miss something here?

collect(Collectors.toMap(k -> k, v -> InternalBrokerMetrics.builder().build())))

brokerMetrics.setJmxMetrics(s.getInternalBrokerMetrics().get(id).getJmxMetrics());
brokerMetrics.setSegmentZise(Long.valueOf(s.getSegmentSize()).intValue());
return brokerMetrics;
}).orElseThrow());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty mono?

jmxMetrics.forEach(j -> {
JmxMetric metric = new JmxMetric();
metric.setCanonicalName(j.getCanonicalName());
metric.setValue(getJmxMetric(jmxPort, jmxHost, j.getCanonicalName()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks strange

@@ -72,4 +99,12 @@ private void closeConnectionExceptionally(String url, JMXConnector srv) {
log.error("Cannot invalidate object in pool, {}", url);
}
}

public static BigDecimal metricValueSum(Number value1, Number value2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean up

return getOrCreateAdminClient(cluster)
.flatMap(
ac -> getClusterMetrics(ac.getAdminClient())
.flatMap(i -> fillJmxMetrics(i, cluster.getName()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can pass adminclient to method


public List<JmxMetric> getJmxMetric(String clusterName, Node node) {
return clustersStorage.getClusterByName(clusterName)
.map(c -> jmxClusterUtil.getJmxMetrics(c.getJmxPort(), node.host())).orElseThrow();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty list better here

return internalClusterMetrics.getInternalBrokerMetrics().values().stream()
.map(c ->
c.getJmxMetrics().stream()
.filter(j -> StringUtils.containsIgnoreCase(j.getCanonicalName(), "num") || StringUtils.containsIgnoreCase(j.getCanonicalName(), "persec"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to constants and array

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's set list of metrics we could rollup

.filter(j -> StringUtils.containsIgnoreCase(j.getCanonicalName(), "num") || StringUtils.containsIgnoreCase(j.getCanonicalName(), "persec"))
.map(j -> j.getValue().entrySet().stream()
.map(e -> Pair.of(j.getCanonicalName() + "+" + e.getKey(), e.getValue()))
.collect(Collectors.toList()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flatmap stream?

jmx.setCanonicalName(c.getKey());
jmx.setValue(Map.of(c.getValue().getKey(), c.getValue().getValue()));
return jmx;
}).collect(Collectors.groupingBy(JmxMetric::getCanonicalName, Collectors.toList()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can reduce on groupingby

c.getJmxMetrics().stream()
.filter(j -> StringUtils.containsIgnoreCase(j.getCanonicalName(), "num") || StringUtils.containsIgnoreCase(j.getCanonicalName(), "persec"))
.map(j -> j.getValue().entrySet().stream()
.map(e -> Pair.of(j.getCanonicalName() + "+" + e.getKey(), e.getValue()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think how to improve all these key transformations

type: object
additionalProperties:
type: number
jmxMetrics:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's name it metrics, not a jmx metrics

$ref: '#/components/schemas/ConsumerTopicPartitionDetail'

JmxMetric:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics

@germanosin germanosin merged commit efc35a9 into master Jul 30, 2020
@germanosin germanosin deleted the backend-jmx-metrics branch July 30, 2020 11:03
javalover123 pushed a commit to javalover123/kafka-ui that referenced this pull request Dec 7, 2022
* Start doing endpoint for jmx metrics

* Added endpoint for getting jmx metric per broker

* Cluster jmx metrics sum endpoit added

* Added endpoints for cluster metrics and broker metrics

* Cleared some code

* Fixed jmxmetrics names

* Changed to all values in metrics

* Removed redundant imports

* Renamed param constant

* Changed to calculate brokers and clusters metrics in one place

* Removed redundant imports

* Fixed some mistakes

* Replaced multiple method usage into single

* Fixed mulptiple call

* Removed cluster level metrics, now only broker-level metrics in cluster

* Just small fixes

* removed redundant variable

* Renamed method for cluster level metrics

* Fixed after PR and added sum for number cluster metrics by num and persec keywords in canonicalname

* Added metricdto object

* Added list of metrics to enum

* Renames and optimizings

* Renamed jmxmetrics objects param to metrics

Co-authored-by: Roman Nedzvetskiy <roman@Romans-MacBook-Pro.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants