Metric Parser script include is not handling all error conditions and is creating false metric typesDescriptionMetric Parser script include is the issue as we cannot control the memory spike on agent so we need to handle it at parsers end.Metric Parser should handle error conditions and avoid creating unwanted metrics. Steps to Reproduce metricparser.doc 1.Install the latest ACC-M 2. Activate windows metrics policy. 3. When the agent's memory spikes, it starts creating stack trace error which gets parsed by MonitorMetricParser and creates false metrics. WorkaroundReplace the MonitorMetricParser script with the below changes: var Config = Packages.com.service_now.mid.services.Config;var RawMetric = Packages.com.service_now.metric.model.RawMetric;var ArrayList = Packages.java.util.ArrayList;var MonConstants = Packages.com.service_now.mid.mon.MonConstants;var HashMap = Packages.java.util.HashMap;var MetricFactory = Packages.com.service_now.metric.MetricFactory;var MonitoringEndpoint = Packages.com.service_now.mid.mon.MonitoringEndpoint;var check = checkResult.getCheck();var metricType = "";var resource = "";var isTraceEnabled = Config.get().getBooleanProperty("sn_agent.logger.trace", false);var node = "" + client.getName();var removeNodePrefix = function(line, node) { // If the line starts with the host name, skip this part and continue. this should handle the case the host name is FQDN and contains dots if (Config.get().getProperty("sn_agent.check_hostname_prefix", true) && line.toLowerCase().startsWith(node.toLowerCase())) { return node.length; } var firstDot = line.indexOf("."); if (firstDot == -1) { ms.log("MetricsParser.matchTokenizer no dot found in line " + line); return -1; } return firstDot;};var matchTokenizer = function(line, node) { var firstDot = removeNodePrefix(line, node); if (firstDot < 0) return false; var afterDot = line.substring(firstDot + 1); var split = afterDot.split(' '); if (split.length != 3 && split.length != 2) { if (isTraceEnabled) ms.log("MetricsParser.matchTokenizer split count is " + split.length + " for line " + line); return false; } metricValue = parseFloat(split[1]); if (isNaN(metricValue)) return false; var metric = "" + split[0]; var metricParts = metric.split('.'); var metricLength = metricParts.length; // If there is a dot character in the metric name, use the part before the dot as the resource name if (metricLength == 1) metricType = metric; else { var parsedCheck = JSON.parse(""+check); var entrypointResource = MonUtils.getEntrypointsResourceName(node, parsedCheck); if (JSUtil.notNil(entrypointResource)) resource = entrypointResource; //examples: disk_usage.root.run.used, disk_usage.root.snap.core.8213.used, disk_usage.root.snap.core.8268.used_percentage if (metricLength > 2 && metricParts[0] == "disk_usage" && (metricParts[metricLength-1] == "used" || metricParts[metricLength-1] == "used(MB)" ||metricParts[metricLength-1] == "used(GB)"|| metricParts[metricLength-1] == "used_percentage" || metricParts[metricLength-1] == "avail" || metricParts[metricLength-1] == "avail(MB)" || metricParts[metricLength-1] == "avail(GB)" || metricParts[metricLength-1] == "total(MB)" || metricParts[metricLength-1] == "total(GB)" )) { metricType = metricParts[0] + "." + metricParts[metricLength-1]; resource = ''; for (var i=1; i<metricLength-1; i++) { if (resource != '') resource += '.'; resource += metricParts[i]; } //examples: cpu.cpu1.nice || disk.sda1.icapacity || proc.sh__c_metrics_process_status_rb___u_servicenow.VmRSS } else if (metricLength == 3 && (metricParts[0] == "disk" || metricParts[0] == "cpu" || metricParts[0] == "proc" || metricParts[0] == "interface")) { resource = metricParts[1]; metricType = metricParts[0] + "." + metricParts[2]; //example: system.network.Network_Interface(Intel(R)_PRO_1000_MT_Network_Connection).Current_Bandwidth if(metricParts[0] == "interface") metricType = "system.network_" + metricType; } else if (metricLength == 4 && metricParts[0] == "system" && metricParts[1] == "network") { resource = metricParts[2]; if (resource.startsWith("Network_Interface")) { resource = resource.replace("Network_Interface", ""); //get rid of 'Network_Interface' prefix //get rid of "(" and ")" if (resource.startsWith("(") && resource.endsWith(")")) { resource = resource.substring(1, resource.length - 1); } } metricType = metricParts[0] + "." + metricParts[1] + "." + metricParts[3]; //example: sql._Total.MSSQL$SQLEXPRESS:Buffer_Manager.Page_life_expectancy } else if (metricLength == 4 && metricParts[0] == "sql" && metricParts[1] == "_Total") { var parts = metricParts[2].split('$'); if (parts.length == 2 && parts[0] == 'MSSQL') { var parts2 = parts[1].split(':'); if (parts2.length == 2) { resource = parts2[0]; metricType = metricParts[0] + "." + metricParts[1] + "." + parts[0] + ":" + parts2[1] + "." + metricParts[3]; } } //example1 length 5: oracle.ORAWIN1.tablespace.USERS.sum_bytes //example2 length 4: oracle.cdb2.stats.Buffer_Cache_Hit_Ratio } else if ((metricLength == 4 || metricLength == 5) && metricParts[0] == "oracle") { if (metricParts[2] == 'tablespace' && metricLength == 5) { resource = metricParts[1] + '.' + metricParts[3]; metricType = metricParts[0] + "." + metricParts[2] + "." + metricParts[4]; } else if (metricLength == 4) { resource = metricParts[1]; metricType = metricParts[0] + "." + metricParts[2] + "." + metricParts[3]; } // Remove 'ps' and 'g1' from metric type: // example1 length 5: java.memory_pool.ps_old_gen.usage.committed => java.memory_pool.old_gen.usage.committed // example2 length 4: java.gc.ps_scavenge.collection_count => java.gc.scavenge.collection_count } else if ((metricLength == 4 || metricLength == 5) && metricParts[0] == "java") { parts = metricParts[2].split('_'); if(parts[0] == 'g1' || parts[0] == 'ps') { parts.splice(0,1); PartsJoined = parts.join('_'); metricType = metricParts[0] + "." + metricParts[1] + "." + PartsJoined + "." + metricParts[3]; if (metricLength == 5) metricType += "." + metricParts[4]; } // Remove the curl_timings or http_timings from metric type // e.g. 'curl_timings.time_total' ,'http_timings.time_total' } else if (metricLength == 2 && ( metricParts[0] == "curl_timings" || metricParts[0] == "http_timings" )) { metricType = metricParts[1]; } else if (metricParts[0] == "tomcat" && metricLength == 4 && (metricParts[1] == "threads" || metricParts[1] == "req" || metricParts[1] == 'jsp')) { metricType = metricParts[0] + "." + metricParts[1] + "." + metricParts[3]; resource = metricParts[2]; }else if (metricLength == 4 && metricParts[0] == "pgsql") { if (metricParts[1] == "tables_size") { metricType = metricParts[0] + "." + metricParts[1]; resource = metricParts[2] + "." + metricParts[3]; } else { metricType = metricParts[0] + "." + metricParts[1] + "." + metricParts[2]; resource = metricParts[3]; } }else if (metricParts[0] == "mongodb" && metricParts[1] == "databaseSizes") { metricType = metricParts[0] + "." + metricParts[1] + "." + metricParts[3]; resource = metricParts[2]; }else if (metricParts[0] == "rabbitmq" && metricParts[2] == "queue") { metricType = metricParts[0] + "." + metricParts[2] + "." + metricParts[4]; resource = metricParts[1] + "." + metricParts[3]; } else if (metricParts[0] == "vsphere"){ metricType = metricParts[0] + "." + metricParts[1] + "." + metricParts[2] + "." + metricParts[3] + "." + metricParts[4]; if(metricLength == 6){ if(metricParts[5] != "total"){ resource = metricParts[5]; } } // 3 vpshere disk metrics have metricLength 7, below if condition is to cover that case if(metricLength == 7){ metricType = metricType + "." + metricParts[5]; if(metricParts[6] != "total"){ resource = metricParts[6]; } } // 6 HostSystem metrics starting with mem.vmfs have metric length 8 if(metricLength == 8){ metricType = metricType + "." + metricParts[5] + "." + metricParts[6]; if(metricParts[7] != "total"){ resource = metricParts[7]; } } } else if (metricParts[0] == "glassfish") { if (metricParts[1] == "applications") { metricType = metricParts[0] + "." + metricParts[1] + "." + metricParts[3]; resource = metricParts[2]; } else if (metricParts[1] == "resources") { metricType = metricParts[0] + "." + metricParts[1] + "." + metricParts[3]; resource = metricParts[2]; } } else if (metricParts[0].includes("MSExchange")) { if(metricLength == 3 && (metricParts[0] == "MSExchange_ADAccess_Domain_Controllers" || metricParts[0] == "MSExchange_ADAccess_Processes" || metricParts[0] == "MSExchange_HttpProxy" || metricParts[0] == "MSExchangeIS_Store" || metricParts[0] == "MSExchangeIS_Client_Type" || metricParts[0] == "MSExchange_WorkloadManagement_Workloads") && !metric.includes("total") && !metric.includes("Total")) { metricType = metricParts[0] + "." + metricParts[2]; resource = metricParts[1]; } else if (metricLength == 3 && metricParts[0] =="MSExchange_Database_Instances"){ metricType = metricParts[0] + "." + metricParts[2]; resource = metricParts[1]; } } else if (metricParts[0].toLowerCase() == "tomcat" && metricLength == 5 ) { metricType = metricParts[0] + "." + metricParts[1] + "."+ metricParts[4]; resource = metricParts[2]+ "." + metricParts[3]; } } if (metricType == "") metricType = metric; return true;};var makeMetric = function(node, check) { var ciId = check.getCiId(); var agentId = checkResult.getAgentId(); var ciIdentifier = new HashMap(); ciIdentifier.put("agent", node); if (ciId) ciIdentifier.put("ci_id", ciId); if (resource) { ciIdentifier.put("resource_path", resource); if (isTraceEnabled) ms.log("MetricParser.makeMetric resource is " + resource + ", ciIdentifier key count: " + ciIdentifier.size() + " resource_path: " + ciIdentifier.get("resource_path") + ", metricValue: " + metricValue); } // In case of proxy agent, the node field in the metric should not be the agent IP, but taken from the target_ip parameter on the check var nodeInMetric = node; if (check.getParam(MonConstants.TARGET_IP)) nodeInMetric = check.getParam(MonConstants.TARGET_IP); var metric = new RawMetric(metricType, nodeInMetric, metricValue, new Packages.java.lang.Long(checkResult.getTimestamp()) * 1000, ciIdentifier, "ITOM Agent"); if(agentId) metric.setSourceInstance(agentId); metric.setCI(ciId); return metric;};var output = check.getOutput();var status = check.getStatus();if ((String(output)) !== "" && ((String(output)).includes("error:")|| (String(output)).includes("Error:") || status == "1" || status == "2")) { ms.log("MetricsParser received an error/unexpected output: " + output);} else { var metricList = new ArrayList(); var outputLines = String(output).split("\n"); for (var i = 0; i < outputLines.length; i++) { //ignore metrics that contain redacted sensitive data if (!outputLines[i].contains("REDACTED")) { metricType = ""; resource = ""; var matches = matchTokenizer(outputLines[i], node); if (matches) { var metric = makeMetric(node, check); metricList.add(metric); } } } MetricFactory.getMetricHandler().handleMetric(metricList); var metricNumRes = metricList.size(); if (!isNaN(metricNumRes)) { var numOfMetrics = parseInt(metricNumRes); MonitoringEndpoint.getMetricsRate().addOccurrences(numOfMetrics); client.getMetricsCounter().addOccurrences(numOfMetrics); }}Related Problem: PRB1661186