Collect Shelly plug power live in JMeter energy experiments

This commit is contained in:
Steffen committed 2026-10-07 22:12:58 +02:00
1 parent a69b9b2118
commit e50cf0a011
13 files changed
+634 -22

No files matched your search

+72 -2
View File
@@ -2,7 +2,7 @@
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.3">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="HealthApp energy: recording" enabled="true">
<stringProp name="TestPlan.comments">Synthetic closed-loop sessions; default duration four hours. Setup and energy-meter control are external.</stringProp>
<stringProp name="TestPlan.comments">Synthetic closed-loop sessions; default duration four hours. Setup is external; Shelly power is collected live without changing the outlet.</stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" enabled="true">
@@ -10,6 +10,76 @@
</elementProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Shelly live power" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">-1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">0</stringProp>
<stringProp name="ThreadGroup.duration">${__P(total_duration_seconds,16210)}</stringProp>
<stringProp name="ThreadGroup.delay">0</stringProp>
<boolProp name="ThreadGroup.scheduler">true</boolProp>
</ThreadGroup>
<hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="POWER Shelly status" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments">
<collectionProp name="Arguments.arguments" />
</elementProp>
<stringProp name="HTTPSampler.domain">${__P(shelly_host,192.168.1.44)}</stringProp>
<stringProp name="HTTPSampler.port">${__P(shelly_port,80)}</stringProp>
<stringProp name="HTTPSampler.protocol">http</stringProp>
<stringProp name="HTTPSampler.path">/rpc/Switch.GetStatus?id=${__P(shelly_switch_id,0)}</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
<stringProp name="HTTPSampler.connect_timeout">3000</stringProp>
<stringProp name="HTTPSampler.response_timeout">3000</stringProp>
<boolProp name="HTTPSampler.follow_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
</HTTPSamplerProxy>
<hashTree>
<JSR223Timer guiclass="JSR223TimerGui" testclass="JSR223Timer" testname="Fixed meter cadence" enabled="true">
<stringProp name="scriptLanguage">groovy</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename" />
<stringProp name="parameters" />
<stringProp name="script">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())</stringProp>
</JSR223Timer>
<hashTree />
<JSR223PreProcessor guiclass="JSR223PreProcessorGui" testclass="JSR223PreProcessor" testname="Clear stale power values" enabled="true">
<stringProp name="scriptLanguage">groovy</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename" />
<stringProp name="parameters" />
<stringProp name="script">['shelly_power_watts','shelly_voltage_volts','shelly_current_amps','shelly_energy_wh'].each { vars.put(it,'') }</stringProp>
</JSR223PreProcessor>
<hashTree />
<JSR223Assertion guiclass="JSR223AssertionGui" testclass="JSR223Assertion" testname="Validate and extract plug readings" enabled="true">
<stringProp name="scriptLanguage">groovy</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename" />
<stringProp name="parameters" />
<stringProp name="script">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 -&gt; assert value instanceof Number &amp;&amp; Double.isFinite(value.doubleValue()) &amp;&amp; value &gt;= 0; vars.put(key,value.toString()) }
} catch (Throwable error) {
AssertionResult.setFailure(true);AssertionResult.setFailureMessage('Shelly status/measurement unavailable');prev.setSuccessful(false)
}
</stringProp>
</JSR223Assertion>
<hashTree />
</hashTree>
<ResultCollector guiclass="SimpleDataWriter" testclass="ResultCollector" testname="Shelly measurements saved live" enabled="true">
<stringProp name="filename">${__P(shelly_file,shelly.csv)}</stringProp>
<boolProp name="ResultCollector.error_logging">false</boolProp>
</ResultCollector>
<hashTree />
</hashTree>
<kg.apc.jmeter.perfmon.PerfMonCollector guiclass="kg.apc.jmeter.vizualizers.PerfMonGui" testclass="kg.apc.jmeter.perfmon.PerfMonCollector" testname="NUC live CPU RAM disk and network" enabled="true">
<stringProp name="filename">${__P(perfmon_file,perfmon.csv)}</stringProp>
<boolProp name="ResultCollector.error_logging">false</boolProp>
@@ -79,7 +149,7 @@
</elementProp>
<stringProp name="ThreadGroup.num_threads">${__P(users,1)}</stringProp>
<stringProp name="ThreadGroup.ramp_time">${__P(ramp_seconds,60)}</stringProp>
<stringProp name="ThreadGroup.duration">${__P(total_duration_seconds,16205)}</stringProp>
<stringProp name="ThreadGroup.duration">${__P(total_duration_seconds,16210)}</stringProp>
<stringProp name="ThreadGroup.delay">0</stringProp>
<boolProp name="ThreadGroup.scheduler">true</boolProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>