Gathering stats from messageReceived via MQTT
Joel Lucuik <[email protected]> Mon, 11 Apr 2016 16:36:00 -0400
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <CAA4qVTL2-FROB1kr6ozimCa+7_T_fZjkNB1WjvfyZZC0T-uG9g@mail.gmail.com> |
--===============6499211072432667077==
Content-Type: multipart/alternative; boundary=001a11401f5820b45605303b7ee6
--001a11401f5820b45605303b7ee6
Content-Type: text/plain; charset=UTF-8
Hi,
I am using MQTTv3 on a client project. I am trying to measure the grinder
stats for it. Specifically the messageArrived callback.
I only get stats for messageArrived when it's ***not instrumented***.
Any advice on how to instrument/gather stats? I put a try block in there in
case there were errors. To no avail.
Code below:
Thanks,
Joel
"========================================="
def instrumentMethod(test, method_name, c=TestRunner):
"""Instrument a method with the given Test."""
unadorned = getattr(c, method_name)
import new
method = new.instancemethod(test.wrap(unadorned), None, c)
setattr(c, method_name, method)
# Replace each method with an instrumented version.
# You can call the unadorned method using self.page1.__target__().
# Only change these, as they seem to override the statements at the top
# of the script.
instrumentMethod(Test(3100, '%s - MESSAGE_ARRIVED' % testId),
'messageArrivedHelper', TestRunnerCallback)
class TestRunnerCallback(MqttCallback):
""" Constructor """
def __init__(self):
self.receivedMessages = 0
info("Callback init" )
self.connectionLost = False
def connectionLost(self, cause):
#This method is called when the connection to the server is lost.
info("connectionLost called" )
def deliveryComplete(self, token):
#Called when delivery for a message has been completed, and all
acknowledgments have been received.
info("deliveryComplete called")
def messageArrived(self, topic, message):
try:
#info("User Data is : %s" % message.toString())
info("Received msg for topic %s " % (topic))
self.receivedMessages = self.receivedMessages + 1
except MqttException, err:
raise RuntimeError("Exception caused by: %s" % str(err))
"========================================="
--001a11401f5820b45605303b7ee6
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<br><div class=3D"gmail_quote"><div dir=3D"ltr"><div cl=
ass=3D"gmail_quote"><div dir=3D"ltr"><div><div><br></div>I am using MQTTv3 =
on a client project. I am trying to measure the grinder stats for it. Speci=
fically the messageArrived callback.<br><br></div><div>I only get stats for=
messageArrived when it's ***not instrumented***.<br><br></div><div>Any=
advice on how to instrument/gather stats? I put a try block in there in ca=
se there were errors. To no avail.<br><br>Code below:<br><br></div><div>Tha=
nks,<br></div><div>Joel<br></div><br><div>"=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D"<br>def instrumentMethod(test, method_name, c=3D=
TestRunner):<br>=C2=A0=C2=A0=C2=A0 """Instrument a method wi=
th the given Test."""<br>=C2=A0=C2=A0=C2=A0 unadorned =3D ge=
tattr(c, method_name)<br>=C2=A0=C2=A0=C2=A0 import new<br>=C2=A0=C2=A0=C2=
=A0 method =3D new.instancemethod(test.wrap(unadorned), None, c)<br>=C2=A0=
=C2=A0=C2=A0 setattr(c, method_name, method)<br>=C2=A0=C2=A0=C2=A0 <br><br>=
# Replace each method with an instrumented version.<br># You can call the u=
nadorned method using self.page1.__target__().<br># Only change these, as t=
hey seem to override the statements at the top<br># of the script.<br>instr=
umentMethod(Test(3100, '%s - MESSAGE_ARRIVED' % testId), 'messa=
geArrivedHelper', TestRunnerCallback)<br><br><br>class TestRunnerCallba=
ck(MqttCallback):<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 ""=
" Constructor """<br>=C2=A0=C2=A0=C2=A0 def __init__(se=
lf):<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 self.receivedMessages =
=3D 0<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 info("Callback ini=
t" )<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 self.connectionLost=
=3D False<br><br>=C2=A0=C2=A0=C2=A0 def connectionLost(self, cause):<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #This method is called when the =
connection to the server is lost.<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 info("connectionLost called" )<br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 def deliveryComplete(self, token)=
:=C2=A0 <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #Called when deliver=
y for a message has been completed, and all acknowledgments have been recei=
ved.<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 info("deliveryCompl=
ete called")<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>=C2=A0=
=C2=A0=C2=A0 def messageArrived(self, topic, message):=C2=A0 <br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try:<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #info("User Data is : %s" % mes=
sage.toString())<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 info("Received msg for topic %s " % (topic))<br>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 self.receiv=
edMessages =3D self.receivedMessages + 1<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 except MqttException, err:<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 raise RuntimeError("Exception cau=
sed by: %s" % str(err))<br><br>"=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D"<br><br><br></div></div>
</div><br></div>
<br></div><br></div>
--001a11401f5820b45605303b7ee6--
--===============6499211072432667077==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
--===============6499211072432667077==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
--===============6499211072432667077==--