Howto create custom metric diagrams as part of your scripts

Howto create custom ZebraTester Diagrams
By Johan Sandberg – johan.sandberg@performancetest.se

In this example a Java Plugin is created that can create two custom diagrams with long values in your scripts.

Start by creating a basic Java plugin using the Create Load Test Plugin Template
Use two type long input parameters to the Plugin.
In this example they are named v1 for value 1 and v2 for value 2.

Add the following two lines of Java code as class member variables

private DataCollectionSequence CustomSequence_1 = new DataCollectionSequence(1,"Custom Diagram 1", "", "%", null); 
private DataCollectionSequence CustomSequence_2 = new DataCollectionSequence(2,"Custom Diagram 2", "", "%", null); 

Add the following Java code in the execute method

	HttpTestURL httpTestURL = pluginContext.getHttpTestURL();
	if (pluginContext.urlPassed())
	{
		DataCollectionFloatItem CustomValueItem_1 = new DataCollectionFloatItem(System.currentTimeMillis(),Float.parseFloat(Long.toString(v1)));
		DataCollectionFloatItem CustomValueItem_2 = new DataCollectionFloatItem(System.currentTimeMillis(),Float.parseFloat(Long.toString(v2)));
		CustomSequence_1.addItem(CustomValueItem_1);
		CustomSequence_2.addItem(CustomValueItem_2);			
	}

Finally add the following Java code to the deconstruct method

	LoadtestPluginContext pluginContext = (LoadtestPluginContext) context;
	
	CustomSequence_1.addClusterOption(DataCollectionSequence.CLUSTER_OPTION_MERGE_FLOAT_ITEMS_TO_AVERAGE,"Merged Cluster Data 1");
	pluginContext.getPerformanceData().addDataCollectionSequence(CustomSequence_1);
	
	CustomSequence_2.addClusterOption(DataCollectionSequence.CLUSTER_OPTION_MERGE_FLOAT_ITEMS_TO_AVERAGE,"Merged Cluster Data 2");
	pluginContext.getPerformanceData().addDataCollectionSequence(CustomSequence_2);

Compile and add the Java Plugin to your script
Add two variables to hold the trend value 1 and 2.

The Custom Trend will be part of the result and report under Diagram: External Measured Data.
Below is a example Custom Trend with two diagrams.

Best Regards
//Johan Sandberg

4 Likes

Thanks for sharing that guide with us, been wanting to play around with that feature for some time :+1:

And welcome to the forum!

Interesting and very useful. Thanks!