Name

sn_app_insights.ThresholdUtils

Description

No description available

Script

var ThresholdUtils = Class.create();
ThresholdUtils.prototype = {
  initialize: function() {
      this.QUEUE_DEPTH_LIMIT_METRICS = {
          "api_int_queue_depth": "API_INT",
          "default_queue_depth": "Default",
          "amb_send_queue_depth": "AMB_SEND",
          "amb_receive_queue_depth": "AMB_RECEIVE"
      };
  },

  buildThresholdData: function(resultArray, metricName, tableName) {
      var combinedArray = [];
      resultArray.forEach(function(el) {
          var lineArr = el.getValues();
          for (var i = 0; i < lineArr.length; ++i) {
              lineArr[i] = parseFloat(lineArr[i]);
              if (isNaN(lineArr[i]) || lineArr[i] == null) {
                  lineArr.splice(i, 1);
                  --i;
              }
          }
          combinedArray = combinedArray.concat(lineArr);
      });

      combinedArray.sort(function(a, b) {
          return a - b;
      });

      var length = combinedArray.length;
      var thresholdData = [];
      thresholdData.push({
          value: combinedArray[Math.floor(length * 0.95)],
          label: gs.getMessage("95th Percentile"),
          type: "neutral-12"
      });

      thresholdData.push({
          value: combinedArray[Math.floor(length * 0.50)],
          label: gs.getMessage("Median"),
          type: "neutral-12"
      });

      var thresholds = new MetricTriggerUtils().getThresholdsForMetric(metricName, tableName);

      thresholds.forEach(function(threshold) {
          thresholdData.push({
              value: threshold.value,
              label: threshold.label,
              type: "alert-warning-5"
          });
      });

      this.addQueueDepthLimitThreshold(thresholdData, metricName);

      return thresholdData;
  },

  buildThresholdConfig: function() {
      return {
          "alert-warning-5": {
              "color": "#635C0B", //now-color--alert-warning-5
              "fontSize": 12
          },
          "alert-critical-2": {
              "color": "#C83C36", //now-color--alert-critical-2
              "dashPattern": "line",
              "fontSize": 12
          },
          "neutral-12": {
              "color": "#425051", //now-color--neutral-12
              "fontSize": 12
          }
      };
  },

  addQueueDepthLimitThreshold: function(thresholdData, metricName) {
      if (this.QUEUE_DEPTH_LIMIT_METRICS[metricName] === undefined)
          return;

      var nodeRecord = new GlideRecord("sys_cluster_state");
      nodeRecord.query();
      if (!nodeRecord.next())
          return;

      var xmlStatsParser = new ParseXmlStats(nodeRecord.node_stats.stats);
      var queueDepthLimit = xmlStatsParser.getQueueDepthLimit(this.QUEUE_DEPTH_LIMIT_METRICS[metricName]);
      thresholdData.push({
          value: queueDepthLimit,
          label: gs.getMessage("Queue Depth Limit"),
          type: "alert-critical-2"
      });
  },

  type: 'ThresholdUtils'
};

Sys ID

d60d47b97fc130100cb8f3c26f2a0cc4

Offical Documentation

Official Docs: