@Override public boolean isMetricsEnabled() { return AwsSdkMetrics.isMetricsEnabled(); }
/** * Convenient method to disable the metric collector at the AWS SDK * level. */ public static void disableMetrics() { setMetricCollector(MetricCollector.NONE); }
public static <T extends MetricCollector> T getMetricCollector() { if (mc == null) { if (isDefaultMetricsEnabled()) enableDefaultMetrics(); } @SuppressWarnings("unchecked") T t = (T)(mc == null ? MetricCollector.NONE : mc); return t; }
@Test public void test() { // by default, it's disabled assertFalse(AwsSdkMetrics.isDefaultMetricsEnabled()); // won't be anble to enable unless the default impl library is on the // classpath assertFalse(AwsSdkMetrics.enableDefaultMetrics()); assertFalse(AwsSdkMetrics.isDefaultMetricsEnabled()); assertSame(RequestMetricCollector.NONE, AwsSdkMetrics.getRequestMetricCollector()); assertFalse(AwsSdkMetrics.isDefaultMetricsEnabled()); // effectively no effect AwsSdkMetrics.disableMetrics(); assertFalse(AwsSdkMetrics.isDefaultMetricsEnabled()); }
/** * Returns the client specific request metric collector if there is one; or the one at the AWS * SDK level otherwise. */ private RequestMetricCollector requestMetricCollector() { return clientLevelMetricCollector != null ? clientLevelMetricCollector : AwsSdkMetrics.getRequestMetricCollector(); }
@Test public void isMetricEnabled() { assertFalse(AwsSdkMetrics.isMetricsEnabled()); AwsSdkMetrics.setMetricCollector(MetricCollector.NONE); assertFalse(AwsSdkMetrics.isMetricsEnabled()); AwsSdkMetrics.setMetricCollector(new MetricCollector() { @Override public boolean start() { assertTrue(AwsSdkMetrics.isMetricsEnabled());
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { if ("get".equals(method.getName())) { ServiceLatencyProvider latencyProvider = new ServiceLatencyProvider( AWSServiceMetrics.HttpClientGetConnectionTime); try { return method.invoke(orig, args); } finally { AwsSdkMetrics.getServiceMetricCollector() .collectLatency(latencyProvider.endTiming()); } } return method.invoke(orig, args); } catch (InvocationTargetException e) { log.debug("", e); throw e.getCause(); } } }
@Override public boolean enableDefaultMetrics() { return AwsSdkMetrics.enableDefaultMetrics(); } @Override
/** * Sets the AWS credential file to be used for accessing Amazon CloudWatch. * Successfully calling this method would result in the AWS credential * provider to make use of the given credential file. */ public static void setCredentialFile(String filepath) throws FileNotFoundException, IOException { setCredentialFile0(filepath); }
@Override public boolean isMachineMetricsExcluded() { return AwsSdkMetrics.isMachineMetricExcluded(); } @Override
public AwsMetricManager(IConfiguration config, INameFactory nameFactory) { cwClient_ = AmazonCloudWatchClientBuilder.defaultClient(); nameSpace_ = nameFactory.getMultiTenantServiceName().toString(); tenantId_ = config.getString("id/tenantId", null); AwsSdkMetrics.enableDefaultMetrics(); // AwsSdkMetrics.setCredentialProvider(credentialsProvider); AwsSdkMetrics.setMetricNameSpace(nameSpace_); }
@Test public void setJvmMetricsExcluded() { final boolean b = AwsSdkMetrics.isMachineMetricExcluded(); AwsSdkMetrics.setMachineMetricsExcluded(b); assertTrue(b == AwsSdkMetrics.isMachineMetricExcluded()); AwsSdkMetrics.setMachineMetricsExcluded(!b); assertFalse(b == AwsSdkMetrics.isMachineMetricExcluded()); AwsSdkMetrics.setMachineMetricsExcluded(b); assertTrue(b == AwsSdkMetrics.isMachineMetricExcluded()); }
/** * Returns the client specific request metric collector if there is one; or * the one at the AWS SDK level otherwise. */ protected RequestMetricCollector requestMetricCollector() { RequestMetricCollector mc = client.getRequestMetricCollector(); return mc == null ? AwsSdkMetrics.getRequestMetricCollector() : mc; }
.guessThroughputMetricType(req, suffix, byteCountTypeNameSuffix); if (!AwsSdkMetrics.isMetricsEnabled()) { assertNull(actualType); AwsSdkMetrics.setMetricCollector(new MetricCollector() { @Override public boolean start() {
void reportMetrics() { if (getByteCount() > 0) { ServiceMetricCollector col = AwsSdkMetrics.getServiceMetricCollector(); col.collectByteThroughput(this); reset(); } }
@Override public boolean enableDefaultMetrics() { return AwsSdkMetrics.enableDefaultMetrics(); } @Override
/** * Sets the AWS credential file to be used for accessing Amazon CloudWatch. * Successfully calling this method would result in the AWS credential * provider to make use of the given credential file. * @param filepath the credential filepath. */ public static void setCredentialFile(String filepath) throws IOException { setCredentialFile0(filepath); }
List<MetricDatum> generateMetrics() { if (AwsSdkMetrics.isMachineMetricExcluded()) return Collections.emptyList(); Set<MachineMetric> customSet = customMachineMetrics(); List<MetricDatum> targetList = new ArrayList<MetricDatum>( MachineMetric.values().length); // Memory usage addMemoryMetrics(targetList, customSet); // Thread related counts try { addThreadMetrics(targetList, customSet); } catch (Throwable t) { LogFactory.getLog(getClass()).debug("Ignoring thread metrics", t); } // File descriptor usage try { addFileDescriptorMetrics(targetList, customSet); } catch (Throwable t) { LogFactory.getLog(getClass()).debug("Ignoring file descriptor metrics", t); } return targetList; }
public static <T extends ServiceMetricCollector> T getServiceMetricCollector() { if (mc == null) { if (isDefaultMetricsEnabled()) enableDefaultMetrics(); } @SuppressWarnings("unchecked") T t = (T)(mc == null ? ServiceMetricCollector.NONE : mc.getServiceMetricCollector()); return t; }
/** * Returns true if we should wrap the given input stream with a byte * counting wrapper; false otherwise. */ private static boolean wrapWithByteCounting(InputStream in) { if (!AwsSdkMetrics.isMetricsEnabled()) { return false; // metrics is disabled } if (in instanceof MetricAware) { MetricAware aware = (MetricAware) in; // wrap only if not already wrapped in one of it's inner chain of input stream return !aware.isMetricActivated(); } return true; // this is a raw input stream so metric wrapping is necessary }