use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class JvmHeapMemoryUsedPerformanceCounter method reportHeap.
private static void reportHeap(MemoryMXBean memory, TelemetryClient telemetryClient) {
MemoryUsage mhu = memory.getHeapMemoryUsage();
if (mhu != null) {
long currentHeapUsed = mhu.getUsed() / Megabyte;
TelemetryItem memoryHeapUsage = TelemetryUtil.createMetricsTelemetry(telemetryClient, HEAP_MEM_USED, currentHeapUsed);
telemetryClient.trackAsync(memoryHeapUsage);
float percentage = 100.0f * (((float) mhu.getUsed()) / ((float) mhu.getMax()));
TelemetryItem memoryHeapUsagePercentage = TelemetryUtil.createMetricsTelemetry(telemetryClient, HEAP_MEM_USED_PERCENTAGE, percentage);
telemetryClient.trackAsync(memoryHeapUsagePercentage);
}
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class ProcessCpuPerformanceCounter method report.
@Override
public void report(TelemetryClient telemetryClient) {
if (cpuPerformanceCounterCalculator == null) {
return;
}
Double processCpuUsage = cpuPerformanceCounterCalculator.getProcessCpuUsage();
if (processCpuUsage == null) {
return;
}
logger.trace("Performance Counter: {}: {}", PROCESS_CPU_PC_METRIC_NAME, processCpuUsage);
TelemetryItem telemetry = TelemetryUtil.createMetricsTelemetry(telemetryClient, PROCESS_CPU_PC_METRIC_NAME, processCpuUsage);
telemetryClient.trackAsync(telemetry);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class BytecodeUtilImpl method trackEvent.
@Override
public void trackEvent(Date timestamp, String name, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics, String instrumentationKey) {
if (Strings.isNullOrEmpty(name)) {
return;
}
TelemetryItem telemetry = new TelemetryItem();
TelemetryEventData data = new TelemetryEventData();
TelemetryClient.getActive().initEventTelemetry(telemetry, data);
data.setName(name);
data.setMeasurements(metrics);
// shared
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, true);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem in project ApplicationInsights-Java by microsoft.
the class BytecodeUtilImpl method trackTrace.
@Override
public void trackTrace(Date timestamp, String message, int severityLevel, Map<String, String> properties, Map<String, String> tags, String instrumentationKey) {
if (Strings.isNullOrEmpty(message)) {
return;
}
TelemetryItem telemetry = new TelemetryItem();
MessageData data = new MessageData();
TelemetryClient.getActive().initMessageTelemetry(telemetry, data);
data.setMessage(message);
if (severityLevel != -1) {
data.setSeverityLevel(getSeverityLevel(severityLevel));
}
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, true);
}
use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem 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;
}
Aggregations