def main():

    f_uptime = open("/proc/uptime", "r")
    f_meminfo = open("/proc/meminfo", "r")
    f_vmstat = open("/proc/vmstat", "r")
    f_stat = open("/proc/stat", "r")
    f_loadavg = open("/proc/loadavg", "r")
    f_entropy_avail = open("/proc/sys/kernel/random/entropy_avail", "r")
    numastats = open_sysfs_numa_stats()

    while True:
        # Scalyr edit to add in check for parent.  A ppid of 1 means our parent has died.
        if os.getppid() == 1:
            sys.exit(1)

        # proc.uptime
        f_uptime.seek(0)
        ts = int(time.time())
        for line in f_uptime:
            m = re.match("(\S+)\s+(\S+)", line)
            if m:
                print "proc.uptime.total %d %s" % (ts, m.group(1))
                print "proc.uptime.now %d %s" % (ts, m.group(2))

        # proc.meminfo
        f_meminfo.seek(0)
        ts = int(time.time())
        for line in f_meminfo:
            m = re.match("(\w+):\s+(\d+)", line)
            if m:
                print ("proc.meminfo.%s %d %s"
                        % (m.group(1).lower(), ts, m.group(2)))

        # proc.vmstat
        f_vmstat.seek(0)
        ts = int(time.time())
        for line in f_vmstat:
            m = re.match("(\w+)\s+(\d+)", line)
            if not m:
                continue
            if m.group(1) in ("pgpgin", "pgpgout", "pswpin",
                              "pswpout", "pgfault", "pgmajfault"):
                print "proc.vmstat.%s %d %s" % (m.group(1), ts, m.group(2))

        # proc.stat
        f_stat.seek(0)
        ts = int(time.time())
        for line in f_stat:
            m = re.match("(\w+)\s+(.*)", line)
            if not m:
                continue
            if m.group(1) == "cpu":
                fields = m.group(2).split()
                print "proc.stat.cpu %d %s type=user" % (ts, fields[0])
                print "proc.stat.cpu %d %s type=nice" % (ts, fields[1])
                print "proc.stat.cpu %d %s type=system" % (ts, fields[2])
                print "proc.stat.cpu %d %s type=idle" % (ts, fields[3])
                print "proc.stat.cpu %d %s type=iowait" % (ts, fields[4])
                print "proc.stat.cpu %d %s type=irq" % (ts, fields[5])
                print "proc.stat.cpu %d %s type=softirq" % (ts, fields[6])
                # really old kernels don't have this field
                if len(fields) > 7:
                    print ("proc.stat.cpu %d %s type=steal"
                           % (ts, fields[7]))
                    # old kernels don't have this field
                    if len(fields) > 8:
                        print ("proc.stat.cpu %d %s type=guest"
                               % (ts, fields[8]))
            elif m.group(1) == "intr":
                print ("proc.stat.intr %d %s"
                        % (ts, m.group(2).split()[0]))
            elif m.group(1) == "ctxt":
                print "proc.stat.ctxt %d %s" % (ts, m.group(2))
            elif m.group(1) == "processes":
                print "proc.stat.processes %d %s" % (ts, m.group(2))
            elif m.group(1) == "procs_blocked":
                print "proc.stat.procs_blocked %d %s" % (ts, m.group(2))

        f_loadavg.seek(0)
        ts = int(time.time())
        for line in f_loadavg:
            m = re.match("(\S+)\s+(\S+)\s+(\S+)\s+(\d+)/(\d+)\s+", line)
            if not m:
                continue
            print "proc.loadavg.1min %d %s" % (ts, m.group(1))
            print "proc.loadavg.5min %d %s" % (ts, m.group(2))
            print "proc.loadavg.15min %d %s" % (ts, m.group(3))
            print "proc.loadavg.runnable %d %s" % (ts, m.group(4))
            print "proc.loadavg.total_threads %d %s" % (ts, m.group(5))

        f_entropy_avail.seek(0)
        ts = int(time.time())
        for line in f_entropy_avail:
            print "proc.kernel.entropy_avail %d %s" % (ts, line.strip())

        print_numa_stats(numastats)

        sys.stdout.flush()
        time.sleep(COLLECTION_INTERVAL)
procstats main loop
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/third_party/tcollector/collectors/0/procstats.py/main