import time

from logger import logger

from perfrunner.helpers.rest import RestHelper


class Monitor(RestHelper):

    DISK_QUEUE_METRICS = ('ep_queue_size', 'ep_flusher_todo')

    def __init__(self, cluster_spec, test_config):
        super(RestHelper, self).__init__(cluster_spec, test_config)
        self.test_config = test_config

    def monitor_rebalance(self, host_port):
        logger.info('Monitoring rebalance status')
        while True:
            is_running, progress = self.get_rebalance_status(host_port)
            if is_running:
                logger.info('Rebalance progress: {0} %'.format(progress))
                time.sleep(10)
            else:
                break
        logger.info('Rebalance successfully completed')

    def monitor_disk_queue(self, host_port, bucket):
        logger.info('Monitoring disk queue: {0}'.format(bucket))
        for metric in self.DISK_QUEUE_METRICS:
            while True:
                bucket_stats = self.get_bucket_stats(host_port, bucket)
                curr_value = bucket_stats['op']['samples'][metric][-1]
                if curr_value:
                    logger.info('Current value of {0}: {1}'.format(metric,
                                                                   curr_value))
                    time.sleep(10)
                else:
                    logger.info('{0} reached 0'.format(metric))
                    break

@@ -136,16 +136,25 @@
 RICS = (
+%0A        
 'ep_queu
@@ -161,16 +161,24 @@
 e_size',
+%0A       
  'ep_flu
@@ -187,16 +187,219 @@
 er_todo'
+,%0A    )%0A    TAP_REPLICATION_METRICS = (%0A        'vb_replica_queue_size',%0A        'ep_tap_replica_queue_itemondisk',%0A        'ep_tap_rebalance_queue_backfillremaining',%0A        'ep_tap_replica_qlen',%0A    
 )%0A%0A    d
@@ -976,24 +976,25 @@
     def 
+_
 monitor_
 disk_que
@@ -989,16 +989,18 @@
 tor_
-disk_que
+metric_val
 ue(s
@@ -1025,127 +1025,19 @@
 cket
-):%0A        logger.info('Monitoring disk queue: %7B0%7D'.format(bucket))%0A        for metric in self.DISK_QUEUE_METRICS:%0A    
+, metric):%0A
     
@@ -1064,20 +1064,16 @@
         
-   
- 
 bucket_s
@@ -1120,20 +1120,16 @@
 bucket)%0A
-    
         
@@ -1199,20 +1199,16 @@
         
-    
 if curr_
@@ -1222,36 +1222,32 @@
                 
- 
-   
 logger.info('Cur
@@ -1340,36 +1340,32 @@
                 
-    
 curr_value))%0A   
@@ -1361,20 +1361,16 @@
 value))%0A
-    
         
@@ -1400,38 +1400,30 @@
             
-    
 else:%0A
-    
             
@@ -1474,30 +1474,505 @@
 c))%0A                
-    
 break
+%0A%0A    def monitor_disk_queue(self, host_port, bucket):%0A        logger.info('Monitoring disk queue: %7B0%7D'.format(bucket))%0A        for metric in self.DISK_QUEUE_METRICS:%0A            self._monitor_metric_value(host_port, bucket, metric)%0A%0A    def monitor_tap_replication(self, host_port, bucket):%0A        logger.info('Monitoring TAP replication: %7B0%7D'.format(bucket))%0A        for metric in self.TAP_REPLICATION_METRICS:%0A            self._monitor_metric_value(host_port, bucket, metric)
 %0A

implement tap replication monitor