use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class HeartbeatTests method heartBeatPayloadContainsDataByDefault.
@Test
void heartBeatPayloadContainsDataByDefault() throws InterruptedException {
// given
HeartBeatProvider provider = new HeartBeatProvider();
provider.initialize(TelemetryClient.createForTest());
// some of the initialization above happens in a separate thread
Thread.sleep(500);
// then
MetricsData t = (MetricsData) provider.gatherData().getData().getBaseData();
assertThat(t).isNotNull();
assertThat(t.getProperties().size() > 0).isTrue();
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class TestUtils method createMetricTelemetry.
public static TelemetryItem createMetricTelemetry(String name, int value, String instrumentationKey) {
TelemetryItem telemetry = new TelemetryItem();
telemetry.setVersion(1);
telemetry.setName("Metric");
telemetry.setInstrumentationKey(instrumentationKey);
Map<String, String> tags = new HashMap<>();
tags.put("ai.internal.sdkVersion", "test_version");
tags.put("ai.internal.nodeName", "test_role_name");
tags.put("ai.cloud.roleInstance", "test_cloud_name");
telemetry.setTags(tags);
MetricsData data = new MetricsData();
List<MetricDataPoint> dataPoints = new ArrayList<>();
MetricDataPoint dataPoint = new MetricDataPoint();
dataPoint.setDataPointType(DataPointType.MEASUREMENT);
dataPoint.setName(name);
dataPoint.setValue(value);
dataPoint.setCount(1);
dataPoints.add(dataPoint);
Map<String, String> properties = new HashMap<>();
properties.put("state", "blocked");
data.setMetrics(dataPoints);
data.setProperties(properties);
MonitorBase monitorBase = new MonitorBase();
monitorBase.setBaseType("MetricData");
monitorBase.setBaseData(data);
telemetry.setData(monitorBase);
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
return telemetry;
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class BaseStatsbeat method createStatsbeatTelemetry.
protected TelemetryItem createStatsbeatTelemetry(TelemetryClient telemetryClient, String name, double value) {
TelemetryItem telemetry = new TelemetryItem();
MetricsData data = new MetricsData();
MetricDataPoint point = new MetricDataPoint();
telemetryClient.initMetricTelemetry(telemetry, data, point);
// overwrite the default name (which is "Metric")
telemetry.setName(STATSBEAT_TELEMETRY_NAME);
point.setName(name);
point.setValue(value);
point.setDataPointType(DataPointType.MEASUREMENT);
telemetry.setInstrumentationKey(telemetryClient.getStatsbeatInstrumentationKey());
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
Map<String, String> properties = new HashMap<>();
customDimensions.populateProperties(properties, telemetryClient.getInstrumentationKey());
data.setProperties(properties);
return telemetry;
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class DeadLockDetectorPerformanceCounter method report.
@Override
public void report(TelemetryClient telemetryClient) {
TelemetryItem telemetry = new TelemetryItem();
MetricsData data = new MetricsData();
MetricDataPoint point = new MetricDataPoint();
TelemetryClient.getActive().initMetricTelemetry(telemetry, data, point);
point.setName(METRIC_NAME);
point.setValue(0);
point.setDataPointType(DataPointType.MEASUREMENT);
long[] threadIds = threadBean.findDeadlockedThreads();
int blockedThreadCount = threadIds == null ? 0 : threadIds.length;
data.getMetrics().get(0).setValue(blockedThreadCount);
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
telemetryClient.trackAsync(telemetry);
if (blockedThreadCount > 0) {
sendDetailedMessage(telemetryClient, threadIds);
}
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.
the class BytecodeUtilImpl method trackMetric.
// TODO do not track if perf counter (?)
@Override
public void trackMetric(Date timestamp, String name, double value, Integer count, Double min, Double max, Double stdDev, Map<String, String> properties, Map<String, String> tags, String instrumentationKey) {
if (Strings.isNullOrEmpty(name)) {
return;
}
TelemetryItem telemetry = new TelemetryItem();
MetricsData data = new MetricsData();
MetricDataPoint point = new MetricDataPoint();
TelemetryClient.getActive().initMetricTelemetry(telemetry, data, point);
point.setName(name);
point.setValue(value);
point.setCount(count);
point.setMin(min);
point.setMax(max);
point.setStdDev(stdDev);
if (count != null || min != null || max != null || stdDev != null) {
point.setDataPointType(DataPointType.AGGREGATION);
} else {
point.setDataPointType(DataPointType.MEASUREMENT);
}
if (!properties.isEmpty()) {
Map<String, String> existingProperties = data.getProperties();
if (existingProperties == null) {
data.setProperties(properties);
} else {
existingProperties.putAll(properties);
}
}
if (timestamp != null) {
telemetry.setTime(FormattedTime.offSetDateTimeFromDate(timestamp));
} else {
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
}
selectivelySetTags(telemetry, tags);
if (instrumentationKey != null) {
telemetry.setInstrumentationKey(instrumentationKey);
}
track(telemetry, false);
}
Aggregations