Previous topic

2.5. Services

Next topic

2.7. Aggregator

This Page

2.6. Add a CollectorΒΆ

Simple

  • Inherit addon.Collector
  • Implement getReport()
  • Optionally implement connectStateChanged()

A collector is a singleton object that runs on every node and is periodically called, about once per second, to collect data and provide the data and type to be sent back to the controller. To add a new collector, place a python file in the modules directory that inherits from the Collector class defined in addons.py and implements the empty method getReport(). You must also include it in the dependency tree so that it is loaded at startup.

When the node daemon process is started, a singleton object will be created and the collector method getReport() will be called about once per second. The value now provides the current timestamp when the collection routine was started. getReport() should return data that is to be sent to the controller or None if there is no new data to send.

If connectStateChanged() is implemented, it will be called when ever the current connection state with the control node changes with a boolean value indicating wheter there is a valid connection

Note

getReport is only called when the experiment node is connected to a controller so most collectors don’t need to implement connectStateChanged

class FileReader(Collector):

    nodedir = '/local/logs/output'
    reporttype = 'FileOutput'

    def __init__(self):
            self.watcher = DirWatcher(self.nodedir)


    def getReport(self, now):
            (deleted, modified) = self.watcher.getChanges()
            if len(modified) > 0:
                    data = messages.Files()
                    for file in modified:
                            f = data.files.add()
                            f.name = file
                            f.modtime = 0 # Don't care
                            fp = open(self.watcher.watcheddir+"/"+file)
                            f.data = fp.read()
                            fp.close()
                    return data.SerializeToString()
            return None