Collect Shelly plug power live in JMeter energy experiments
This commit is contained in:
1 parent
a69b9b2118
commit
e50cf0a011
13 files changed
+634
-22
No files matched your search
@@ -70,12 +70,40 @@ def record(t, correction=False):
|
||||
request(t,'Remove duplicate test entry','DELETE','/api/observations/${observation_id}',status=204)
|
||||
request(t,'Confirm removal','GET','/api/observations/${observation_id}',status=404)
|
||||
|
||||
def shelly_group(tree):
|
||||
group,gt=element(tree,'ThreadGroup','ThreadGroupGui','Shelly live power')
|
||||
prop(group,'ThreadGroup.on_sample_error','continue')
|
||||
loop=E.SubElement(group,'elementProp',name='ThreadGroup.main_controller',elementType='LoopController',guiclass='LoopControlPanel',testclass='LoopController',enabled='true')
|
||||
prop(loop,'LoopController.continue_forever',False,'boolProp');prop(loop,'LoopController.loops',-1)
|
||||
for k,v in [('ThreadGroup.num_threads','1'),('ThreadGroup.ramp_time','0'),('ThreadGroup.duration','${__P(total_duration_seconds,16210)}'),('ThreadGroup.delay','0')]:prop(group,k,v)
|
||||
prop(group,'ThreadGroup.scheduler',True,'boolProp')
|
||||
e,t=element(gt,'HTTPSamplerProxy','HttpTestSampleGui','POWER Shelly status')
|
||||
E.SubElement(E.SubElement(e,'elementProp',name='HTTPsampler.Arguments',elementType='Arguments'),'collectionProp',name='Arguments.arguments')
|
||||
for k,v in [('HTTPSampler.domain','${__P(shelly_host,192.168.1.44)}'),('HTTPSampler.port','${__P(shelly_port,80)}'),('HTTPSampler.protocol','http'),('HTTPSampler.path','/rpc/Switch.GetStatus?id=${__P(shelly_switch_id,0)}'),('HTTPSampler.method','GET'),('HTTPSampler.implementation','HttpClient4'),('HTTPSampler.connect_timeout','3000'),('HTTPSampler.response_timeout','3000')]:prop(e,k,v)
|
||||
for k,v in [('HTTPSampler.follow_redirects',False),('HTTPSampler.use_keepalive',True)]:prop(e,k,v,'boolProp')
|
||||
script(t,'JSR223Timer','Fixed meter cadence', "if (!vars.get('shelly_last_poll_ms')) return 0L; return Math.max(0L, Long.parseLong(vars.get('shelly_last_poll_ms')) + Long.parseLong(props.getProperty('shelly_interval_ms','5000')) - System.currentTimeMillis())")
|
||||
script(t,'JSR223PreProcessor','Clear stale power values', "['shelly_power_watts','shelly_voltage_volts','shelly_current_amps','shelly_energy_wh'].each { vars.put(it,'') }")
|
||||
script(t,'JSR223Assertion','Validate and extract plug readings', """vars.put('shelly_last_poll_ms',prev.getStartTime().toString())
|
||||
try {
|
||||
assert prev.getResponseCode() == '200'
|
||||
def json=new groovy.json.JsonSlurper().parseText(prev.getResponseDataAsString())
|
||||
assert json.output == true : 'Outlet is off'
|
||||
def readings=[shelly_power_watts:json.apower,shelly_voltage_volts:json.voltage,shelly_current_amps:json.current,shelly_energy_wh:json.aenergy?.total]
|
||||
readings.each { key,value -> assert value instanceof Number && Double.isFinite(value.doubleValue()) && value >= 0; vars.put(key,value.toString()) }
|
||||
} catch (Throwable error) {
|
||||
AssertionResult.setFailure(true);AssertionResult.setFailureMessage('Shelly status/measurement unavailable');prev.setSuccessful(false)
|
||||
}
|
||||
""")
|
||||
collector,_=element(gt,'ResultCollector','SimpleDataWriter','Shelly measurements saved live')
|
||||
prop(collector,'filename','${__P(shelly_file,shelly.csv)}');prop(collector,'ResultCollector.error_logging',False,'boolProp')
|
||||
|
||||
for scenario in ['recording','review','correction','professional','mixed','idle']:
|
||||
root=E.Element('jmeterTestPlan',version='1.2',properties='5.0',jmeter='5.6.3'); tree=E.SubElement(root,'hashTree')
|
||||
plan, pt=element(tree,'TestPlan','TestPlanGui','HealthApp energy: '+scenario)
|
||||
prop(plan,'TestPlan.comments','Synthetic closed-loop sessions; default duration four hours. Setup and energy-meter control are external.')
|
||||
prop(plan,'TestPlan.comments','Synthetic closed-loop sessions; default duration four hours. Setup is external; Shelly power is collected live without changing the outlet.')
|
||||
prop(plan,'TestPlan.functional_mode',False,'boolProp'); prop(plan,'TestPlan.serialize_threadgroups',False,'boolProp')
|
||||
E.SubElement(E.SubElement(plan,'elementProp',name='TestPlan.user_defined_variables',elementType='Arguments',guiclass='ArgumentsPanel',testclass='Arguments',enabled='true'),'collectionProp',name='Arguments.arguments')
|
||||
shelly_group(pt)
|
||||
collector, _ = element(pt,'kg.apc.jmeter.perfmon.PerfMonCollector','kg.apc.jmeter.vizualizers.PerfMonGui','NUC live CPU RAM disk and network')
|
||||
collector.set('enabled','true')
|
||||
prop(collector,'filename','${__P(perfmon_file,perfmon.csv)}')
|
||||
@@ -88,7 +116,7 @@ for scenario in ['recording','review','correction','professional','mixed','idle'
|
||||
prop(group,'ThreadGroup.on_sample_error','stopthread')
|
||||
loop=E.SubElement(group,'elementProp',name='ThreadGroup.main_controller',elementType='LoopController',guiclass='LoopControlPanel',testclass='LoopController',enabled='true')
|
||||
prop(loop,'LoopController.continue_forever',False,'boolProp'); prop(loop,'LoopController.loops',-1)
|
||||
for k,v in [('ThreadGroup.num_threads','${__P(users,1)}'),('ThreadGroup.ramp_time','${__P(ramp_seconds,60)}'),('ThreadGroup.duration','${__P(total_duration_seconds,16205)}'),('ThreadGroup.delay','0')]: prop(group,k,v)
|
||||
for k,v in [('ThreadGroup.num_threads','${__P(users,1)}'),('ThreadGroup.ramp_time','${__P(ramp_seconds,60)}'),('ThreadGroup.duration','${__P(total_duration_seconds,16210)}'),('ThreadGroup.delay','0')]: prop(group,k,v)
|
||||
prop(group,'ThreadGroup.scheduler',True,'boolProp'); prop(group,'ThreadGroup.same_user_on_next_iteration',True,'boolProp')
|
||||
if scenario=='idle':
|
||||
prop(group,'ThreadGroup.num_threads','1');prop(group,'ThreadGroup.ramp_time','0')
|
||||
|
||||
Reference in new issue
Block a user