You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/09/27 08:28:41 UTC

[GitHub] [pulsar] tjiuming opened a new pull request, #17850: [broker][monitoring] Add per-thread CPU usage metrics.

tjiuming opened a new pull request, #17850:
URL: https://github.com/apache/pulsar/pull/17850

   ### Motivation
   
   Introduce the metrics for thread CPU usage which can help Pulsar maintainers to detect performance issues related to parts of threads that run with high CPU usage, especially the IO thread.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] Anything that affects deployment
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [x] `doc-required` 
   (Your PR needs to update docs and you will update later)
   
   - [ ] `doc-not-needed` 
   (Please explain why)
   
   - [ ] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)
   
   ### Matching PR in forked repository
   
   PR in forked repository: 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tisonkun commented on a diff in pull request #17850: [broker][monitoring] Add per-thread CPU usage metrics.

Posted by GitBox <gi...@apache.org>.
tisonkun commented on code in PR #17850:
URL: https://github.com/apache/pulsar/pull/17850#discussion_r981110610


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java:
##########
@@ -1586,6 +1589,46 @@ public void testMetricsGroupedByTypeDefinitions() throws Exception {
         p2.close();
     }
 
+
+    @Test
+    public void testBrokerThreadsCpuUsageMetrics() throws Exception {
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+        PrometheusMetricsGenerator.generate(pulsar, false, false, false, false, output);
+        Multimap<String, Metric> metricsMap = parseMetrics(output.toString("UTF-8"));
+        Collection<Metric> total = metricsMap.get("pulsar_broker_thread_total_cpu_usage_ns");
+        Collection<Metric> user = metricsMap.get("pulsar_broker_thread_user_cpu_usage_ns");
+        Collection<Metric> system = metricsMap.get("pulsar_broker_thread_system_cpu_usage_ns");
+
+        Map<String, Metric> threadName2User =
+                user.stream().collect(Collectors.toMap(m -> m.tags.get("thread_name"), m -> m));
+        Map<String, Metric> threadName2System =
+                system.stream().collect(Collectors.toMap(m -> m.tags.get("thread_name"), m -> m));
+
+        ThreadMXBean mxbean = ManagementFactory.getThreadMXBean();
+        if (!mxbean.isThreadCpuTimeSupported()) {
+            return;
+        }
+
+        Assert.assertNotNull(total);
+        Assert.assertTrue(total.size() > 0);
+
+        for (Metric total0 : total) {
+            String cluster = total0.tags.get("cluster");
+            Assert.assertNotNull(cluster);
+            Assert.assertEquals(cluster, "test");
+            String threadName = total0.tags.get("thread_name");
+            Assert.assertNotNull(threadName);
+            Assert.assertTrue(total0.value >= 0);

Review Comment:
   You can try to use assertj's assertion for better error messages. Like:
   
   ```java
   import static org.assertj.core.api.Assertions.assertThat;
   
   assertThat(total0.value).isGreaterThanOrEqualTo(0);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tjiuming closed pull request #17850: [broker][monitoring] Add per-thread CPU usage metrics.

Posted by GitBox <gi...@apache.org>.
tjiuming closed pull request #17850: [broker][monitoring] Add per-thread CPU usage metrics.
URL: https://github.com/apache/pulsar/pull/17850


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org