Gather spider based stats

def get_machine_stats(self):
        '''
        Gather spider based stats
        '''
        self.logger.debug("Gathering machine stats")
        the_dict = {}
        keys = self.redis_conn.keys('stats:crawler:*:*:*:*')

        for key in keys:
            # break down key
            elements = key.split(":")
            machine = elements[2]
            spider = elements[3]
            response = elements[4]
            end = elements[5]

            # we only care about the machine, not spider type
            if machine not in the_dict:
                the_dict[machine] = {}

            if response not in the_dict[machine]:
                the_dict[machine][response] = {}

            if end in the_dict[machine][response]:
                the_dict[machine][response][end] = the_dict[machine][response][end] + \
                    self._get_key_value(key, end == 'lifetime')
            else:
                the_dict[machine][response][end] = self._get_key_value(key, end == 'lifetime')

        # simple count
        the_dict['count'] = len(list(the_dict.keys()))

        ret_dict = {}
        ret_dict['machines'] = the_dict

        return ret_dict