/** * Sends a numeric metric to Application Insights. Appears in customMetrics in Analytics, and under Custom Metrics in Metric Explorer. * @param name The name of the metric. Max length 150. * @param value The value of the metric. * @throws IllegalArgumentException if name is null or empty. */ public void trackMetric(String name, double value) { trackMetric(name, value, null, null, null, null, null); }
@Override public void run() { tclient.trackMetric(name, value, sampleCount, min, max, properties); } };
@Override public void run() { tclient.trackMetric(name, value); } };
@Override public void run() { tclient.trackMetric(mt); } };
protected void sendMetricInternal(final String name, final double value) { // Log that the event occurred (this log is used in testing) logger.debug(String.format("sendMetric(%s, %f)", name, value)); if (telemetryClient != null) { telemetryClient.trackMetric(name, value); } }
/** * Sends a numeric metric to Application Insights. Appears in customMetrics in Analytics, and under Custom Metrics in Metric Explorer. * @param name The name of the metric. Max length 150. * @param value The value of the metric. Sum if based on more than one sample count. * @param sampleCount The sample count. * @param min The minimum value of the sample. * @param max The maximum value of the sample. * @param properties Named string values you can use to search and classify trace messages. * @throws IllegalArgumentException if name is null or empty. * @deprecated Use {@link #trackMetric(String, double, Integer, Double, Double, Double, Map)} */ @Deprecated public void trackMetric(String name, double value, int sampleCount, double min, double max, Map<String, String> properties) { this.trackMetric(name, value, sampleCount, min, max, null, properties); }
@Override public void run() { long runElapsed = System.nanoTime(); int i = 0; for (; i < numberOfTelemetries; ++i) { int mod = i % 4; switch (mod) { case 0: telemetryClient.trackEvent(MOCK_EVENT_NAME); break; case 1: telemetryClient.trackMetric(MOCK_METRIC_NAME, MOCK_METRIC_VALUE); break; case 2: telemetryClient.trackTrace(MOCK_TRACE_NAME); break; default: telemetryClient.trackPageView(MOCK_PAGE_VIEW_NAME); break; } } sendTimeInNanos = System.nanoTime() - runElapsed; acceptedUntilEndOfSending = testResultsVerifier.getCurrentAccepted(); } });
/** * Send the heartbeat item synchronously to application insights backend. */ private void send() { MetricTelemetry telemetry = gatherData(); telemetry.getContext().getOperation().setSyntheticSource(HEARTBEAT_SYNTHETIC_METRIC_NAME); telemetryClient.trackMetric(telemetry); InternalLogger.INSTANCE.trace("No of heartbeats sent, %s", ++heartbeatsSent); }
mt.setCount(100); mt.setStandardDeviation(2.43); appInsights.trackMetric(mt); System.out.println("[4] Metric -- metric:\"Test time\", value=17.0, Max=20.0, Min=10.0, Count=100 and STDV=2.43"); appInsights.trackMetric(mtPc); System.out.println("[8] Metric -- metric:\"Test PC Metric\", value=23.0");
@Test public void testTrackMetricWithExpandedValues() { Map<String, String> properties = new HashMap<String, String>() {{ put("key", "value"); }}; client.trackMetric("Metric", 1, 1, 1, 1, properties); verifyAndGetLastEventSent(); }
@Test public void testTrackMetricWithMetricTelemetry() { MetricTelemetry telemetry = new MetricTelemetry("Metric", 1); client.trackMetric(telemetry); verifyAndGetLastEventSent(); }
@Test public void testTrackMetricWithAllValues() { Map<String, String> props = new HashMap<String, String>() {{ put("key1", "value1"); put("key2", "value2"); }}; final String name = "MyMetric"; final double value = 1.01; final Integer sampleCount = 2; final Double min = 0.01; final Double max = 1.0; final Double stdDev = 0.636396; client.trackMetric(name, value, sampleCount, min, max, stdDev, props); MetricTelemetry mt = (MetricTelemetry) verifyAndGetLastEventSent(); assertEquals("getName", name, mt.getName()); assertEquals("getValue", value, mt.getValue(), Math.ulp(value)); assertEquals("getMin", min, mt.getMin()); assertEquals("getMax", max, mt.getMax()); assertEquals("getStandardDeviation", stdDev, mt.getStandardDeviation()); assertNotNull("getProperties should be non-null", mt.getProperties()); for (String key : props.keySet()) { assertTrue("metric properties contains key", mt.getProperties().containsKey(key)); assertEquals("metric properties key/value pair did not match", props.get(key), mt.getProperties().get(key)); } }
@Test public void testTrackMetricWithNameAndValue() { final String name = "Metric"; final double value = 1.11; client.trackMetric(name, value); MetricTelemetry mt = (MetricTelemetry) verifyAndGetLastEventSent(); assertEquals("getName", name, mt.getName()); assertEquals("getValue", value, mt.getValue(), Math.ulp(value)); assertNull("getCount should be null", mt.getCount()); assertNull("getMin should be null", mt.getMin()); assertNull("getMax should be null", mt.getMax()); assertNull("getStandardDeviation should be null", mt.getStandardDeviation()); assertTrue("properties should be empty", mt.getProperties().isEmpty()); }
@Test public void testTrackMetricAggregateWithSomeNulls() { Map<String, String> propsIsNull = null; final String name = "MyMetricHasNulls"; final double value = 1.02; final Integer sampleCount = 3; final Double minIsNull = null; final Double max = 0.99; final Double stdDevIsNull = null; client.trackMetric(name, value, sampleCount, minIsNull, max, stdDevIsNull, propsIsNull); MetricTelemetry mt = (MetricTelemetry) verifyAndGetLastEventSent(); assertEquals("getName", name, mt.getName()); assertEquals("getValue", value, mt.getValue(), Math.ulp(value)); assertNull("getMin should be null", mt.getMin()); assertEquals("getMax", max, mt.getMax()); assertNull("getStandardDeviation should be null", mt.getStandardDeviation()); assertNotNull("getProperties should be null", mt.getProperties()); assertEquals("properties size", 0, mt.getProperties().size()); }