private void reportHeap(MemoryMXBean memory, TelemetryClient telemetryClient) { MemoryUsage mhu = memory.getHeapMemoryUsage(); if (mhu != null) { long currentHeapUsed = mhu.getUsed() / Megabyte; MetricTelemetry memoryHeapUsage = new MetricTelemetry(HEAP_MEM_USED, currentHeapUsed); memoryHeapUsage.markAsCustomPerfCounter(); telemetryClient.track(memoryHeapUsage); } } }
MetricTelemetry mtTotalTime = new MetricTelemetry(GC_TOTAL_TIME, timeToReport); mtTotalCount.markAsCustomPerfCounter(); mtTotalCount.markAsCustomPerfCounter();
/** * Registers the argument's data into performance counters. * @param pcsData The performance counters to register for Windows OS. * @throws java.lang.Throwable The constructor might throw an Error if the JniPCConnector is not able to properly * connect to the native code. or Exception if the constructor is not called under Windows OS. */ public WindowsPerformanceCounterAsMetric(Iterable<WindowsPerformanceCounterData> pcsData) throws Throwable { Preconditions.checkState(SystemInformation.INSTANCE.isWindows(), "Must be used under Windows OS."); Preconditions.checkNotNull(pcsData, "pcsData must be non-null value."); // indicate that this is used for performance counters, not custom metrics. telemetry.markAsCustomPerfCounter(); register(pcsData); if (keyToDisplayName.isEmpty()) { // Failed to register, the performance counter is not needed. throw new Exception("No valid data"); } }
@Override protected void send(TelemetryClient telemetryClient, String displayName, double value) { InternalLogger.INSTANCE.trace("Metric JMX: %s, %s", displayName, value); MetricTelemetry telemetry = new MetricTelemetry(); telemetry.markAsCustomPerfCounter(); telemetry.setName(displayName); telemetry.setValue(value); telemetry.getProperties().put("CustomPerfCounter", "true"); telemetryClient.track(telemetry); } }
@Override public void report(TelemetryClient telemetryClient) { MetricTelemetry mt = new MetricTelemetry(METRIC_NAME, 0.0); mt.markAsCustomPerfCounter(); long[] threadIds = threadBean.findDeadlockedThreads(); if (threadIds != null && threadIds.length > 0) { ArrayList<Long> blockedThreads = new ArrayList<Long>(); StringBuilder sb = new StringBuilder(); for (long threadId : threadIds) { ThreadInfo threadInfo = threadBean.getThreadInfo(threadId); if (threadInfo == null) { continue; } setThreadInfoAndStack(sb, threadInfo); blockedThreads.add(threadId); } if (!blockedThreads.isEmpty()) { String uuid = LocalStringsUtils.generateRandomIntegerId(); mt.setValue((double)blockedThreads.size()); mt.getContext().getOperation().setId(uuid); TraceTelemetry trace = new TraceTelemetry(String.format("%s%s", "Suspected deadlocked threads: ", sb.toString())); trace.getContext().getOperation().setId(uuid); telemetryClient.track(trace); } } telemetryClient.track(mt); } private void setThreadInfoAndStack(StringBuilder sb, ThreadInfo ti) {
mtPc.markAsCustomPerfCounter(); appInsights.trackMetric(mtPc); System.out.println("[8] Metric -- metric:\"Test PC Metric\", value=23.0");