def run(self, registry): import copy from liota.entities.metrics.metric import Metric # Acquire resources from registry reg_edge_system = copy.copy(registry.get("sierra_edge_system")) opengate = registry.get("opengate_dmm_DCC") # Create metrics tuple self.metrics = [] # Getting CPU utilization metric_cpu_utilization = Metric(name="EdgeSystem.CPU_Utilization", unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_utilization ) reg_metric_cpu_utilization = opengate.register(metric_cpu_utilization) opengate.create_relationship(reg_edge_system, reg_metric_cpu_utilization) reg_metric_cpu_utilization.start_collecting() self.metrics.append(reg_metric_cpu_utilization) # Getting RAM used metric_ram_used = Metric(name="EdgeSystem.RAM_Used", unit=None, interval=5, aggregation_size=1, sampling_function=read_ram_used ) reg_metric_ram_used = opengate.register(metric_ram_used) opengate.create_relationship(reg_edge_system, reg_metric_ram_used) reg_metric_ram_used.start_collecting() self.metrics.append(reg_metric_ram_used)
def run(self, registry): from liota.entities.metrics.metric import Metric # Acquire resources from registry influx = registry.get("influx") bike_simulator = registry.get("bike_simulator") influx_bike = influx.register(bike_simulator) ureg = bike_simulator.ureg self.create_udm(bike_model=bike_simulator) # Create metrics self.metrics = [] metric_name = "speed" bike_speed = Metric(name=metric_name, unit=(ureg.m / ureg.sec), interval=2, sampling_function=self.get_bike_speed) reg_bike_speed = influx.register(bike_speed) influx.create_relationship(influx_bike, reg_bike_speed) reg_bike_speed.start_collecting() self.metrics.append(reg_bike_speed) metric_name = "power" bike_power = Metric(name=metric_name, unit=ureg.watt, interval=2, sampling_function=self.get_bike_power) reg_bike_power = influx.register(bike_power) influx.create_relationship(influx_bike, reg_bike_power) reg_bike_power.start_collecting() self.metrics.append(reg_bike_power)
def run(self, registry): from liota.entities.metrics.metric import Metric # Acquire resources from registry graphite = registry.get("graphite") bike_simulator = registry.get("bike_simulator") graphite_bike = graphite.register(bike_simulator) ureg = bike_simulator.ureg self.create_udm(bike_model=bike_simulator) # Create metrics self.metrics = [] metric_name = "model.bike.speed" bike_speed = Metric(name=metric_name, unit=(ureg.m / ureg.sec), interval=5, sampling_function=self.get_bike_speed) reg_bike_speed = graphite.register(bike_speed) graphite.create_relationship(graphite_bike, reg_bike_speed) reg_bike_speed.start_collecting() self.metrics.append(reg_bike_speed) metric_name = "model.bike.power" bike_power = Metric(name=metric_name, unit=ureg.watt, interval=5, sampling_function=self.get_bike_power) reg_bike_power = graphite.register(bike_power) graphite.create_relationship(graphite_bike, reg_bike_power) reg_bike_power.start_collecting() self.metrics.append(reg_bike_power)
def run(self, registry): import copy from liota.entities.metrics.metric import Metric # Acquire resources from registry edge_system = copy.copy(registry.get("graphite_edge_system")) graphite = registry.get("graphite") reg_edge_system = graphite.register(edge_system) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Create metrics self.metrics = [] metric_name = "EdgeSystem.CPU_Utilization" metric_cpu_utilization = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_utilization ) reg_metric_cpu_utilization = graphite.register(metric_cpu_utilization) graphite.create_relationship(reg_edge_system, reg_metric_cpu_utilization) reg_metric_cpu_utilization.start_collecting() self.metrics.append(reg_metric_cpu_utilization) metric_name = "EdgeSystem.CPU_Process" metric_cpu_procs = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_procs ) reg_metric_cpu_procs = graphite.register(metric_cpu_procs) graphite.create_relationship(reg_edge_system, reg_metric_cpu_procs) reg_metric_cpu_procs.start_collecting() self.metrics.append(reg_metric_cpu_procs) metric_name = "EdgeSystem.Disk_Busy_Stats" metric_disk_busy_stats = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_disk_usage_stats ) reg_metric_disk_busy_stats = graphite.register(metric_disk_busy_stats) graphite.create_relationship(reg_edge_system, reg_metric_disk_busy_stats) reg_metric_disk_busy_stats.start_collecting() self.metrics.append(reg_metric_disk_busy_stats) metric_name = "EdgeSystem.Network_Bytes_Received" metric_network_bytes_received = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_network_bytes_received ) reg_metric_network_bytes_received = graphite.register(metric_network_bytes_received) graphite.create_relationship(reg_edge_system, reg_metric_network_bytes_received) reg_metric_network_bytes_received.start_collecting() self.metrics.append(reg_metric_network_bytes_received)
def run(self, registry): import copy from liota.entities.metrics.metric import Metric # Acquire resources from registry iotcc_edge_system = copy.copy(registry.get("iotcc_edge_system_mqtt")) iotcc = registry.get("iotcc_mqtt") # Get values from configuration file config_path = registry.get("package_conf") config = {} execfile(config_path + '/sampleProp.conf', config) # Create metrics self.metrics = [] metric_name = "CPU Utilization" metric_cpu_utilization = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_utilization ) reg_metric_cpu_utilization = iotcc.register(metric_cpu_utilization) iotcc.create_relationship(iotcc_edge_system, reg_metric_cpu_utilization) reg_metric_cpu_utilization.start_collecting() self.metrics.append(reg_metric_cpu_utilization) metric_name = "CPU Process" metric_cpu_procs = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_cpu_procs ) reg_metric_cpu_procs = iotcc.register(metric_cpu_procs) iotcc.create_relationship(iotcc_edge_system, reg_metric_cpu_procs) reg_metric_cpu_procs.start_collecting() self.metrics.append(reg_metric_cpu_procs) metric_name = "Disk Usage Stats" metric_disk_usage_stats = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_disk_usage_stats ) reg_metric_disk_usage_stats = iotcc.register(metric_disk_usage_stats) iotcc.create_relationship(iotcc_edge_system, reg_metric_disk_usage_stats) reg_metric_disk_usage_stats.start_collecting() self.metrics.append(reg_metric_disk_usage_stats) metric_name = "Network Bytes Received" metric_network_bytes_received = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=read_network_bytes_received ) reg_metric_network_bytes_received = iotcc.register(metric_network_bytes_received) iotcc.create_relationship(iotcc_edge_system, reg_metric_network_bytes_received) reg_metric_network_bytes_received.start_collecting() self.metrics.append(reg_metric_network_bytes_received)
def test_metric_interval(self): ureg = pint.UnitRegistry() m = Metric("test5", interval=5) assert isinstance(m, Metric) m = Metric("test5.0", interval=5.0) assert isinstance(m, Metric) with self.assertRaises(TypeError): m = Metric("test5s", interval=(5 * ureg.second)) assert m is None
def run(self, registry): from liota.entities.metrics.metric import Metric import copy # Acquire resources from registry iotcc = registry.get("iotcc") iotcc_edge_system = copy.copy(registry.get("iotcc_edge_system")) thermistor_simulator = registry.get("thermistor_simulator") iotcc_thermistor = iotcc.register(thermistor_simulator) iotcc.create_relationship(iotcc_edge_system, iotcc_thermistor) ureg = thermistor_simulator.ureg self.create_udm(thermistor_model=thermistor_simulator) # Create metrics self.metrics = [] metric_name = "model.thermistor.temperature" thermistor_temper = Metric( name=metric_name, unit=ureg.degC, interval=5, sampling_function=self.get_thermistor_temperature) reg_thermistor_temper = iotcc.register(thermistor_temper) iotcc.create_relationship(iotcc_thermistor, reg_thermistor_temper) reg_thermistor_temper.start_collecting() self.metrics.append(reg_thermistor_temper)
def test_implementation_get_entity_hierarchy(self): """ Test case to check get_entity_entity_hierarchy() for RegisteredEdgeSystem->RegisteredMetric :return: None """ # Register the edge registered_entity = self.aws.register(self.edge_system) # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) registered_metric = self.aws.register(test_metric) # Creating the parent-child relationship self.aws.create_relationship(registered_entity, registered_metric) # Getting the parent child relationship array from registered metric entity_hierarchy = get_entity_hierarchy(registered_metric) self.assertSequenceEqual( [ registered_entity.ref_entity.name, registered_metric.ref_entity.name ], entity_hierarchy, "Check the implementation of _get_entity_hierarchy for " "RegisteredEdgeSystem->RegisteredMetric")
def run(self, registry): from liota.entities.metrics.metric import Metric import copy # Acquire resources from registry self.config_path = registry.get("package_conf") self.iotcc = registry.get("iotcc") self.iotcc_edge_system = copy.copy(registry.get("iotcc_edge_system")) thermistor_simulator = registry.get("thermistor_simulator") self.iotcc_thermistor = self.iotcc.register(thermistor_simulator) self.iotcc.create_relationship(self.iotcc_edge_system, self.iotcc_thermistor) ureg = thermistor_simulator.ureg self.create_udm(thermistor_model=thermistor_simulator) # Create metrics self.metrics = [] metric_name = "model.thermistor.temperature" thermistor_temper = Metric( name=metric_name, unit=ureg.degC, interval=5, sampling_function=self.get_thermistor_temperature) reg_thermistor_temper = self.iotcc.register(thermistor_temper) self.iotcc.create_relationship(self.iotcc_thermistor, reg_thermistor_temper) reg_thermistor_temper.start_collecting() self.metrics.append(reg_thermistor_temper) # Use the iotcc_device_name as identifier in the registry to easily refer the registered device in other packages registry.register("iotcc_thermistor_simulated", self.iotcc_thermistor)
def run(self, registry): from liota.entities.devices.simulated_device import SimulatedDevice from liota.entities.metrics.metric import Metric import copy # Acquire resources from registry iotcc = registry.get("iotcc") # Creating a copy of edge_system object to keep original object "clean" iotcc_edge_system = copy.copy(registry.get("iotcc_edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = {} execfile(config_path + '/sampleProp.conf', config) # Register device ram_device = SimulatedDevice(config['DeviceName'], "Device-RAM") reg_ram_device = iotcc.register(ram_device) iotcc.set_properties(reg_ram_device, config['DevicePropList']) iotcc.create_relationship(iotcc_edge_system, reg_ram_device) # Create metrics self.metrics = [] mem_free_metric = Metric(name="Memory Free", unit=None, interval=10, sampling_function=read_mem_free) reg_mem_free_metric = iotcc.register(mem_free_metric) iotcc.create_relationship(reg_ram_device, reg_mem_free_metric) reg_mem_free_metric.start_collecting() self.metrics.append(reg_mem_free_metric) registry.register("reg_ram_device", reg_ram_device)
def test_implementation_get_formatted_data_no_data(self): """ Test case to check the implementation of _format_data for empty metric data. :return: None """ # Mocking the DataCenterComponent init method with mock.patch("liota.dccs.aws_iot.DataCenterComponent.__init__" ) as mocked_dcc: self.aws = AWSIoT("Mocked DCC", enclose_metadata=False) # Register the edge registered_entity = self.aws.register(self.edge_system) # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) registered_metric = self.aws.register(test_metric) # Creating the parent-child relationship self.aws.create_relationship(registered_entity, registered_metric) # Getting the parent child relationship array from registered metric # formatted_data = self.aws._format_data(registered_metric) formatted_data = get_formatted_data(registered_metric, False) # Check two dicts are equal or not self.assertEqual(None, formatted_data, "Check implementation of get_formatted_data")
def test_implementation_create_relationship(self): """ Test case to test RegisteredEntity as Parent and RegisteredMetric as child. RegisteredEdgeSystem->RegisteredMetric :return: None """ # Register the edge registered_entity = self.rabbitmq_client.register(self.edge_system) # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) registered_metric = self.rabbitmq_client.register(test_metric) # Creating the parent-child relationship self.rabbitmq_client.create_relationship(registered_entity, registered_metric) self.assertEqual(registered_metric.parent, registered_entity, "Check the implementation of create_relationship")
def test_format_data(self, mocked_get_formatted_data=None): """ Test the implementation of _format_data. :param mocked_get_formatted_data: Mocked get_formatted_data from dcc_utilities :return: None """ # Assign return value to get_formatted_data mocked_get_formatted_data.return_value = None # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) # Mock the get_formatted_data with mock.patch("liota.dccs.rabbitmq.get_formatted_data" ) as mocked_get_formatted_data: registered_metric = self.rabbitmq_client.register(test_metric) # Call _format_data self.rabbitmq_client._format_data(reg_metric=registered_metric) # Check get_formatted_data called with following mocked_get_formatted_data.assert_called_with( registered_metric, False)
def run(self, registry): from liota.entities.metrics.metric import Metric import copy # Acquire resources from registry self.config_path = registry.get("package_conf") self.iotcc = registry.get("iotcc") self.iotcc_edge_system = copy.copy(registry.get("iotcc_edge_system")) bike_simulator = registry.get("bike_simulator") self.iotcc_bike = self.iotcc.register(bike_simulator) self.iotcc.create_relationship(self.iotcc_edge_system, self.iotcc_bike) ureg = bike_simulator.ureg self.create_udm(bike_model=bike_simulator) # Create metrics self.metrics = [] metric_name = "model.bike.speed" bike_speed = Metric( name=metric_name, unit=(ureg.m / ureg.sec), interval=5, sampling_function=self.get_bike_speed ) reg_bike_speed = self.iotcc.register(bike_speed) self.iotcc.create_relationship(self.iotcc_bike, reg_bike_speed) reg_bike_speed.start_collecting() self.metrics.append(reg_bike_speed) metric_name = "model.bike.power" bike_power = Metric( name=metric_name, unit=ureg.watt, interval=5, sampling_function=self.get_bike_power ) reg_bike_power = self.iotcc.register(bike_power) self.iotcc.create_relationship(self.iotcc_bike, reg_bike_power) reg_bike_power.start_collecting() self.metrics.append(reg_bike_power) # Use the iotcc_device_name as identifier in the registry to easily refer the registered device in other packages registry.register("iotcc_bike_simulated", self.iotcc_bike)
def run(self, registry): from liota.entities.metrics.metric import Metric windmill_simulator = registry.get("windmill_simulator") tensorflow_edge_component = registry.get("tensorflow_edge_component") graphite = registry.get("graphite") graphite_windmill = graphite.register(windmill_simulator) self.create_udm(windmill_model=windmill_simulator) tensorflow_edge_component.actuator_udm = self.get_action self.metrics = [] metric_name = "edge_tensorflow.rpm" rpm = Metric( name = metric_name, unit = None, interval=1, aggregation_size=1, sampling_function=self.get_rpm ) reg_windmill_rpm = graphite.register(rpm) graphite.create_relationship(graphite_windmill, reg_windmill_rpm) reg_rpm = tensorflow_edge_component.register(rpm) reg_rpm.start_collecting() reg_windmill_rpm.start_collecting() self.metrics.append(reg_windmill_rpm) metric_name1 = "edge_sklearn.action" action_taken = Metric( name = metric_name1, unit = None, interval=1, aggregation_size=1, sampling_function=self.get_action_taken ) reg_windmill_action = graphite.register(action_taken) graphite.create_relationship(graphite_windmill, reg_windmill_action) reg_windmill_action.start_collecting() self.metrics.append(reg_windmill_action)
class PackageClass(LiotaPackage): def run(self, registry): """ The execution function of a liota package. Acquires "iotcc_mqtt" and "iotcc_mqtt_edge_system" from registry then register five devices and publishes device metrics to the DCC :param registry: the instance of ResourceRegistryPerPackage of the package :return: """ from liota.entities.devices.device import Device from liota.entities.metrics.metric import Metric import copy log.info("-----------beging register device with:" + device_name + "--" +device_metric_name) # Acquire resources from registry self.iotcc = registry.get("iotcc_mqtt") # Creating a copy of edge_system object to keep original object "clean" self.iotcc_edge_system = copy.copy(registry.get("iotcc_mqtt_edge_system")) self.reg_devices = [] self.metrics = [] try: # Register device device = Device(device_name,systemUUID().get_uuid(device_name),"edgexfoundry") log.info("Registration Started for Device".format(device.name)) # Device Registration reg_device = self.iotcc.register(device) self.reg_devices.append(reg_device) self.iotcc.create_relationship(self.iotcc_edge_system, reg_device) # Use the device name as identifier in the registry to easily refer the device in other packages device_registry_name = device_name registry.register(device_registry_name, reg_device) log.info("----------------relation success:"+str(device_name)+"----------------------") self.iotcc.set_properties(reg_device, {"Country": "USA-G", "State": "California", "City": "Palo Alto", "Location": "VMware HQ", "Building": "Promontory H Lab", "Floor": "First Floor"}) try: # Registering Metric for Device metric_name = device_metric_name + "_metrics" metric_simulated_received = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=device_metric) reg_metric_simulated_received = self.iotcc.register(metric_simulated_received) self.iotcc.create_relationship(reg_device, reg_metric_simulated_received) reg_metric_simulated_received.start_collecting() log.info("--------------relation metics:"+device_metric_name+"----------------------") self.metrics.append(reg_metric_simulated_received)
def run(self, registry): from liota.entities.metrics.metric import Metric from liota.lib.transports.mqtt import MqttMessagingAttributes import copy # Acquire resources from registry wavefront_edge_system = copy.copy( registry.get("wavefront_edge_system")) wavefront = registry.get("wavefront") bike_simulator = registry.get("bike_simulator") wavefront_bike = wavefront.register(bike_simulator) wavefront.create_relationship(wavefront_edge_system, wavefront_bike) config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') ureg = bike_simulator.ureg self.create_udm(bike_model=bike_simulator) # Create metrics self.metrics = [] metric_name = "speed" bike_speed = Metric(name=metric_name, unit=(ureg.m / ureg.sec), interval=2, sampling_function=self.get_bike_speed) reg_bike_speed = wavefront.register(bike_speed) wavefront.create_relationship(wavefront_bike, reg_bike_speed) reg_bike_speed.start_collecting() self.metrics.append(reg_bike_speed) metric_name = "power" bike_power = Metric(name=metric_name, unit=ureg.watt, interval=2, sampling_function=self.get_bike_power) reg_bike_power = wavefront.register(bike_power) wavefront.create_relationship(wavefront_bike, reg_bike_power) reg_bike_power.start_collecting() self.metrics.append(reg_bike_power)
def test_implementation_get_formatted_data_without_enclose_metatadata( self): """ Test case to check the output given by get_formatted_data method without enclosed meta_data option. RegisteredEdgeSystem->RegisteredMetric :return: None """ # Mocking the DataCenterComponent init method with mock.patch("liota.dccs.aws_iot.DataCenterComponent.__init__" ) as mocked_dcc: self.aws = AWSIoT("Mocked DCC", enclose_metadata=False) # Register the edge registered_entity = self.aws.register(self.edge_system) # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) registered_metric = self.aws.register(test_metric) # Creating the parent-child relationship self.aws.create_relationship(registered_entity, registered_metric) # Get current timestamp timestamp = getUTCmillis() registered_metric.values.put((timestamp, 10)) # Expected output without enclosed metadata expected_output = { "metric_name": registered_metric.ref_entity.name, "metric_data": [{ "value": 10, "timestamp": timestamp }], "unit": "null" } # Getting the parent child relationship array from registered metric formatted_data = get_formatted_data(registered_metric, False) # Convert json string to dict for the comparision formatted_json_data = json.loads(formatted_data) # Check two dicts are equal or not self.assertEqual( validate_json(formatted_json_data) == validate_json( expected_output), True, "Check implementation of get_formatted_data")
def run(self, registry): from liota.entities.metrics.metric import Metric import copy # Acquire resources from registry iotcc = registry.get("iotcc") iotcc_edge_system = copy.copy(registry.get("iotcc_edge_system")) bike_simulator = registry.get("bike_simulator") iotcc_bike = iotcc.register(bike_simulator) iotcc.create_relationship(iotcc_edge_system, iotcc_bike) ureg = bike_simulator.ureg self.create_udm(bike_model=bike_simulator) # Create metrics self.metrics = [] metric_name = "model.bike.speed" bike_speed = Metric(name=metric_name, unit=(ureg.m / ureg.sec), interval=5, sampling_function=self.get_bike_speed) reg_bike_speed = iotcc.register(bike_speed) iotcc.create_relationship(iotcc_bike, reg_bike_speed) reg_bike_speed.start_collecting() self.metrics.append(reg_bike_speed) metric_name = "model.bike.power" bike_power = Metric(name=metric_name, unit=ureg.watt, interval=5, sampling_function=self.get_bike_power) reg_bike_power = iotcc.register(bike_power) iotcc.create_relationship(iotcc_bike, reg_bike_power) reg_bike_power.start_collecting() self.metrics.append(reg_bike_power)
def test_validation_get_entity_hierarchy(self): """ Test case to check the validation of _get_entity_hierarchy method for Metric object. :return: None """ # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) # Checking whether implementation raising the TypeError for invalid input with self.assertRaises(TypeError): get_entity_hierarchy(test_metric)
def test_implementation_register_metric(self): """ Test case to check the implementation of register method of RabbitMQ for metric registration. :return: None """ # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) registered_metric = self.rabbitmq_client.register(test_metric) # Check the returned object is of the class RegisteredMetric self.assertIsInstance(registered_metric, RegisteredMetric)
def test_implementation_get_formatted_data_with_enclose_metadata(self): """ Test case to check the implementation of get_formatted_data method with enclose_metadata option of AWSIoT class. RegisteredEdgeSystem->RegisteredMetric :return: None """ # Register the edge registered_entity = self.aws.register(self.edge_system) # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) registered_metric = self.aws.register(test_metric) # Creating the parent-child relationship self.aws.create_relationship(registered_entity, registered_metric) timestamp = getUTCmillis() registered_metric.values.put((timestamp, 10)) expected_output = { "edge_system_name": registered_entity.ref_entity.name, "metric_name": registered_metric.ref_entity.name, "metric_data": [{ "value": 10, "timestamp": timestamp }], "unit": "null" } # Getting the parent child relationship array from registered metric formatted_data = get_formatted_data(registered_metric, True) formatted_json_data = json.loads(formatted_data) # Check two dicts are equal or not self.assertEqual( validate_json(formatted_json_data) == validate_json( expected_output), True, "Check implementation of get_formatted_data")
def run(self, registry): import copy from liota.entities.metrics.metric import Metric # Acquire resources from registry reg_edge_system = copy.copy(registry.get("sierra_edge_system")) opengate = registry.get("opengate_iot_DCC") # Create metrics tuple self.metrics = [] # Getting CPU utilization simulated_metric = Metric( name='Random.Metric', unit=None, interval=3, aggregation_size=3, sampling_function=simulated_sampling_function) reg_simulated_metric = opengate.register(simulated_metric) opengate.create_relationship(reg_edge_system, reg_simulated_metric) reg_simulated_metric.start_collecting() self.metrics.append(reg_simulated_metric)
def test_validation_create_relationship_metric_device(self): """ Test case to test validation for RegisteredMetric as Parent and RegisteredEntity as child. RegisteredMetric->RegisteredMetric :return: None """ # Register the edge registered_entity = self.rabbitmq_client.register(self.edge_system) # Creating test Metric test_metric = Metric(name="Test_Metric", unit=None, interval=10, aggregation_size=2, sampling_function=sampling_function) registered_metric = self.rabbitmq_client.register(test_metric) with self.assertRaises(TypeError): # Test case to check validation for RegisteredMetric as Parent and RegisteredEntity as child. self.rabbitmq_client.create_relationship(registered_metric, registered_entity)
def run(self, registry): from liota.entities.metrics.metric import Metric graphite = registry.get("graphite") windmill_simulator = registry.get("windmill_simulator") graphite_windmill = graphite.register(windmill_simulator) self.create_udm(windmill_model=windmill_simulator) self.metrics = [] metric_name = "model.rpm" rpm = Metric( name=metric_name, unit=None, interval=1, aggregation_size=1, sampling_function=self. get_rpm #how to plot rpm and actions taken along with it at once?? ) reg_rpm = graphite.register(rpm)
def run(self, registry): from liota.entities.devices.simulated_device import SimulatedDevice from liota.entities.metrics.metric import Metric import copy # Acquire resources from registry self.iotcc = registry.get("iotcc_mqtt") # Creating a copy of edge_system object to keep original object "clean" self.iotcc_edge_system = copy.copy(registry.get("iotcc_mqtt_edge_system")) # Get values from configuration file config_path = registry.get("package_conf") self.config = read_user_config(config_path + '/sampleProp.conf') # Register device ram_device = SimulatedDevice(self.config['DeviceName'], "Device-RAM") self.reg_ram_device = self.iotcc.register(ram_device) self.iotcc.set_properties(self.reg_ram_device, self.config['DevicePropList']) self.iotcc.create_relationship(self.iotcc_edge_system, self.reg_ram_device) # Create metrics self.metrics = [] mem_free_metric = Metric( name="Memory Free", unit=None, interval=10, sampling_function=read_mem_free ) reg_mem_free_metric = self.iotcc.register(mem_free_metric) self.iotcc.create_relationship(self.reg_ram_device, reg_mem_free_metric) reg_mem_free_metric.start_collecting() self.metrics.append(reg_mem_free_metric) # Use the iotcc_device_name as identifier in the registry to easily refer the device in other packages registry.register("reg_ram_device_mqtt", self.reg_ram_device)
def run(self, registry): from liota.entities.metrics.metric import Metric # Acquire resources from registry graphite = registry.get("graphite") thermistor_simulator = registry.get("thermistor_simulator") graphite_thermistor = graphite.register(thermistor_simulator) ureg = thermistor_simulator.ureg self.create_udm(thermistor_model=thermistor_simulator) # Create metrics self.metrics = [] metric_name = "model.thermistor.temperature" thermistor_temper = Metric( name=metric_name, unit=ureg.degC, interval=5, sampling_function=self.get_thermistor_temperature) reg_thermistor_temper = graphite.register(thermistor_temper) graphite.create_relationship(graphite_thermistor, reg_thermistor_temper) reg_thermistor_temper.start_collecting() self.metrics.append(reg_thermistor_temper)
identity=identity, tls_conf=tls_conf, qos_details=qos_details, clean_session=True, userdata=config['userdata'], protocol=config['protocol'], transport=['transport'], conn_disconn_timeout=config['ConnectDisconnectTimeout']), enclose_metadata=True) # Registering EdgeSystem reg_edge_system = aws.register(edge_system) # Creating CPU Metric cpu_utilization = Metric(name="CPUUtilization", unit=None, interval=10, aggregation_size=2, sampling_function=read_cpu_utilization) # Registering Metric and creating Parent-Child relationship reg_cpu_utilization = aws.register(cpu_utilization) aws.create_relationship(reg_edge_system, reg_cpu_utilization) # Publishing Registered CPU Utilization Metric to AWS reg_cpu_utilization.start_collecting() # Creating Simulated Device dht_sensor = SimulatedDevice("SimulatedDHTSensor") # Registering Device and creating Parent-Child relationship reg_dht_sensor = aws.register(dht_sensor) aws.create_relationship(reg_edge_system, reg_dht_sensor) # Creating Temperature Metric temp_metric = Metric(name="LivingRoomTemperature",
# these call set properties on the Resource representing the IoT System # properties are a key:value store reg_edge_system.set_properties(config['SystemPropList']) # ---------- Create metrics 'on' the Resource in IoTCC representing the IoT System # arguments: # local object referring to the Resource in IoTCC on which the metric should be associated # metric name # unit = An SI Unit (work needed here) # sampling_interval = the interval in seconds between called to the user function to obtain the next value for the metric # aggregation_size = the number of values collected in a cycle before publishing to DCC # value = user defined function to obtain the next value from the device associated with this metric cpu_utilization_metric = Metric(name="CPU Utilization", unit=None, interval=10, aggregation_size=2, sampling_function=read_cpu_utilization) reg_cpu_utilization_metric = iotcc.register(cpu_utilization_metric) iotcc.create_relationship(reg_edge_system, reg_cpu_utilization_metric) # call to start collecting values from the device or system and sending to the data center component reg_cpu_utilization_metric.start_collecting() cpu_procs_metric = Metric(name="CPU Process", unit=None, interval=6, aggregation_size=8, sampling_function=read_cpu_procs) reg_cpu_procs_metric = iotcc.register(cpu_procs_metric) iotcc.create_relationship(reg_edge_system, reg_cpu_procs_metric) reg_cpu_procs_metric.start_collecting()
edge_system = Dell5KEdgeSystem(config['EdgeSystemName']) # initialize and run the physical model (simulated device) bike_model = BikeSimulated(name=config['DeviceName'], ureg=ureg) # Sending data to Graphite data center component # Socket is the underlying transport used to connect to the Graphite # instance graphite = Graphite( SocketDccComms(ip=config['GraphiteIP'], port=config['GraphitePort'])) graphite_reg_dev = graphite.register(bike_model) metric_name = "model.bike.speed" bike_speed = Metric(name=metric_name, unit=(ureg.m / ureg.sec), interval=5, sampling_function=get_bike_speed) reg_bike_speed = graphite.register(bike_speed) graphite.create_relationship(graphite_reg_dev, reg_bike_speed) reg_bike_speed.start_collecting() metric_name = "model.bike.power" bike_power = Metric(name=metric_name, unit=ureg.watt, interval=5, sampling_function=get_bike_power) reg_bike_power = graphite.register(bike_power) graphite.create_relationship(graphite_reg_dev, reg_bike_power) reg_bike_power.start_collecting()