# In this example, we demonstrate how data for a simulated metric generating
# random numbers can be directed to graphite data center component using Liota.
# The program illustrates the ease of use Liota brings to IoT application
# developers.


def xmpp_subscribe():
    xmpp_conn = XmppDeviceComms("[email protected]", "m1ndst1x", "127.0.0.1",
                                "5222")
    xmpp_conn.subscribe("pubsub.127.0.0.1", "/vmware11",
                        callback_openfire_data)


if __name__ == '__main__':
    xmpp_subscribe()
    edge_system = SimulatedEdgeSystem('EdgeSystemName')

    # Sending data to Graphite data center component
    # Socket is the underlying transport used to connect to the Graphite
    # instance
    graphite = Graphite(SocketDccComms(ip='127.0.0.1', port=80))
    graphite_reg_edge_system = graphite.register(edge_system)

    metric_name = 'OpenfireData'
    openfire_metric = Metric(
        name=metric_name,
        interval=0,
        sampling_function=lambda: get_value(openfire_data))
    reg_openfire_metric = graphite.register(openfire_metric)
    graphite.create_relationship(graphite_reg_edge_system, reg_openfire_metric)
    reg_openfire_metric.start_collecting()
Ejemplo n.º 2
0
# Random number generator, simulating random metric readings.


def simulated_sampling_function():
    return random.randint(0, 20)


# ---------------------------------------------------------------------------
# In this example, we demonstrate how data for a simulated metric generating
# random numbers can be directed to graphite data center component using Liota.
# The program illustrates the ease of use Liota brings to IoT application
# developers.

if __name__ == '__main__':

    edge_system = SimulatedEdgeSystem(config['EdgeSystemName'])

    # Sending data to Graphite data center component
    # Socket is the underlying transport used to connect to the Graphite
    # instance
    graphite = Graphite(
        Socket(ip=config['GraphiteIP'], port=config['GraphitePort']))
    graphite_reg_edge_system = graphite.register(edge_system)

    metric_name = config['MetricName']
    simulated_metric = Metric(name=metric_name,
                              interval=10,
                              sampling_function=simulated_sampling_function)
    reg_metric = graphite.register(simulated_metric)
    graphite.create_relationship(graphite_reg_edge_system, reg_metric)
    reg_metric.start_collecting()