Navigation:  LVE-Stats 2 > Creating a Plugin for LVE Stats 2 > Examples of Plugins >


Previous pageReturn to chapter overviewNext page

Analyzer decides if the file's size has changed and gives a command to persistor to refresh log.



# Example plugin for monitoring file size.

# Part 2. Analyzer


from lvestats.core.plugin import LveStatsPlugin


# Key name from collector plugin

COLLECTOR_KEY = 'FSizeWatcher_fsize'


# Key name 1 for saver plugin

SAVER_KEY = 'FSizeWatcher_fsize_to_store'

# Key name 2 for saver plugin

SAVER_DATA_PRESENCE = 'FSizeWatcher_fsize_present'



class FSize_watcher_analyzer (LveStatsPlugin):

 # this plugin should be second in chain

 order = 1

 # Last file size

 file_last_size = 0

 # Plugin run period in seconds

 period = 60


 def __init__(self):



 # work method

 def execute(self, lve_data):

         # Default setting for saver

         lve_data[SAVER_DATA_PRESENCE] = 0

         # Check presence data

         if COLLECTOR_KEY not in lve_data:



         # Get file size from server data dictionary

         fsize = lve_data[COLLECTOR_KEY]


         # Check, if file size changed, store it for saver plugin

         if fsize == self.file_last_size:



         # Put new size for saver plugin

         lve_data[SAVER_KEY] = fsize

         self.file_last_size = fsize

         lve_data[SAVER_DATA_PRESENCE] = 1


This plugin is extremely simple as well. It starts after collector (order=1), searches for file size in the dictionary and compares it with the previous index. If it has changed, then it writes a sign of presence of a new size into the dictionary. If no changes seen, then sign resets. The previous file size is stored in the plugin itself in file_last_size variable. Note that they are stored during the whole server lve-stats lifetime.


If file size is not found in data dictionary, then plugin just ends.


All the errors are completely ignored.


Analyzer is unconfigurable, that is why it doesn’t require any configuration file and it doesn’t contain set_config method.


Plugin starts every 60 seconds (1 minute), because we need data fixation to be performed one time in a minute.