Using Python and want to get more detail from your app?

Assuming you've tinkered a bit with the demo,
let's take it for a little spin

1

Create an account

Signup with Graphdat and your first agent is free. There are no charges for using our service if you stay with one agent. If you like the service and want to add more agents, Graphdat offers the easiest and most competitive pricing around.

2

Install the agent

After signup you will see a message telling you how to install the Graphdat agent

See our How To's page for more.

3
your agent is running

Check out your dashboard!

To confirm that the agent is running, go to your dashboard.

You should see some lines appearing (if not, wait a few seconds, if you still don't see anything then contact us).

When you first install the agent it will automatically begin providing basic, system level metrics to your dashboard.

Whenever you install the agent on a new machine, new lines will appear on your dashboard (yep, that easy!).

Now onto some Python action...

4
$ pip install graphdat

  or

$ easy_install graphdat

Install the Graphdat Python extension

If you are using PIP, install with PIP. If you are using easy_install, upgrade to pip, or use easy_install.

PIP is our preferred method, some reading for you if you are wondering why.

5
#! /usr/bin/env python import time from wsgiref.simple_server import make_server import graphdat def application(environ, start_response): # Sort and stringifying the environment vars response_body = ['%s: %s' % (key, value) for key, value in sorted(environ.items())] response_body = '\n'.join(response_body) status = '200 OK' response_headers = \ [('Content-Type', 'text/plain'), ('Content-Length', str(len(response_body)))] start_response(status, response_headers) time.sleep(0.5) return [response_body] # graphdat wraps the application application = graphdat.WSGIWrapper(application) if __name__ == '__main__': server = make_server( 'localhost', # The host name. 1337, # A port number. application # Our graphdat wrapped application ) print 'server starting on http://localhost:1337' server.serve_forever()

Add two lines to your code

Just require the import graphdat module at the top of your file and wrap your WSGI application and the Graphdat SDK will automatically hook into web requests you receive, record response time information, and send it to your dashboard.

Let's try it out!

Copy the code you see on the right, save it to a file, then run it with python.

Next, browse to http://127.0.0.1:1337 and hit refresh a few times.

6
requests appearing

We see web requests!

If all is going to plan, the Request Count and Response Time graphs on your dashboard should now show the requests you just made.

In the upper right corner of the Response Time graph you can click the Zoom button to get a closer look

Once you zoom in, click on one of the peaks in the upper graph and you will see a drill down appear for that request which tells you the requests made at that point in time.

Click one of the routes in the lower left and you can see how this route performed over time.

That's handy! But let's take it a bit further...

7
#! /usr/bin/env python import time from wsgiref.simple_server import make_server import graphdat def application(environ, start_response): # get the graphdat timer graphdat = environ['graphdat'] # start a timer at the beginning of an operation graphdat.begin("sorting") # Sort and stringifying the environment vars response_body = ['%s: %s' % (key, value) for key, value in sorted(environ.items())] response_body = '\n'.join(response_body) # end a timer when we are done the operation graphdat.end("sorting") # start a new timer for sending the response graphdat.begin("response") status = '200 OK' response_headers = \ [('Content-Type', 'text/plain'), ('Content-Length', str(len(response_body)))] start_response(status, response_headers) BLOCKSIZE = 1000 offset = 0 # create a nested timer under the response timer graphdat.begin('offset' + str(offset)) block = response_body[0:BLOCKSIZE] while block: time.sleep(0.5) yield block graphdat.end('offset' + str(offset)) offset += BLOCKSIZE graphdat.begin('offset' + str(offset)) block = response_body[offset:offset + BLOCKSIZE] # the open timers will automatically be closed # when the response is finished # graphdat wraps the application application = graphdat.WSGIWrapper(application) if __name__ == '__main__': server = make_server( 'localhost', # The host name. 1337, # A port number. application # Our graphdat wrapped application ) print 'server starting on http://localhost:1337' server.serve_forever()

Take a closer look

In most applications there are a handful of functions that you want to keep an eye on for performance (e.g. calls to databases, remote web calls, etc..)

Using the Graphdat SDK you can instrument your code easily using some helper functions to wrap your calls.

As before, copy the sample code on the right to a file and run it in python then, once again, browse to your page a few times.

In the example, if we have a sort opertation that we want to track how much time was spent

# start a timer at the beginning of an operation graphdat.begin("sorting") .... Sorting operation # end a timer when we are done the operation graphdat.end("sorting")

We are reading chunks from a string (another use case would be a file) and we want to know how long it is taking to read each iteration

# start a timer for the entire cycle graphdat.begin("response") # create a nested timer under the response timer # /response/offset0 graphdat.begin('offset' + str(offset)) .... do some work while block: yield block # end the old timer graphdat.end('offset' + str(offset)) # start a new one graphdat.begin('offset' + \ str(offset+BLOCK_SIZE)) .... do some more work

Graphdat cleans up the open timers when the response is done, computes the times, does the summary and now you have the break down in your graphdat dashboard.

8
requests appearing

Dive into those requests

Just as above, zoom into your Response Time graph, click a peak in the top graph, then client the '/' route in the lower left.

Because the system now has data for your request it will show the breakdown as a stacked line and bar graph.

You can now watch the performance of these functions over time to look for trends as well is jump into slow running web calls whenever they happen.


That's the quick start!

For further information on how the Graphdat SDK works, you can view more details in the wiki article here.

OK, Here is the deal... You get a free server to check out everything we have to offer! Every month, we keep giving you another free server, so if you only have one server, Graphdat is free forever SIGNUP NOW

Graphdat offers the easiest and most competitive pricing around. Because we believe that every application developer,
whether a solo warrior, or member of a large corporate team,
should have access to these powerful tools.