Ejemplo n.º 1
0
    def add_datediff(self, elements, instance_name):

        old_ts = self.__memory.get_timestamp(instance_name)
        new_ts = elements[instance_name]['logTimestamp']

        ts_diff = times_str_diff(new_ts, old_ts)
        elements[instance_name]['DeltaTime'] = ts_diff
Ejemplo n.º 2
0
    def get_incrementals(self, metric_name, new_value, old_value, new_ts, old_ts, 
        register_bytes=32):

        max_value = pow(2, register_bytes) -1 

        new_ammount = int(re.findall(r'\d+',new_value)[0])
        old_ammount = int(re.findall(r'\d+',old_value)[0])
        
        result = {}        
        
        if old_ammount > max_value:
            logging.critical("old_ammount of %s is greater than max (%s): %s"
                %(metric_name, max_value, old_ammount))
        elif new_ammount > max_value:
            logging.critical("new_ammount of %s is greater than max (%s): %s"
                %(metric_name, max_value, new_ammount))
        else:

            if new_ammount < old_ammount:
                new_ammount += pow(2,register_bytes) - 1

            ammount_diff = new_ammount - old_ammount

            ts_diff = times_str_diff(new_ts, old_ts)

            result[ '%s%s' %(metric_name, 'Diff')] = ammount_diff

            # avoid ZeroDivision try catch
            if ts_diff > 0:
                result[ '%s%s' %(metric_name, 'DiffRate')] = ammount_diff / ts_diff


        return result
Ejemplo n.º 3
0
    def test_dateDiff_3(self):
        """times_str_diff(dt2, dt1): assert if the same date, difference is 0"""

        self.assertEqual(times_str_diff(self.a_dt, self.a_dt), 0*24*60*60)
Ejemplo n.º 4
0
    def test_dateDiff_2(self):
        """times_str_diff(dt2, dt1): 1 day difference with bigger first"""


        self.assertEqual(times_str_diff(self.b_dt,self.a_dt), 1*24*60*60)
Ejemplo n.º 5
0
    def test_dateDiff_1(self):
        """times_str_diff(ts1, ts2): 1 day difference """

        
        self.assertEqual(times_str_diff(self.a_dt, self.b_dt), 1*24*60*60)
Ejemplo n.º 6
0
    def test_dateDiff_3(self):
        """times_str_diff(dt2, dt1): assert if the same date, difference is 0"""

        self.assertEqual(times_str_diff(self.a_dt, self.a_dt),
                         0 * 24 * 60 * 60)
Ejemplo n.º 7
0
    def test_dateDiff_2(self):
        """times_str_diff(dt2, dt1): 1 day difference with bigger first"""

        self.assertEqual(times_str_diff(self.b_dt, self.a_dt),
                         1 * 24 * 60 * 60)
Ejemplo n.º 8
0
    def test_dateDiff_1(self):
        """times_str_diff(ts1, ts2): 1 day difference """

        self.assertEqual(times_str_diff(self.a_dt, self.b_dt),
                         1 * 24 * 60 * 60)