use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint in project ApplicationInsights-Java by microsoft.
the class HeartBeatProvider method gatherData.
/**
* Creates and returns the heartbeat telemetry.
*
* @return Metric Telemetry which represent heartbeat.
*/
// visible for testing
TelemetryItem gatherData() {
Map<String, String> properties = new HashMap<>();
double numHealthy = 0;
for (Map.Entry<String, HeartBeatPropertyPayload> entry : heartbeatProperties.entrySet()) {
HeartBeatPropertyPayload payload = entry.getValue();
properties.put(entry.getKey(), payload.getPayloadValue());
numHealthy += payload.isHealthy() ? 0 : 1;
}
TelemetryItem telemetry = new TelemetryItem();
MetricsData data = new MetricsData();
MetricDataPoint point = new MetricDataPoint();
telemetryClient.initMetricTelemetry(telemetry, data, point);
point.setName(HEARTBEAT_SYNTHETIC_METRIC_NAME);
point.setValue(numHealthy);
point.setDataPointType(DataPointType.MEASUREMENT);
data.setProperties(properties);
telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
return telemetry;
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint in project ApplicationInsights-Java by microsoft.
the class TelemetryClient method trackAsync.
public void trackAsync(TelemetryItem telemetry) {
if (Strings.isNullOrEmpty(instrumentationKey)) {
return;
}
MonitorDomain data = telemetry.getData().getBaseData();
if (data instanceof MetricsData) {
MetricsData metricsData = (MetricsData) data;
if (metricsData.getMetrics().isEmpty()) {
throw new AssertionError("MetricsData has no metric point");
}
MetricDataPoint point = metricsData.getMetrics().get(0);
String metricName = point.getName();
if (!nonFilterableMetricNames.contains(metricName)) {
for (MetricFilter metricFilter : metricFilters) {
if (!metricFilter.matches(metricName)) {
// user configuration filtered out this metric name
return;
}
}
}
if (!Double.isFinite(point.getValue())) {
// breeze doesn't like these values
return;
}
}
if (telemetry.getTime() == null) {
// this is easy to forget when adding new telemetry
throw new AssertionError("telemetry item is missing time");
}
QuickPulseDataCollector.INSTANCE.add(telemetry);
TelemetryObservers.INSTANCE.getObservers().forEach(consumer -> consumer.accept(telemetry));
// only that it was successfully delivered to the next layer
if (data instanceof MetricsData) {
getMetricsChannelBatcher().trackAsync(telemetry);
} else {
getGeneralChannelBatcher().trackAsync(telemetry);
}
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint 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.MetricDataPoint 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.MetricDataPoint 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);
}
}
Aggregations