Getting gaps in metric data for data from an EP Agent plugin

Document ID : KB000122851
Last Modified Date : 11/12/2018
Show Technical Document Details
We are running a python script as a stateful plugin to report data back to the EP agent every 15 seconds. As far as we can tell the plugin runs correctly but we find that in the data recorded in APM there are gaps (zero values) in the data
User-added image
EPA agent – any platform any release
This is not a APM issue. The plugin is running as a stateful plugin and the 15 second interval is controlled in the plugin code itself not by the EP agent via the delayinseconds setting as would be the case for stateless plugins. The problem is not the way that the script is run but in the way python outputs data. It maintains it’s data in a buffer and for performance reasons will only flush the buffer to stdout when it is full. Therefore if the buffer is not filled every 15 seconds the data may not be sent.
To ensure the data is sent for each cycle you need to flush the output buffers using sys.stdout.flush() as shown in the below artificial example
import sys
import re
import time
def main():
        while True:
                print "<metric type=\"IntAverage\" name=\"MYSCRIPTPY1|VirtualMachine|Process|ME:Cpu Usage %\" value=\"55\" />"
if __name__ == "__main__":