Class PulseMetrics

java.lang.Object
com.cyara.apisamples.PulseMetrics
All Implemented Interfaces:
java.lang.Comparable<PulseMetrics>

public class PulseMetrics
extends java.lang.Object
implements java.lang.Comparable<PulseMetrics>
Training demo built for Xchange 2020 that uses Cyara's Pulse API to collect call results and generate metrics into an HTML file.

This is not an official Cyara product and is not officially supported. It is used for demonstration and training purposes. For assistance, contact chris.ryan@cyara.com

Version:
1.7
Author:
Chris Ryan
  • Field Summary

    Fields 
    Modifier and Type Field Description
    private int problemTestCaseFailCount  
    private int problemTestCaseId  
    private java.lang.String problemTestCaseName  
  • Constructor Summary

    Constructors 
    Constructor Description
    PulseMetrics​(int failTCId, java.lang.String failTCName, int failCount)  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String buildStatsDatasets​(int[][] timeStats, java.lang.String dataType)
    Prepares data and generates the JavaScript for the hour by hour response time metrics chart.
    int compareTo​(PulseMetrics o)
    Compares two fail counts and checks equality.
    static javax.json.JsonObject convertAPIOutputToJson​(java.lang.String apiString)
    Convert a String object with Json format into a JsonObject
    static java.lang.String generateComparisonScatterHtml​(java.lang.StringBuilder scatterData, java.lang.String canvasId, java.lang.String yLabelString)
    Create the HTML structure for a scatter graph.
    static java.lang.String generateDaysChartHtml​(int[] totalsByDayArr, int[] failsByDayArr, int[] satsByDayArr, int[] successesByDayArr, java.lang.String timeframe)
    Generates the HTML and JavaScript for the day by day calls made number categorized by overall result.
    static java.lang.String generateHoursChartHtml​(int[] totalsByHourArr, int[] failsByHourArr, int[] satsByHourArr, int[] successesByHourArr, java.lang.String timeframe)
    Prepares data and generates the HTML and JavaScript for the hour by hour calls made number categorized by overall result.
    static java.lang.String generateKeyToken​(java.lang.String baseUrl, java.lang.String authStringEnc)
    Use the 2.5 API to dynamically generate a fresh 3.0 API key:token pair.
    static java.lang.String generatePieHtml​(java.lang.String outcome, java.util.HashMap<java.lang.String,​java.lang.Integer> sortedTestCaseIds, java.util.HashMap<java.lang.Integer,​java.lang.String> campaignTCResultIds, long startNS, long endNS, java.lang.String baseUrl, int accountNum, java.lang.String timeframe)
    Prepares data and generates the HTML and JavaScript for the pie chart showing the top 10 most failed test cases in the given time frame.
    static java.lang.String generateTimesChartHtml​(java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> connectionTimesList, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> initiationTimesList, java.lang.String timeframe)
    Prepares data and generates the HTML for the hour by hour response time metrics chart.
    static void getComparisonStats​(java.lang.String jsonFile, java.text.SimpleDateFormat apiFormat, java.util.ArrayList<java.lang.String> comparedTimeframes, java.lang.String outputFile)
    Take in one or more date ranges and build the necessary Chart.JS structure for a scatter graph.
    private int getFailCount()
    Get the problematic test case failure count
    static int getLastTestResultId​(java.lang.String jsonFile)
    Parse the source file with all our previously grabbed results, and find the newest, most recent call grabbed.
    private int getTestCaseId()
    Get the problematic test case ID
    private java.lang.String getTestCaseName()
    Get the problematic test case Name
    static void getTimeframeStats​(java.lang.String jsonFile, java.text.SimpleDateFormat apiFormat, java.util.Date startDate, java.util.Date endDate, java.lang.String timeframe, java.lang.String baseUrl, int accountNum, java.lang.String outputFile)
    Prepares data and makes calls for all the charts used to display data for the provided time frame.
    static void main​(java.lang.String[] argv)  
    static java.util.HashMap<java.lang.String,​java.lang.Integer> sortByValue​(java.util.HashMap<java.lang.String,​java.lang.Integer> failedTestCaseIds)
    Sort hashmap by values from lowest to highest.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PulseMetrics

      public PulseMetrics​(int failTCId, java.lang.String failTCName, int failCount)
  • Method Details

    • main

      public static void main​(java.lang.String[] argv)
    • getComparisonStats

      public static void getComparisonStats​(java.lang.String jsonFile, java.text.SimpleDateFormat apiFormat, java.util.ArrayList<java.lang.String> comparedTimeframes, java.lang.String outputFile)
      Take in one or more date ranges and build the necessary Chart.JS structure for a scatter graph. Ultimately, the method to generate said scatter graph is called from here.

      The previously grabbed API data is accessed and response times for Step 0 and Step 1 are stored. These reflect the connection times and initiation times, respectively.

      Parameters:
      jsonFile - The source file of all the previously grabbed API data
      apiFormat - The time format the 3.0 Cyara API uses
      comparedTimeframes - All of the different date ranges we want our scatter graph to show
      outputFile - The HTML file metrics are outputted to
      Since:
      1.0
      See Also:
      generateComparisonScatterHtml(java.lang.StringBuilder,java.lang.String,java.lang.String)
    • generateComparisonScatterHtml

      public static java.lang.String generateComparisonScatterHtml​(java.lang.StringBuilder scatterData, java.lang.String canvasId, java.lang.String yLabelString)
      Create the HTML structure for a scatter graph. The scatter graph generated is used for viewing results within one or more date ranges.
      Parameters:
      scatterData - The JavaScript from data collection containing the graph data (time of day and response time)
      canvasId - The html id used to reference this chart
      yLabelString - The label on the chart to tell the user what this chart is showing
      Returns:
      The JavaScript and HTML for the scatter chart
      Since:
      1.0
      See Also:
      getComparisonStats(java.lang.String,java.text.SimpleDateFormat,java.util.ArrayList<java.lang.String>,java.lang.String)
    • getTimeframeStats

      public static void getTimeframeStats​(java.lang.String jsonFile, java.text.SimpleDateFormat apiFormat, java.util.Date startDate, java.util.Date endDate, java.lang.String timeframe, java.lang.String baseUrl, int accountNum, java.lang.String outputFile)
      Prepares data and makes calls for all the charts used to display data for the provided time frame.

      Upon generation of the chart HTMLs, appends said HTML to the output HTML file.

      Parameters:
      jsonFile - The source file of all the previously grabbed API data
      apiFormat - The time format the 3.0 Cyara API uses
      startDate - The first date in which data is retrieved, inclusive
      endDate - The last date in which data is retrieved, exclusive
      timeframe - The human friendly label for the chart telling the time period
      baseUrl - The core Cyara Portal URL
      accountNum - The account number in the portal referenced
      outputFile - The HTML file metrics are outputted to
      Since:
      1.0
      See Also:
      generateDaysChartHtml(int[],int[],int[],int[],java.lang.String), generatePieHtml(java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>,java.util.HashMap<java.lang.Integer,java.lang.String>,long,long,java.lang.String,int,java.lang.String), generateHoursChartHtml(int[],int[],int[],int[],java.lang.String), generateTimesChartHtml(java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>,java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>,java.lang.String)
    • generateTimesChartHtml

      public static java.lang.String generateTimesChartHtml​(java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> connectionTimesList, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> initiationTimesList, java.lang.String timeframe)
      Prepares data and generates the HTML for the hour by hour response time metrics chart. This data will be broken down into the min, max, mean, median, mode and 95 percentile.
      Parameters:
      connectionTimesList - The 2D ArrayList of all our connection times for every hour of the day
      initiationTimesList - The 2D ArrayList of all our initiation times for every hour of the day
      timeframe - The human friendly label for the chart telling the time period
      Returns:
      The HTML for the hourly response metrics chart
      Since:
      1.0
      See Also:
      getTimeframeStats(java.lang.String,java.text.SimpleDateFormat,java.util.Date,java.util.Date,java.lang.String,java.lang.String,int,java.lang.String), buildStatsDatasets(int[][],java.lang.String)
    • buildStatsDatasets

      public static java.lang.String buildStatsDatasets​(int[][] timeStats, java.lang.String dataType)
      Prepares data and generates the JavaScript for the hour by hour response time metrics chart. This data will be broken down into the min, max, mean, median, mode and 95 percentile.
      Parameters:
      timeStats - The metrics of each hour of the day
      dataType - The human friendly label for data tracked
      Returns:
      The JavaScript for the hourly response metrics chart
      Since:
      1.0
      See Also:
      generateTimesChartHtml(java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>,java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>,java.lang.String)
    • generatePieHtml

      public static java.lang.String generatePieHtml​(java.lang.String outcome, java.util.HashMap<java.lang.String,​java.lang.Integer> sortedTestCaseIds, java.util.HashMap<java.lang.Integer,​java.lang.String> campaignTCResultIds, long startNS, long endNS, java.lang.String baseUrl, int accountNum, java.lang.String timeframe)
      Prepares data and generates the HTML and JavaScript for the pie chart showing the top 10 most failed test cases in the given time frame.
      Parameters:
      outcome - The call result we're looking for
      sortedTestCaseIds - All the test cases found within the given time frame
      campaignTCResultIds - All the campaigns in the given time frame which had a failure
      startNS - The C# representation of the starting nanoseconds for our time frame
      endNS - The C# representation of the ending nanoseconds for our time frame
      baseUrl - The core Cyara Portal URL
      accountNum - The account number in the portal referenced
      timeframe - The human friendly label for the chart telling the time period
      Returns:
      The HTML and JavaScript for the pie chart
      Since:
      1.0
      See Also:
      getTimeframeStats(java.lang.String,java.text.SimpleDateFormat,java.util.Date,java.util.Date,java.lang.String,java.lang.String,int,java.lang.String)
    • generateHoursChartHtml

      public static java.lang.String generateHoursChartHtml​(int[] totalsByHourArr, int[] failsByHourArr, int[] satsByHourArr, int[] successesByHourArr, java.lang.String timeframe)
      Prepares data and generates the HTML and JavaScript for the hour by hour calls made number categorized by overall result.
      Parameters:
      totalsByHourArr - The amount of total calls that happened for each hour of the time frame
      failsByHourArr - The amount of failed calls that happened for each hour of the time frame
      satsByHourArr - The amount of satisfactory calls that happened for each hour of the time frame
      successesByHourArr - The amount of successful calls that happened for each hour of the time frame
      timeframe - The human friendly label for the chart telling the time period
      Returns:
      The HTML and JavaScript for the calls per hour chart
      Since:
      1.0
      See Also:
      getTimeframeStats(java.lang.String,java.text.SimpleDateFormat,java.util.Date,java.util.Date,java.lang.String,java.lang.String,int,java.lang.String)
    • generateDaysChartHtml

      public static java.lang.String generateDaysChartHtml​(int[] totalsByDayArr, int[] failsByDayArr, int[] satsByDayArr, int[] successesByDayArr, java.lang.String timeframe)
      Generates the HTML and JavaScript for the day by day calls made number categorized by overall result.

      The days are shown in a column chart and start on Monday.

      Parameters:
      totalsByDayArr - The amount of total calls that happened for each hour of the time frame
      failsByDayArr - The amount of failed calls that happened for each hour of the time frame
      satsByDayArr - The amount of satisfactory calls that happened for each hour of the time frame
      successesByDayArr - The amount of successful calls that happened for each hour of the time frame
      timeframe - The human friendly label for the chart telling the time period
      Returns:
      The HTML and JavaScript for the calls per day chart
      Since:
      1.0
      See Also:
      getTimeframeStats(java.lang.String,java.text.SimpleDateFormat,java.util.Date,java.util.Date,java.lang.String,java.lang.String,int,java.lang.String)
    • getLastTestResultId

      public static int getLastTestResultId​(java.lang.String jsonFile)
      Parse the source file with all our previously grabbed results, and find the newest, most recent call grabbed.
      Parameters:
      jsonFile - The source file of all the previously grabbed API data
      Returns:
      The most recent Test Result Id
      Since:
      1.0
    • convertAPIOutputToJson

      public static javax.json.JsonObject convertAPIOutputToJson​(java.lang.String apiString)
      Convert a String object with Json format into a JsonObject
      Parameters:
      apiString - The Json string to convert into Json
      Returns:
      The JsonObject representation of the input String
      Since:
      1.0
    • generateKeyToken

      public static java.lang.String generateKeyToken​(java.lang.String baseUrl, java.lang.String authStringEnc)
      Use the 2.5 API to dynamically generate a fresh 3.0 API key:token pair.
      Parameters:
      baseUrl - The core Cyara Portal URL
      authStringEnc - The base64 encoded username and password
      Returns:
      The raw API output
      Since:
      1.0
    • sortByValue

      public static java.util.HashMap<java.lang.String,​java.lang.Integer> sortByValue​(java.util.HashMap<java.lang.String,​java.lang.Integer> failedTestCaseIds)
      Sort hashmap by values from lowest to highest.
      Parameters:
      failedTestCaseIds - The unsorted hashmap containing the names of each failed test case and their failure count
      Returns:
      The sorted hashmap
      Since:
      1.0
    • compareTo

      public int compareTo​(PulseMetrics o)
      Compares two fail counts and checks equality.
      Specified by:
      compareTo in interface java.lang.Comparable<PulseMetrics>
      Parameters:
      o - The provided PuseMetric failure object
      Returns:
      The equality check
      Since:
      1.0
    • getTestCaseId

      private int getTestCaseId()
      Get the problematic test case ID
      Returns:
      The test case ID
      Since:
      1.0
    • getTestCaseName

      private java.lang.String getTestCaseName()
      Get the problematic test case Name
      Returns:
      The test case name
      Since:
      1.0
    • getFailCount

      private int getFailCount()
      Get the problematic test case failure count
      Returns:
      The failure count
      Since:
      1.0