예제 #1
0
"""
To use create a config in your porkchop conf dir called jsondata.ini. In that
config place the following::

   [jsondata]
   path = <path to your json file>

"""

import json

from porkchop.plugin import PorkchopPlugin, test_plugin_data


class JsondataPlugin(PorkchopPlugin):
    def get_data(self):
        try:
            path = self.config['jsondata']['path']
        except KeyError:
            return {}
        with open(path) as f:
            return json.load(f)

if __name__ == '__main__':
    print test_plugin_data('jsondata')
예제 #2
0
            resp_hdr += sock.recv(1)

          resp_len = int(resp_hdr.strip())
          resp_data = sock.recv(resp_len)
          sock.send('quit\r\n')

      except (socket.error, ValueError):
        continue

      for line in resp_data.splitlines():
        # apparently some versions of redis have comments and empty lines
        if not line or line.startswith('#'):
          continue

        k, v = line.split(':', 1)

        # some stat values are CSV, k/v delimited with an '='
        # one of them is allocation_stats but its format is
        # all f****d up
        if ',' in v and k != 'allocation_stats':
          for stat in v.split(','):
            k2, v2 = stat.split('=')
            data[port][k][k2] = v2
        else:
          data[port][k] = v

    return data

if __name__ == '__main__':
  print test_plugin_data('redis')
예제 #3
0
from porkchop.plugin import PorkchopPlugin, PorkchopPluginHandler, test_plugin_data
from porkchop.util import parse_config


def iter_stats(glob_):
    """Yields a label at a time from every mmstats file in MMSTATS_DIR"""
    for fn in glob.glob(glob_):
        try:
            for label, value in MmStatsReader.from_mmap(fn):
                yield fn, label, value
        except Exception:
            continue


class MmsPlugin(PorkchopPlugin):

    def get_data(self):
        try:
            path = self.config['mmstats']['mmstats_path']
        except KeyError:
            path = tempdir()
        GLOB = os.path.join(path, 'mmstats-*')
        stats = {}
        for _, label, value in iter_stats(GLOB):
            stats.update({label: value})
        return stats

if __name__ == '__main__':
    print test_plugin_data('mms')