Package com.cyara.apisamples
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 JsonObjectstatic 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 countstatic 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 IDprivate java.lang.String
getTestCaseName()
Get the problematic test case Namestatic 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.
-
Field Details
-
problemTestCaseId
private int problemTestCaseId -
problemTestCaseName
private java.lang.String problemTestCaseName -
problemTestCaseFailCount
private int problemTestCaseFailCount
-
-
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 dataapiFormat
- The time format the 3.0 Cyara API usescomparedTimeframes
- All of the different date ranges we want our scatter graph to showoutputFile
- 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 chartyLabelString
- 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 dataapiFormat
- The time format the 3.0 Cyara API usesstartDate
- The first date in which data is retrieved, inclusiveendDate
- The last date in which data is retrieved, exclusivetimeframe
- The human friendly label for the chart telling the time periodbaseUrl
- The core Cyara Portal URLaccountNum
- The account number in the portal referencedoutputFile
- 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 dayinitiationTimesList
- The 2D ArrayList of all our initiation times for every hour of the daytimeframe
- 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 daydataType
- 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 forsortedTestCaseIds
- All the test cases found within the given time framecampaignTCResultIds
- All the campaigns in the given time frame which had a failurestartNS
- The C# representation of the starting nanoseconds for our time frameendNS
- The C# representation of the ending nanoseconds for our time framebaseUrl
- The core Cyara Portal URLaccountNum
- The account number in the portal referencedtimeframe
- 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 framefailsByHourArr
- The amount of failed calls that happened for each hour of the time framesatsByHourArr
- The amount of satisfactory calls that happened for each hour of the time framesuccessesByHourArr
- The amount of successful calls that happened for each hour of the time frametimeframe
- 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 framefailsByDayArr
- The amount of failed calls that happened for each hour of the time framesatsByDayArr
- The amount of satisfactory calls that happened for each hour of the time framesuccessesByDayArr
- The amount of successful calls that happened for each hour of the time frametimeframe
- 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 URLauthStringEnc
- 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
Compares two fail counts and checks equality.- Specified by:
compareTo
in interfacejava.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
-