<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _get_plugin_stats(self, name):
        '''
        Used for getting stats for Plugin based stuff, like Kafka Monitor
        and Redis Monitor

        @param name: the main class stats name
        @return: A formatted dict of stats
        '''
        the_dict = {}

        keys = self.redis_conn.keys('stats:{n}:*'.format(n=name))

        for key in keys:
            # break down key
            elements = key.split(":")
            main = elements[2]
            end = elements[3]

            if main == 'total' or main == 'fail':
                if main not in the_dict:
                    the_dict[main] = {}
                the_dict[main][end] = self._get_key_value(key, end == 'lifetime')
            elif main == 'self':
                if 'nodes' not in the_dict:
                    # main is self, end is machine, true_tail is uuid
                    the_dict['nodes'] = {}
                true_tail = elements[4]
                if end not in the_dict['nodes']:
                    the_dict['nodes'][end] = []
                the_dict['nodes'][end].append(true_tail)
            else:
                if 'plugins' not in the_dict:
                    the_dict['plugins'] = {}
                if main not in the_dict['plugins']:
                    the_dict['plugins'][main] = {}
                the_dict['plugins'][main][end] = self._get_key_value(key, end == 'lifetime')

        return the_dict