[TriLUG] a python question
Greg Brown
gwbrown1 at gmail.com
Tue Jan 21 11:07:22 EST 2014
Igor:
Thank you for your feedback. I did know the R.Pi does not have an internal
clock but I had also managed to forget that as well. The R.Pi is just a
proof-of-concept.
What I'm trying to do is replace a now decommissioned monitoring platform
for our Internet hosted web applications with something home-built. I've
been wanting to learn Python and have been taking baby steps in that
direction but I thought this was a very good reason to dive in and build
something actually useful.
What I need to capture is duration of time it takes to resolve host names
for external URLs (why this is necessary I do not know, it's just something
the old app did so it is deemed necessary). Beyond that I need to log into
a web front end and track the time it takes to jump from the login page to
the production page. That's it as far as first steps, I'm sure more is
coming in the future.
I'd like to build this whole thing in Web2py which, I think, can provide a
web framework that would allow people to log in externally and display
data. As far as tracking the data a simple database seems in order and to
graph the data perhaps Python Pandas? I'm open to any and all suggestions
if you have any strong feelings about any of this.
Thank you for your feedback and I'll give your code a whirl.
Kind Regards,
Greg
On Mon, Jan 20, 2014 at 8:58 PM, Igor Partola <igor at igorpartola.com> wrote:
> Assuming you know that the RPi has no real time clock and ntpd will adjust
> system time for you, making these results potentially inaccurate (just
> average lots of them to avoid it), here is a simple decorator that will do
> this in your one big script:
>
> import time
>
> def profile(func):
> def wrapper(*args, **kwargs):
> s = time.time()
> res = func(*args, **kwargs)
> delta = time.time() - s
>
> # inset delta and func.__name__ into a database or a log file
>
> return res
>
> return wrapper
>
> Use it as follows:
>
> @profile
> def my_command():
> pass
>
> Note that time.time() returns a float so you will get microseconds. I do
> not know what precision clocks you get on an RPi so the resolution might
> not be down to microsecond level.
>
> Out of curiosity, what are you benchmarking?
>
> Igor
> --
> This message was sent to: Greg Brown <gwbrown1 at gmail.com>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web :
> http://www.trilug.org/mailman/options/trilug/gwbrown1%40gmail.com
> Welcome to TriLUG: http://trilug.org/welcome
>
More information about the TriLUG
mailing list