[GitHub] [ignite] nizhikov commented on a change in pull request #6882: IGNITE-12044: Export histogram values as separate JMX attributes.

2019-09-19 Thread GitBox
nizhikov commented on a change in pull request #6882: IGNITE-12044: Export 
histogram values as separate JMX attributes.
URL: https://github.com/apache/ignite/pull/6882#discussion_r326167668
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/spi/metric/jmx/MetricRegistryMBean.java
 ##
 @@ -146,4 +176,55 @@ else if (metric instanceof ObjectMetric)
 
 throw new UnsupportedOperationException("invoke not supported.");
 }
+
+/**
+ * Parse attribute name for a histogram and search it's value.
+ *
+ * @param name Attribute name.
+ * @param mreg Metric registry to search histogram in.
+ * @return Specific bucket value or {@code null} if not found.
+ * @see MetricUtils#histogramBucketNames(HistogramMetric, Map)
+ */
+public static Long searchHistogram(String name, MetricRegistry mreg) {
+Scanner sc = new Scanner(name).useDelimiter("_");
+
+if (!sc.hasNext())
+return null;
+
+Metric m = mreg.findMetric(sc.next());
+
+if (!(m instanceof HistogramMetric))
+return null;
+
+HistogramMetric h = (HistogramMetric)m;
+
+long[] bounds = h.bounds();
+long[] values = h.value();
+
+if (!sc.hasNextLong())
+return null;
+
+long lowBound = sc.nextLong();
+
+//If `highBound` not presented this can be last interval `[max]_inf`.
+if (!sc.hasNextLong()) {
+if (sc.hasNext() && INF.equals(sc.next()) && 
bounds[bounds.length-1] == lowBound)
+return values[values.length-1];
+
+return null;
+}
+
+long highBound = sc.nextLong();
+
+for (int i=0; i

[GitHub] [ignite] nizhikov commented on a change in pull request #6882: IGNITE-12044: Export histogram values as separate JMX attributes.

2019-09-19 Thread GitBox
nizhikov commented on a change in pull request #6882: IGNITE-12044: Export 
histogram values as separate JMX attributes.
URL: https://github.com/apache/ignite/pull/6882#discussion_r326164528
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/MetricUtils.java
 ##
 @@ -133,6 +138,43 @@ private static boolean ensureAllNamesNotEmpty(String... 
names) {
 return true;
 }
 
+/**
+ * Gets histogram bucket names.
+ *
+ * Example of metric names if bounds are 10,100:
+ *  histogram_0_10 (less than 10)
+ *  histogram_10_100 (between 10 and 100)
+ *  histogram_100_inf (more than 100)
+ *
+ * @param metric Histogram metric.
 
 Review comment:
   Fixed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] nizhikov commented on a change in pull request #6882: IGNITE-12044: Export histogram values as separate JMX attributes.

2019-09-19 Thread GitBox
nizhikov commented on a change in pull request #6882: IGNITE-12044: Export 
histogram values as separate JMX attributes.
URL: https://github.com/apache/ignite/pull/6882#discussion_r326163356
 
 

 ##
 File path: 
modules/core/src/test/java/org/apache/ignite/internal/metric/JmxMetricExporterSpiTest.java
 ##
 @@ -131,17 +134,70 @@ public void testFilterAndExport() throws Exception {
 
 assertThrowsWithCause(new RunnableX() {
 @Override public void runx() throws Exception {
-metricSet(ignite.name(), "filtered", "metric");
+metricRegistry(ignite.name(), "filtered", "metric");
 }
 }, IgniteException.class);
 
-DynamicMBean bean1 = metricSet(ignite.name(), "other", "prefix");
+DynamicMBean bean1 = metricRegistry(ignite.name(), "other", "prefix");
 
 assertEquals(42L, bean1.getAttribute("test"));
 assertEquals(43L, bean1.getAttribute("test2"));
 
-DynamicMBean bean2 = metricSet(ignite.name(), "other", "prefix2");
+DynamicMBean bean2 = metricRegistry(ignite.name(), "other", "prefix2");
 
 assertEquals(44L, bean2.getAttribute("test3"));
 }
+
+/** */
+@Test
+public void testHistogramSearchByName() throws Exception {
 
 Review comment:
   For now, we don't support interval changes.
   So, I don't think we should test it.
   
   Seems, we should re-register MBean if some metric change its properties.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] nizhikov commented on a change in pull request #6882: IGNITE-12044: Export histogram values as separate JMX attributes.

2019-09-19 Thread GitBox
nizhikov commented on a change in pull request #6882: IGNITE-12044: Export 
histogram values as separate JMX attributes.
URL: https://github.com/apache/ignite/pull/6882#discussion_r326163490
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/spi/metric/jmx/MetricRegistryMBean.java
 ##
 @@ -146,4 +176,55 @@ else if (metric instanceof ObjectMetric)
 
 throw new UnsupportedOperationException("invoke not supported.");
 }
+
+/**
+ * Parse attribute name for a histogram and search it's value.
+ *
+ * @param name Attribute name.
+ * @param mreg Metric registry to search histogram in.
+ * @return Specific bucket value or {@code null} if not found.
+ * @see MetricUtils#histogramBucketNames(HistogramMetric, Map)
+ */
+public static Long searchHistogram(String name, MetricRegistry mreg) {
+Scanner sc = new Scanner(name).useDelimiter("_");
+
+if (!sc.hasNext())
+return null;
+
+Metric m = mreg.findMetric(sc.next());
+
+if (!(m instanceof HistogramMetric))
+return null;
+
+HistogramMetric h = (HistogramMetric)m;
+
+long[] bounds = h.bounds();
+long[] values = h.value();
+
+if (!sc.hasNextLong())
+return null;
+
+long lowBound = sc.nextLong();
+
+//If `highBound` not presented this can be last interval `[max]_inf`.
+if (!sc.hasNextLong()) {
+if (sc.hasNext() && INF.equals(sc.next()) && 
bounds[bounds.length-1] == lowBound)
+return values[values.length-1];
+
+return null;
+}
+
+long highBound = sc.nextLong();
+
+for (int i=0; i