SeriesHelper { public static double getAvg( final List<Series> series, final Tag... tags ) { double result = 0; int count = 0; for ( Series s : series ) { boolean match = true; for ( int i = 0; i < tags.length && match; i++ ) { String k = s.getTags().get( tags[i].getName() ); if ( k == null || !k.equalsIgnoreCase( tags[i].getValue() ) ) { match = false; } } if ( match ) { for ( Double[] v : s.getValues() ) { result += v[1]; count++; } break; } } return count > 0 ? result / count : result; } private  SeriesHelper(); static double getAvg( final List<Series> series, final Tag... tags ); static Set<String> getTagValues( final List<Series> series, String tag );  }
@Test public void testGetAvg() { final List<Series> cpuSeries = rhMetrics.getSeriesByType( SeriesBatch.SeriesType.CPU ); assertEquals( 0.9345833333, SeriesHelper.getAvg( cpuSeries, new Tag( "type", "system" ) ), 0.0000001 ); assertEquals( 3.005, SeriesHelper.getAvg( cpuSeries, new Tag( "type", "user" ) ), 0.0000001 ); final List<Series> netSeries = rhMetrics.getSeriesByType( SeriesBatch.SeriesType.NET ); assertEquals( 853730.013333333, SeriesHelper.getAvg( netSeries, new Tag( "iface", "eth0" ), new Tag( "type", "in" ) ), 0.0000001 ); }