Search in sources :

Example 1 with MetricDataPoint

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;
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 2 with MetricDataPoint

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);
    }
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) MonitorDomain(com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain)

Example 3 with MetricDataPoint

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;
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) ArrayList(java.util.ArrayList) MonitorBase(com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorBase)

Example 4 with MetricDataPoint

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;
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)

Example 5 with MetricDataPoint

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);
    }
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)

Aggregations

MetricDataPoint (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)8 MetricsData (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData)8 TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)6 HashMap (java.util.HashMap)3 MonitorDomain (com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain)2 MonitorBase (com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorBase)1 AlertMetricType (com.microsoft.applicationinsights.alerting.config.AlertMetricType)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1