I am trying to read in a log file in python that is updated every 20 seconds. So far I am only able to read a static file. I am trying to read in these values to plot them on a graph using HighCharts. I am able to plot the values using a static file. However I would like the graph to be real time. Could anyone help me with this?
with open(self.filename) as f:
        cpu = []
        idle = []
        wait = []
        ld5 = []
        ld10 = []
        ld15 = []
        load = []
        swapu = []
        swapf = []
        #need to remove all the white space in the file
        for line in f:
            if line is not None:
                    stripped = line.strip()
                    dstat_tokens = self.whitespace_re.split(stripped)           
            #dstat_tokens = self.whitespace_re.split(stripped)
                    dstat_tokens = line.split(',')
                    (timestamp) = dstat_tokens[0:1]
                    (system,user,idl, wt, hwi, sfi) = dstat_tokens[1:7];
                    (diskread,diskwrite) = dstat_tokens[7:9]
                    (pagein,pageout) = dstat_tokens[9:11]
                    (load5,load10,load15) = dstat_tokens[11:14]
                    (used,buffers,cache,free) = dstat_tokens[14:18]
                    (swapused,swapfree) = dstat_tokens[18:20]
                    (interrupts,contextswitches) = dstat_tokens[20:22]
                    (receive,send) = dstat_tokens[22:24]
                    (runnable,uninterruptable,new) = dstat_tokens[24:27]
                #print "Stripping %s" % timestamp[0]
                    ts = time.strptime(timestamp[0], "%d %b %Y %H:%M:%S CET")
                    dt = datetime.fromtimestamp(time.mktime(ts))
                    returned_time = dt.strftime("%d/%m/%Y %H:%M:%S")
                #print returned_time
                    cpu.append({"ts": returned_time, "value": float(system)})
                    idle.append({"ts": returned_time, "value": float(idl)})
                    wait.append({"ts": returned_time, "value": float(wt)})
                    ld5.append({"ts": returned_time, "value": float(load5)})
                    ld10.append({"ts": returned_time, "value": float(load10)})
                    ld15.append({"ts": returned_time, "value": float(load15)})
                    load.append({"ts": returned_time, "value": float(load5)})
                    swapu.append({"ts": returned_time, "value": float(swapused)})
                    swapf.append({"ts": returned_time, "value": float(swapfree)})
            self.data["cpu"] = cpu
            self.data["idle"] = idle
            self.data["load5"] = ld5
            self.data["load10"] = ld10
            self.data["load15"] = ld15
            self.data["swapused"] = swapu
            self.data["swapfree"] = swapf`
 
    