title: How to write Event hooks in locust for response times of Individual requests
body: <p>I am planning to test my web server for performance using locust, 
  The problem with the below code is that it is only giving me the average times</p>
  
  <p>My basic code is as follows</p>
  
  <pre><code>from locust import HttpLocust, TaskSet, task, events, web
  def index(l):
          l.client.get("/")
  
  def stats(l):
          l.client.get("/stats/requests")
  
  class MyTaskSet(TaskSet):
         tasks = [index,stats]
  
  class MyLocust(HttpLocust):
      host = "http://127.0.0.1:8089"
      min_wait = 2000
      max_wait = 5000
      task_set = MyTaskSet
      request_success_stats = [list()]
      request_fail_stats = [list()]
  
      def __init__(self):
          super(MyLocust, self).__init__()
          locust.events.request_success += self.hook_request_success
          locust.events.request_failure += self.hook_request_fail
          locust.events.quitting += self.hook_locust_quit
  
      def hook_request_success(self, request_type, name, response_time, response_length):
              self.request_success_stats.append([name, request_type, response_time, response_length])
  
      def hook_request_fail(self, request_type, name, response_time, exception):
          self.request_fail_stats.append([name, request_type, response_time, exception])
  
      def hook_locust_quit(self):
          self.save_success_stats()
  
      def save_success_stats(self):
          import csv
          with open('success_req_stats.csv', 'wb') as csv_file:
              writer = csv.writer(csv_file)
                  for value in self.request_success_stats:
                      writer.writerow(value)
  </code></pre>