HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //lib/check_mk_agent/local/locaweb-nfs
#!/usr/bin/python
import os
import time
import json

from pprint import pprint

stats = "/proc/self/mountstats"
cache = "/tmp/%s-mountstats.cache" % os.getuid()

def parse_mountstats():
    mountstats = {"timestamp": time.time(), "datasets": {}}
    device = None
    ops = {}
    for line in [ line.strip().split() for line in open(stats).readlines() ]:
        if len(line) == 0: continue
    
        # New device
        if line[0] == "device" and line[7] == "nfs" and "/.zfs/" not in line[1] and "/.snapshots" not in line[1]:
            if device:
                mountstats["datasets"][device] = ops

            device = line[1]
            ops = {}

        if line[0] == "xprt:":
            ops.update ({'connect_count': int(line[4]), 'connect_time': int(line[5]), 'rpcsends': int(line[7]), 'rpcreceives': int(line[8]), 'backlogutil': int(line[11]) })
    
        if line[0] in ("READ:", "WRITE:"):
            operation = line[0][:-1].lower()
            ops.update({operation+'_ops': float(line[1]), operation+'_retrans': float(line[2]) - float(line[1]), operation+'_bytes': (float(line[4]) + float(line[5])) / 1024 / 1024, operation+'_exe_time': float(line[8])})
    if device:
        mountstats["datasets"][device] = ops
    return mountstats


if __name__ == '__main__':
    stats = parse_mountstats()
    diff = {}
    if not os.path.isfile(cache):
        open(cache, 'w').write(json.dumps(stats))
    else:
        try:
            old = json.loads(open(cache).read())
        except:
            pass
        else:
            timediff = stats["timestamp"] - old["timestamp"]
            for dataset, info in stats["datasets"].iteritems():
                diff[dataset] = {}
                for key, value in info.iteritems():
                    if old["datasets"].get(dataset, {}).get(key):
                        valuediff = value - old["datasets"].get(dataset, {}).get(key)
                        if valuediff == 0:
                            diff[dataset][key] = valuediff
                        else:
                            diff[dataset][key] = valuediff / timediff
        open(cache, 'w').write(json.dumps(stats))

    for dataset, info in diff.iteritems():
        print "0 stats-%s" % dataset, "|".join([ "%s=%s" % (x, y) for x, y in info.iteritems() ]), "OK"