Search in sources :

Example 6 with MetricDataPoint

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint 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);
}
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)

Example 7 with MetricDataPoint

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint in project ApplicationInsights-Java by microsoft.

the class TelemetryUtil method createMetricsTelemetry.

public static TelemetryItem createMetricsTelemetry(TelemetryClient telemetryClient, String name, double value) {
    TelemetryItem telemetry = new TelemetryItem();
    MetricsData data = new MetricsData();
    MetricDataPoint point = new MetricDataPoint();
    telemetryClient.initMetricTelemetry(telemetry, data, point);
    point.setName(name);
    point.setValue(value);
    point.setDataPointType(DataPointType.MEASUREMENT);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    return telemetry;
}
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)

Example 8 with MetricDataPoint

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint in project ApplicationInsights-Java by microsoft.

the class AlertingServiceFactory method addObserver.

private static void addObserver(AlertingSubsystem alertingSubsystem, TelemetryObservers telemetryObservers) {
    telemetryObservers.addObserver(telemetry -> {
        MonitorDomain data = telemetry.getData().getBaseData();
        if (!(data instanceof MetricsData)) {
            return;
        }
        MetricDataPoint point = ((MetricsData) data).getMetrics().get(0);
        AlertMetricType alertMetricType = null;
        if (point.getName().equals(TOTAL_CPU_PC_METRIC_NAME)) {
            alertMetricType = AlertMetricType.CPU;
        }
        if (alertMetricType != null) {
            alertingSubsystem.track(alertMetricType, point.getValue());
        }
    });
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) AlertMetricType(com.microsoft.applicationinsights.alerting.config.AlertMetricType) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) MonitorDomain(com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain)

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