def test_next_window_time_sample_passed(self): """If next window time has elapsed with at least one sample passed then pass filtered value""" test_window_scheme = WindowingScheme(self.window_test_filter, 3) # Value 15 will be filtered as it ranges between lower and upper bound limits filtered_value = test_window_scheme.filter(self.middle_value) self.assertEquals(filtered_value, self.middle_value) # Let next window time elapse time.sleep(4) filtered_value = test_window_scheme.filter(self.more_than_upper_bound) # None is expected as filtered value because at least one sample has been already passed and # value ranges outside lower and upper bound limits self.assertEquals(filtered_value, None)
# Getting edge_system's network interface and disk name network_interface = get_default_network_interface() disk_name = get_disk_name() # Filters to filter data at Sampling Functions # Simple filters cpu_pro_filter = RangeFilter(Type.CLOSED_REJECT, 5, 10) # If no of CPU processes <=5 or >=10 cpu_util_filter = RangeFilter(Type.AT_LEAST, None, 85) # CPU util >= 85 disk_usage_filter = RangeFilter(Type.AT_LEAST, None, 80) # Disk usage >= 80% net_usage_filter = RangeFilter(Type.AT_LEAST, None, 1000000) # Network usage >= 1Mb # Filter with windowing scheme cpu_util_filter_with_window = WindowingScheme(cpu_util_filter, 30) # --------------------------------------------------------------------------- # User defined methods with RangeFilters def read_cpu_procs(): cnt = cpu_stat.procs_running() return cpu_pro_filter.filter(cnt) def read_cpu_utilization(sample_duration_sec=1): cpu_pcts = cpu_stat.cpu_percents(sample_duration_sec) return cpu_util_filter_with_window.filter( round((100 - cpu_pcts['idle']), 2))
execfile('sampleProp.conf', config) # Getting edge_system's network interface and disk name network_interface = get_default_network_interface() disk_name = get_disk_name() # Filters to filter data at Sampling Functions # Simple filters cpu_pro_filter = RangeFilter(Type.CLOSED_REJECT, 5, 10) # If no of CPU processes <=5 or >=10 cpu_util_filter = RangeFilter(Type.AT_LEAST, None, 85) # CPU util >= 85 disk_usage_filter = RangeFilter(Type.AT_LEAST, None, 80) # Disk usage >= 80% net_usage_filter = RangeFilter(Type.AT_LEAST, None, 1000000) # Network usage >= 1Mb mem_free_filter = RangeFilter(Type.AT_MOST, 15, None) # Memory Free <= 15% # Filters with windowing scheme net_usage_filter_with_window = WindowingScheme(net_usage_filter, 30) mem_free_filter_with_window = WindowingScheme(mem_free_filter, 60) # some standard metrics for Linux systems # agent classes for different IoT system # agent classes for different data center components # agent classes for different kinds of of devices, connected to the IoT System # we are showing here how to create a representation for a Device in IoTCC but # using the notion of RAM (because we have no connected devices yet) # agent classes for different kinds of layer 4/5 connections from agent to DCC # -------User defined functions with filters for getting the next value for a metric -------- # usage of these shown below in main # semantics are that on each call the function returns the next available value # from the device or system associated to the metric.
def test_next_window_time_no_sample_passed(self): """If next window time has elapsed with no sample passed so far then pass collected value""" test_window_scheme = WindowingScheme(self.window_test_filter, 3) time.sleep(4) collected_value = test_window_scheme.filter(self.more_than_upper_bound) self.assertEquals(collected_value, self.more_than_upper_bound)
def test_window_filter(self): """If filter returns a valid value, windowing_scheme should return it""" test_window_scheme = WindowingScheme(self.window_test_filter, 5) filtered_value = test_window_scheme.filter(self.middle_value) self.assertEquals(filtered_value, self.middle_value)
def test_init_windowing_scheme_window_size(self): """If window size is not a non negative number, raise ValueError""" self.assertRaises( ValueError, lambda: WindowingScheme(self.window_test_filter, "10")) self.assertRaises( ValueError, lambda: WindowingScheme(self.window_test_filter, -10))
def test_init_windowing_scheme_filter(self): """If filter not provided in Windowing scheme, raise TypeError""" self.assertRaises(TypeError, lambda: WindowingScheme("", 10))
from liota.lib.utilities.filters.range_filter import RangeFilter, Type from liota.lib.utilities.filters.windowing_scheme.windowing_scheme import WindowingScheme dependencies = ["iotcc"] # Filters to filter data at Sampling Functions # Simple filters cpu_pro_filter = RangeFilter(Type.CLOSED_REJECT, 5, 10) # If no of CPU processes <=5 or >=10 cpu_util_filter = RangeFilter(Type.AT_LEAST, None, 85) # CPU util >= 85 disk_usage_filter = RangeFilter(Type.AT_LEAST, None, 80) # Disk usage >= 80% net_usage_filter = RangeFilter(Type.AT_LEAST, None, 1000000) # Network usage >= 1Mb # Filters with windowing scheme net_usage_filter_with_window = WindowingScheme(net_usage_filter, 30) # --------------------------------------------------------------------------- # User defined methods with RangeFilters def read_cpu_procs(): cnt = cpu_stat.procs_running() return cpu_pro_filter.filter(cnt) def read_cpu_utilization(sample_duration_sec=1): cpu_pcts = cpu_stat.cpu_percents(sample_duration_sec) return cpu_util_filter.filter(round((100 - cpu_pcts['idle']), 2))