コード例 #1
0
 def option(self, opt, optarg, index):
     """ Perform setup for an individual command line option """
     if index == self.daemonize and opt == '':
         self.daemonize = 1
         return
     if opt == 'K':
         if not self.speclocal or not self.speclocal.startswith(";"):
             self.speclocal = ";" + optarg
         else:
             self.speclocal = self.speclocal + ";" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'F':
         if os.path.exists(optarg):
             sys.stderr.write("File %s already exists.\n" % optarg)
             sys.exit(1)
         self.outfile = optarg
     elif opt == 'e':
         if not self.derived or not self.derived.startswith(";"):
             self.derived = ";" + optarg
         else:
             self.derived = self.derived + ";" + optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'r':
         self.type = 1
     elif opt == 'R':
         self.type_prefer = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(
             optarg)
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'P':
         self.precision = optarg
     elif opt == '0':
         self.precision_force = optarg
     elif opt == 'f':
         self.timefmt = optarg
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'Q':
         self.count_scale_force = optarg
     elif opt == 'B':
         self.space_scale_force = optarg
     elif opt == 'Y':
         self.time_scale_force = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #2
0
ファイル: pcp2graphite.py プロジェクト: goodwinos/pcp
    def connect(self):
        """ Establish a PMAPI context """
        context, self.source = pmapi.pmContext.set_connect_options(self.opts, self.source, self.speclocal)

        self.pmfg = pmapi.fetchgroup(context, self.source)
        self.pmfg_ts = self.pmfg.extend_timestamp()
        self.context = self.pmfg.get_context()

        if pmapi.c_api.pmSetContextOptions(self.context.ctx, self.opts.mode, self.opts.delta):
            raise pmapi.pmUsageErr()
コード例 #3
0
    def connect(self):
        """ Establish PMAPI context """
        context, self.source = pmapi.pmContext.set_connect_options(self.opts, self.source, self.speclocal)

        self.pmfg = pmapi.fetchgroup(context, self.source)
        self.pmfg_ts = self.pmfg.extend_timestamp()
        self.context = self.pmfg.get_context()

        if pmapi.c_api.pmSetContextOptions(self.context.ctx, self.opts.mode, self.opts.delta):
            raise pmapi.pmUsageErr()
コード例 #4
0
 def option(self, opt, optarg, index):
     """ Perform setup for an individual command line option """
     if index == self.daemonize and opt == '':
         self.daemonize = 1
         return
     if opt == 'K':
         if not self.speclocal or not self.speclocal.startswith("K:"):
             self.speclocal = "K:" + optarg
         else:
             self.speclocal = self.speclocal + "|" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'F':
         if os.path.exists(optarg):
             sys.stderr.write("File %s already exists.\n" % optarg)
             sys.exit(1)
         self.outfile = optarg
     elif opt == 'e':
         self.derived = optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'r':
         self.type = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(
             optarg)
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'P':
         try:
             self.precision = int(optarg)
         except:
             sys.stderr.write(
                 "Error while parsing options: Integer expected.\n")
             sys.exit(1)
     elif opt == 'f':
         self.timefmt = optarg
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'x':
         self.extended = 1
     elif opt == 'X':
         self.everything = 1
     else:
         raise pmapi.pmUsageErr()
コード例 #5
0
ファイル: prometheus2pcp.py プロジェクト: nkshirsagar/pcp-1
 def openArchive(self, tz=None):
     if self.args.verbose:
         print("create new archive %s" % self.args.archive)
     if self.args.archive is None:
         raise pmapi.pmUsageErr()
     # TODO create path to archive if necessary
     self.pmi = pmi.pmiLogImport(self.args.archive)
     if self.args.host is not None:
         self.pmi.pmiSetHostname(self.args.host)
     if self.args.zone is not None:
         self.pmi.pmiSetTimezone(self.args.zone)
コード例 #6
0
 def option(self, opt, optarg, index):
     # need only handle the non-common options
     if opt == 'g':
         self.elasticsearch_host = optarg
     elif opt == 'u':
         self.unitsstr = optarg
     elif opt == 'm':
         self.es_index = optarg
     elif opt == 'i':
         self.hostid = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #7
0
 def option(self, opt, optarg, index):
     """ Perform setup for an individual command line option """
     if index == self.daemonize and opt == '':
         self.daemonize = 1
         return
     if opt == 'K':
         if not self.speclocal or not self.speclocal.startswith("K:"):
             self.speclocal = "K:" + optarg
         else:
             self.speclocal = self.speclocal + "|" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'e':
         self.derived = optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'r':
         self.type = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(
             optarg)
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'P':
         self.precision = int(optarg)
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'g':
         self.graphite_host = optarg
     elif opt == 'p':
         self.graphite_port = int(optarg)
         self.pickle = 1
     elif opt == 'X':
         self.pickle_protocol = int(optarg)
         self.pickle = 1
     elif opt == 'E':
         self.graphite_port = int(optarg)
         self.pickle = 0
     elif opt == 'x':
         self.prefix = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #8
0
ファイル: pcp2graphite.py プロジェクト: marcliangma8/pcp
 def option(self, opt, optarg, index):  # need only handle the non-common options
     if opt == "g":
         self.graphite_host = optarg
     elif opt == "p":
         self.graphite_port = int(optarg if optarg else "2004")
         self.pickle = True
     elif opt == "P":
         self.graphite_port = int(optarg if optarg else "2003")
         self.pickle = False
     elif opt == "u":
         self.unitsstr = optarg
     elif opt == "m":
         self.prefix = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #9
0
 def option(self, opt, optarg, index): # need only handle the non-common options
     if (opt == 'g'):
         self.graphite_host = optarg
     elif (opt == 'p'):
         self.graphite_port = int(optarg if optarg else "2004")
         self.pickle = True
     elif (opt == 'P'):
         self.graphite_port = int(optarg if optarg else "2003")
         self.pickle = False
     elif (opt == 'u'):
         self.unitsstr = optarg
     elif (opt == 'm'):
         self.prefix = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #10
0
 def option(self, opt, optarg, index):
     # need only handle the non-common options
     if opt == 'i':
         self.influxdb_address = optarg
     elif opt == 'u':
         self.unitsstr = optarg
     elif opt == 'd':
         self.database = optarg
     elif opt == 'U':
         self.influxdb_user = optarg
     elif opt == 'P':
         self.influxdb_pass = optarg
     elif opt == 'I':
         self.influxdb_tags = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #11
0
    def connect(self):
        """ Establish a PMAPI context """
        context, self.source = pmapi.pmContext.set_connect_options(self.opts, self.source, self.speclocal)

        if context == PM_CONTEXT_HOST:
            try:
                self.pmfg = pmapi.fetchgroup(context, self.source)
            except pmapi.pmErr:
                context = PM_CONTEXT_LOCAL
        if self.pmfg == None:
            self.pmfg = pmapi.fetchgroup(context, self.source)
        self.pmfg_ts = self.pmfg.extend_timestamp()
        self.context = self.pmfg.get_context()

        if pmapi.c_api.pmSetContextOptions(self.context.ctx, self.opts.mode, self.opts.delta):
            raise pmapi.pmUsageErr()
コード例 #12
0
ファイル: pcp2influxdb.py プロジェクト: sitaramshelke/pcp
 def option(self, opt, optarg, index):
     # need only handle the non-common options
     if opt == 'i':
         self.influxdb_address = optarg
     elif opt == 'u':
         self.unitsstr = optarg
     elif opt == 'd':
         self.database = optarg
     elif opt == 'U':
         self.influxdb_user = optarg
     elif opt == 'P':
         self.influxdb_pass = optarg
     elif opt == 'I':
         self.influxdb_tags = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #13
0
ファイル: pcp2graphite.py プロジェクト: jirib/pcp
 def option(self, opt, optarg, index):
     # need only handle the non-common options
     if opt == 'g':
         self.graphite_host = optarg
     elif opt == 'p':
         self.graphite_port = int(optarg if optarg else "2004")
         self.pickle = True
     elif opt == 'r':
         self.pickle_protocol = int(optarg if optarg else "0")
     elif opt == 'P':
         self.graphite_port = int(optarg if optarg else "2003")
         self.pickle = False
     elif opt == 'u':
         self.unitsstr = optarg
     elif opt == 'm':
         self.prefix = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #14
0
 def option(self, opt, optarg, index):
     """ Perform setup for an individual command line option """
     if index == self.daemonize and opt == '':
         self.daemonize = 1
         return
     if opt == 'K':
         if not self.speclocal or not self.speclocal.startswith(";"):
             self.speclocal = ";" + optarg
         else:
             self.speclocal = self.speclocal + ";" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'o':
         self.output = optarg
     elif opt == 'F':
         if os.path.exists(optarg + ".index"):
             sys.stderr.write("Archive %s already exists.\n" % optarg)
             sys.exit(1)
         if os.path.exists(optarg):
             kind = "File" if os.path.isfile(optarg) else "Directory"
             sys.stderr.write("%s %s already exists.\n" % (kind, optarg))
             sys.exit(1)
         self.outfile = optarg
     elif opt == 'e':
         if not self.derived or not self.derived.startswith(";"):
             self.derived = ";" + optarg
         else:
             self.derived = self.derived + ";" + optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'U':
         self.unitinfo = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'p':
         self.timestamp = 1
     elif opt == 'd':
         self.delay = 1
     elif opt == 'r':
         self.type = 1
     elif opt == 'R':
         self.type_prefer = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(
             optarg)
     elif opt == 'j':
         self.live_filter = 1
     elif opt == 'J':
         self.rank = optarg
     elif opt == 'n':
         self.invert_filter = 1
     elif opt == 'N':
         self.predicate = optarg
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'X':
         self.colxrow = optarg
     elif opt == 'w':
         self.width = optarg
     elif opt == 'W':
         self.width_force = optarg
     elif opt == 'P':
         self.precision = optarg
     elif opt == '0':
         self.precision_force = optarg
     elif opt == 'l':
         self.delimiter = optarg
     elif opt == 'k':
         self.extcsv = 1
     elif opt == 'x':
         self.extheader = 1
     elif opt == 'E':
         self.repeat_header = optarg
     elif opt == 'g':
         self.separate_header = 1
     elif opt == 'f':
         self.timefmt = optarg
     elif opt == 'u':
         self.interpol = 0
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'Q':
         self.count_scale_force = optarg
     elif opt == 'B':
         self.space_scale_force = optarg
     elif opt == 'Y':
         self.time_scale_force = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #15
0
ファイル: pcp2graphite.py プロジェクト: goodwinos/pcp
 def option(self, opt, optarg, _index):
     """ Perform setup for individual command line option """
     if opt == 'daemonize':
         self.daemonize = 1
     elif opt == 'K':
         if not self.speclocal or not self.speclocal.startswith(";"):
             self.speclocal = ";" + optarg
         else:
             self.speclocal = self.speclocal + ";" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'e':
         if not self.derived or not self.derived.startswith(";"):
             self.derived = ";" + optarg
         else:
             self.derived = self.derived + ";" + optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'r':
         self.type = 1
     elif opt == 'R':
         self.type_prefer = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == '5':
         self.ignore_unknown = 1
     elif opt == '4':
         if optarg == 'ignore':
             self.names_change = 0
         elif optarg == 'abort':
             self.names_change = 1
         elif optarg == 'update':
             self.names_change = 2
         else:
             sys.stderr.write("Unknown names-change action '%s' specified.\n" % optarg)
             sys.exit(1)
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(optarg)
     elif opt == 'j':
         self.live_filter = 1
     elif opt == 'J':
         self.rank = optarg
     elif opt == '8':
         self.limit_filter = optarg
     elif opt == '9':
         self.limit_filter_force = optarg
     elif opt == 'n':
         self.invert_filter = 1
     elif opt == 'N':
         self.predicate = optarg
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'P':
         self.precision = optarg
     elif opt == '0':
         self.precision_force = optarg
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'Q':
         self.count_scale_force = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'B':
         self.space_scale_force = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'Y':
         self.time_scale_force = optarg
     elif opt == 'g':
         self.graphite_host = optarg
     elif opt == 'p':
         self.graphite_port = int(optarg)
         self.pickle = 1
     elif opt == 'X':
         self.pickle_protocol = int(optarg)
         self.pickle = 1
     elif opt == 'E':
         self.graphite_port = int(optarg)
         self.pickle = 0
     elif opt == 'x':
         self.prefix = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #16
0
ファイル: pcp2graphite.py プロジェクト: jirib/pcp
    def __init__(self):
        """ Construct object, parse command line """
        self.context = None
        self.socket = None
        self.sample_count = 0
        self.opts = pmapi.pmOptions()
        self.opts.pmSetShortOptions("a:O:s:T:g:p:P:r:u:m:t:h:t:D:LV?")
        self.opts.pmSetShortUsage("[options] metricname ...")
        self.opts.pmSetOptionCallback(self.option)
        self.opts.pmSetOverrideCallback(self.option_override)
        self.opts.pmSetLongOptionText("""
Description: Periodically, relay raw values of all instances of a
given hierarchies of PCP metrics to a graphite/carbon server on the
network.""")
        self.opts.pmSetLongOptionHeader("Options")
        self.opts.pmSetLongOptionVersion() # -V
        self.opts.pmSetLongOptionArchive() # -a FILE
        self.opts.pmSetLongOptionOrigin() # -O TIME
        self.opts.pmSetLongOptionSamples() # -s NUMBER
        self.opts.pmSetLongOptionFinish() # -T NUMBER
        self.opts.pmSetLongOptionDebug() # -D stuff
        self.opts.pmSetLongOptionHost() # -h HOST
        self.opts.pmSetLongOptionLocalPMDA() # -L
        self.opts.pmSetLongOptionInterval() # -t NUMBER
        self.opts.pmSetLongOption("graphite-host", 1, 'g', '',
                                  "graphite server host " +
                                  "(default \"localhost\")")
        self.opts.pmSetLongOption("pickled-port", 1, 'p', '',
                                  "graphite pickled port (default 2004)")
        self.opts.pmSetLongOption("text-port", 1, 'P', '',
                                  "graphite plaintext port (usually 2003)")
        self.opts.pmSetLongOption("units", 1, 'u', '',
                                  "rescale units " +
                                  "(e.g. \"MB\", will omit incompatible units)")
        self.opts.pmSetLongOption("prefix", 1, 'm', '',
                                  "prefix for metric names (default \"pcp.\")")
        self.opts.pmSetLongOption("pickle-protocol", 1, 'r', 'PROTOCOL',
                                  "graphite pickle protocol (default 0)")
        self.opts.pmSetLongOptionHelp()
        self.graphite_host = "localhost"
        self.graphite_port = 2004
        self.pickle = True
        self.pickle_protocol = 0
        self.prefix = "pcp."
        self.unitsstr = None
        self.units = None # pass verbatim by default
        self.units_mult = None # pass verbatim by default

        # now actually parse
        self.context = pmapi.pmContext.fromOptions(self.opts, sys.argv)
        self.interval = self.opts.pmGetOptionInterval() or pmapi.timeval(60, 0)
        if self.unitsstr is not None:
            units = self.context.pmParseUnitsStr(self.unitsstr)
            (self.units, self.units_mult) = units
        self.metrics = []
        self.pmids = []
        self.descs = []
        metrics = self.opts.pmGetNonOptionsFromList(sys.argv)
        if metrics:
            for m in metrics:
                try:
                    self.context.pmTraversePMNS(m, self.handle_candidate_metric)
                except pmapi.pmErr as error:
                    sys.stderr.write("Excluding metric %s (%s)\n" %
                                     (m, str(error)))
            sys.stderr.flush()

        if len(self.metrics) == 0:
            sys.stderr.write("No acceptable metrics specified.\n")
            raise pmapi.pmUsageErr()

        # Report what we're about to do
        print("Relaying %d %smetric(s) with prefix %s from %s "
              "in %s mode to %s:%d every %f s" %
              (len(self.metrics),
               "rescaled " if self.units else "",
               self.prefix,
               self.describe_source(),
               "pickled" if self.pickle else "text",
               self.graphite_host, self.graphite_port,
               self.interval))
        sys.stdout.flush()
コード例 #17
0
ファイル: pmconfig.py プロジェクト: fbacchella/pcp
    def prepare_metrics(self):
        """ Construct and prepare metricset """
        metrics = self.util.opts.pmGetOperands()
        if not metrics:
            sys.stderr.write("No metrics specified.\n")
            raise pmapi.pmUsageErr()

        # Read config
        # Python < 3.2 compat
        if sys.version_info[0] >= 3 and sys.version_info[1] >= 2:
            config = ConfigParser.ConfigParser()
        else:
            config = ConfigParser.SafeConfigParser()
        config.optionxform = str
        if self.util.config:
            try:
                config.read(self.util.config)
            except ConfigParser.Error as error:
                sys.stderr.write(
                    "Failed to read configuration file '%s', line %d:\n%s\n" %
                    (self.util.config, error.lineno, str(
                        error.message).split("\n")[0]))  # pylint: disable=no-member
                sys.exit(1)

        # First read global metrics (if not disabled already)
        globmet = OrderedDict()
        if self.util.globals == 1:
            if config.has_section('global'):
                parsemet = OrderedDict()
                for key in config.options('global'):
                    if key in self.util.keys:
                        sys.stderr.write(
                            "No options allowed in [global] section.\n")
                        sys.exit(1)
                    self.parse_metric_info(parsemet, key,
                                           config.get('global', key))
                for metric in parsemet:
                    name = parsemet[metric][:1][0]
                    globmet[name] = parsemet[metric][1:]

        # Add command line and configuration file metricsets
        tempmet = OrderedDict()
        for metric in metrics:
            if metric.startswith(":"):
                tempmet[metric[1:]] = None
            else:
                spec, insts = self.parse_metric_spec_instances(metric)
                m = spec.split(",")
                m[2] = insts
                tempmet[m[0]] = m[1:]

        # Get config and set details for configuration file metricsets
        confmet = OrderedDict()
        for spec in tempmet:
            if tempmet[spec] is None:
                if config.has_section(spec):
                    parsemet = OrderedDict()
                    for key in config.options(spec):
                        if key not in self.util.keys:
                            self.parse_metric_info(parsemet, key,
                                                   config.get(spec, key))
                    for metric in parsemet:
                        name = parsemet[metric][:1][0]
                        confmet[name] = parsemet[metric][1:]
                    tempmet[spec] = confmet
                else:
                    raise IOError("Metricset definition '%s' not found." %
                                  metric)

        # Create combined metricset
        if self.util.globals == 1:
            for metric in globmet:
                self.util.metrics[metric] = globmet[metric]
        for metric in tempmet:
            if isinstance(tempmet[metric], list):
                self.util.metrics[metric] = tempmet[metric]
            else:
                if tempmet[metric]:
                    for m in tempmet[metric]:
                        self.util.metrics[m] = confmet[m]

        if not self.util.metrics:
            raise IOError("No metrics specified.")

        self._conf_metrics = deepcopy(self.util.metrics)
コード例 #18
0
ファイル: pmconfig.py プロジェクト: fbacchella/pcp
 def read_cmd_line(self):
     """ Read command line options """
     pmapi.c_api.pmSetOptionFlags(pmapi.c_api.PM_OPTFLAG_DONE)
     if pmapi.c_api.pmGetOptionsFromList(sys.argv):
         raise pmapi.pmUsageErr()
     return pmapi.c_api.pmGetOperands()
コード例 #19
0
ファイル: pcp2xlsx.py プロジェクト: goodwinos/pcp
 def option(self, opt, optarg, _index):
     """ Perform setup for individual command line option """
     if opt == 'daemonize':
         self.daemonize = 1
     elif opt == 'K':
         if not self.speclocal or not self.speclocal.startswith(";"):
             self.speclocal = ";" + optarg
         else:
             self.speclocal = self.speclocal + ";" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'F':
         if os.path.exists(optarg):
             sys.stderr.write("File %s already exists.\n" % optarg)
             sys.exit(1)
         self.outfile = optarg
     elif opt == 'e':
         if not self.derived or not self.derived.startswith(";"):
             self.derived = ";" + optarg
         else:
             self.derived = self.derived + ";" + optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'r':
         self.type = 1
     elif opt == 'R':
         self.type_prefer = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == '5':
         self.ignore_unknown = 1
     elif opt == '4':
         if optarg == 'ignore':
             self.names_change = 0
         elif optarg == 'abort':
             self.names_change = 1
         else:
             sys.stderr.write("Unknown names-change action '%s' specified.\n" % optarg)
             sys.exit(1)
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(optarg)
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'P':
         self.precision = optarg
     elif opt == '0':
         self.precision_force = optarg
     elif opt == 'f':
         self.timefmt = optarg
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'Q':
         self.count_scale_force = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'B':
         self.space_scale_force = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'Y':
         self.time_scale_force = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #20
0
    def __init__(self):
        """ Construct object, parse command line """
        self.context = None
        self.database = 'pcp'
        self.influxdb_tags = ''
        self.influxdb_address = 'http://127.0.0.1:8086'
        self.influxdb_user = None
        self.influxdb_pass = None
        self.sample_count = 0
        self.unitsstr = None
        self.units = None
        self.units_mult = None

        # option setup
        self.opts = pmapi.pmOptions()
        self.opts.pmSetShortOptions("a:O:s:T:g:p:P:r:m:t:u:h:t:D:LV?")
        self.opts.pmSetShortUsage("[options] metricname ...")
        self.opts.pmSetLongOptionText("""
Description: Periodically, relay raw values of all instances of a
given hierarchies of PCP metrics to an InfluxDB server on the network.""")
        self.opts.pmSetLongOptionHeader("Options")
        self.opts.pmSetOptionCallback(self.option)

        # common options
        self.opts.pmSetLongOptionVersion()
        self.opts.pmSetLongOptionArchive()
        self.opts.pmSetLongOptionOrigin()
        self.opts.pmSetLongOptionSamples()
        self.opts.pmSetLongOptionFinish()
        self.opts.pmSetLongOptionDebug()
        self.opts.pmSetLongOptionHost()
        self.opts.pmSetLongOptionLocalPMDA()
        self.opts.pmSetLongOptionInterval()

        # custom options
        self.opts.pmSetLongOption(
            "influxdb-address", 1, 'i', '', "InfluxDB HTTP/HTTPS address " +
            "(default \"" + self.influxdb_address + "\")")
        self.opts.pmSetLongOption(
            "units", 1, 'u', '',
            "rescale units " + "(e.g. \"MB\", will omit incompatible units)")
        self.opts.pmSetLongOption("database", 1, 'd', '',
                                  "database for metric (default \"pcp\")")
        self.opts.pmSetLongOption("db-user", 1, 'U', '',
                                  "username for InfluxDB database")
        self.opts.pmSetLongOption("db-password", 1, 'P', '',
                                  "password for InfluxDB database")
        self.opts.pmSetLongOption("tag-string", 1, 'I', '',
                                  "string of tags to add to the metrics")
        self.opts.pmSetLongOptionHelp()

        # parse options
        self.context = pmapi.pmContext.fromOptions(self.opts, sys.argv)
        self.interval = self.opts.pmGetOptionInterval() or pmapi.timeval(60, 0)
        if self.unitsstr is not None:
            units = self.context.pmParseUnitsStr(self.unitsstr)
            (self.units, self.units_mult) = units
        self.metrics = []
        self.pmids = []
        self.descs = []
        metrics = self.opts.pmGetNonOptionsFromList(sys.argv)
        if metrics:
            for m in metrics:
                try:
                    self.context.pmTraversePMNS(m,
                                                self.handle_candidate_metric)
                except pmapi.pmErr as error:
                    sys.stderr.write("Excluding metric %s (%s)\n" %
                                     (m, str(error)))

            sys.stderr.flush()

        if len(self.metrics) == 0:
            sys.stderr.write("No acceptable metrics specified.\n")
            raise pmapi.pmUsageErr()

        # Report what we're about to do
        print("Relaying %d %smetric(s) to database %s with tags %s from %s "
              "to %s every %f s" %
              (len(self.metrics), "rescaled " if self.units else "",
               self.database, self.influxdb_tags, self.describe_source(),
               self.influxdb_address, self.interval))

        sys.stdout.flush()
コード例 #21
0
    def __init__(self):
        """ Construct object, parse command line """
        self.context = None
        self.opts = pmapi.pmOptions()
        self.opts.pmSetShortOptions("g:p:P:u:m:t:h:Lt:D:V?") # must include common options
        self.opts.pmSetShortUsage("[options] metricname ...")
        self.opts.pmSetOptionCallback(self.option)
        self.opts.pmSetOverrideCallback(self.option_override)
        # hack to include some explanatory text
        self.opts.pmSetLongOptionHeader("""
Description: Periodically, relay raw values of all instances of a
given hierarchies of PCP metrics to a graphite/carbon server on the
network.

Options""")
        self.opts.pmSetLongOptionVersion() # -V
        # self.opts.pmSetLongOptionArchive() # -a FILE   -- not supported yet; need -S/etc. controls
        self.opts.pmSetLongOptionDebug() # -D stuff
        self.opts.pmSetLongOptionHost() # -h HOST
        # self.opts.pmSetLongOptionLocalPMDA() # -L
        self.opts.pmSetLongOptionInterval() # -t NUMBER
        self.opts.pmSetLongOption("graphite-host", 1, 'g', '', "graphite server host (default \"localhost\")")
        self.opts.pmSetLongOption("pickled-port", 1, 'p', '', "graphite pickled port (default 2004)")
        self.opts.pmSetLongOption("text-port", 1, 'P', '', "graphite plaintext port (usually 2003)")
        self.opts.pmSetLongOption("units", 1, 'u', '', "rescale all metric units (e.g., \"mbytes/5 sec\")")
        self.opts.pmSetLongOption("prefix", 1, 'm', '', "prefix for metric names (default \"pcp.\")")
        self.opts.pmSetLongOptionHelp()
        self.graphite_host = "localhost"
        self.graphite_port = 2004
        self.pickle = True
        self.prefix = "pcp."
        self.unitsstr = None
        self.units = None # pass verbatim by default
        self.units_mult = None # pass verbatim by default

        # now actually parse
        self.context = pmapi.pmContext.fromOptions(self.opts, sys.argv)
        self.interval = self.opts.pmGetOptionInterval() or pmapi.timeval(60,0)

        if self.unitsstr is not None:
            (self.units, self.units_mult) = self.context.pmParseUnitsStr(self.unitsstr)
        self.metrics = []
        self.pmids = []
        self.descs = []
        metrics = self.opts.pmNonOptionsFromList(sys.argv)
        if metrics:
            for m in metrics:
                try:
                    self.context.pmTraversePMNS(m, self.handle_candidate_metric)
                except pmapi.pmErr as error:
                    sys.stderr.write("Excluding metric %s (%s)\n" % (m, str(error)))
            sys.stderr.flush()

        if len(self.metrics) == 0:
            sys.stderr.write("No acceptable metrics specified.\n")
            raise pmapi.pmUsageErr()

        # Report what we're about to do
        print("Relaying %d %smetric(s) with prefix %s "
              "in %s mode to %s:%d every %f s" % (
                len(self.metrics),
                "rescaled " if self.units else "",
                self.prefix,
                "pickled" if self.pickle else "text",
                self.graphite_host, self.graphite_port,
                self.interval))
        sys.stdout.flush()
コード例 #22
0
ファイル: pcp2influxdb.py プロジェクト: sitaramshelke/pcp
    def __init__(self):
        """ Construct object, parse command line """
        self.context = None
        self.database = 'pcp'
        self.influxdb_tags = ''
        self.influxdb_address = 'http://127.0.0.1:8086'
        self.influxdb_user = None
        self.influxdb_pass = None
        self.sample_count = 0
        self.unitsstr = None
        self.units = None
        self.units_mult = None

        # option setup
        self.opts = pmapi.pmOptions()
        self.opts.pmSetShortOptions("a:O:s:T:g:p:P:r:m:t:u:h:t:D:LV?")
        self.opts.pmSetShortUsage("[options] metricname ...")
        self.opts.pmSetLongOptionText("""
Description: Periodically, relay raw values of all instances of a
given hierarchies of PCP metrics to an InfluxDB server on the network.""")
        self.opts.pmSetLongOptionHeader("Options")
        self.opts.pmSetOptionCallback(self.option)

        # common options
        self.opts.pmSetLongOptionVersion()
        self.opts.pmSetLongOptionArchive()
        self.opts.pmSetLongOptionOrigin()
        self.opts.pmSetLongOptionSamples()
        self.opts.pmSetLongOptionFinish()
        self.opts.pmSetLongOptionDebug()
        self.opts.pmSetLongOptionHost()
        self.opts.pmSetLongOptionLocalPMDA()
        self.opts.pmSetLongOptionInterval()

        # custom options
        self.opts.pmSetLongOption("influxdb-address", 1, 'i', '',
                                  "InfluxDB HTTP/HTTPS address " +
                                  "(default \"" + self.influxdb_address +
                                  "\")")
        self.opts.pmSetLongOption("units", 1, 'u', '',
                                  "rescale units " +
                                  "(e.g. \"MB\", will omit incompatible units)")
        self.opts.pmSetLongOption("database", 1, 'd', '',
                                  "database for metric (default \"pcp\")")
        self.opts.pmSetLongOption("db-user", 1, 'U', '',
                                  "username for InfluxDB database")
        self.opts.pmSetLongOption("db-password", 1, 'P', '',
                                  "password for InfluxDB database")
        self.opts.pmSetLongOption("tag-string", 1, 'I', '',
                                  "string of tags to add to the metrics")
        self.opts.pmSetLongOptionHelp()

        # parse options
        self.context = pmapi.pmContext.fromOptions(self.opts, sys.argv)
        self.interval = self.opts.pmGetOptionInterval() or pmapi.timeval(60, 0)
        if self.unitsstr is not None:
            units = self.context.pmParseUnitsStr(self.unitsstr)
            (self.units, self.units_mult) = units
        self.metrics = []
        self.pmids = []
        self.descs = []
        metrics = self.opts.pmGetNonOptionsFromList(sys.argv)
        if metrics:
            for m in metrics:
                try:
                    self.context.pmTraversePMNS(m,
                                                self.handle_candidate_metric)
                except pmapi.pmErr as error:
                    sys.stderr.write("Excluding metric %s (%s)\n" %
                                     (m, str(error)))

            sys.stderr.flush()

        if len(self.metrics) == 0:
            sys.stderr.write("No acceptable metrics specified.\n")
            raise pmapi.pmUsageErr()

        # Report what we're about to do
        print("Relaying %d %smetric(s) to database %s with tags %s from %s "
              "to %s every %f s" %
              (len(self.metrics),
               "rescaled " if self.units else "",
               self.database,
               self.influxdb_tags,
               self.describe_source(),
               self.influxdb_address,
               self.interval))

        sys.stdout.flush()
コード例 #23
0
 def option(self, opt, optarg, index):
     """ Perform setup for an individual command line option """
     if opt in ['c']:
         self.plugins.append('cpu')
     elif opt in ['C']:
         self.cpulist = arg.split(',')
     elif opt in ['d']:
         self.plugins.append('disk')
     elif opt in ['D']:
         self.disklist = arg.split(',')
     elif opt in ['--filesystem']:
         self.plugins.append('fs')
     elif opt in ['g']:
         self.plugins.append('page')
     elif opt in ['i']:
         self.plugins.append('int')
     elif opt in ['I']:
         self.intlist = arg.split(',')
     elif opt in ['l']:
         self.plugins.append('load')
     elif opt in ['m']:
         self.plugins.append('mem')
     elif opt in ['n']:
         self.plugins.append('net')
     elif opt in ['N']:
         self.netlist = arg.split(',')
     elif opt in ['p']:
         self.plugins.append('proc')
     elif opt in ['r']:
         self.plugins.append('io')
     elif opt in ['s']:
         self.plugins.append('swap')
     elif opt in ['S']:
         self.swaplist = arg.split(',')
     elif opt in ['t']:
         self.plugins.append('time')
     elif opt in ['T']:
         self.plugins.append('epoch')
     elif opt in ['y']:
         self.plugins.append('sys')
     elif opt in ['a', 'all']:
         self.plugins += [ 'cpu', 'disk', 'net', 'page', 'sys' ]
     elif opt in ['v', 'vmstat']:
         self.plugins += [ 'proc', 'mem', 'page', 'disk', 'sys', 'cpu' ]
     elif opt in ['f', 'full']:
         self.full = True
     elif opt in ['all-plugins']:
         self.plugins += self.allplugins
     elif opt in ['bits']:
         self.bits = True
     elif opt in ['bw', 'black-on-white', 'blackonwhite']:
         self.blackonwhite = True
     elif opt in ['color']:
         self.color = True
         self.update = True
     elif opt in ['debug']:
         self.debug = self.debug + 1
     elif opt in ['float']:
         self.float = True
     elif opt in ['integer']:
         self.integer = True
     elif opt in ['list']:
         self.show_plugins()
         sys.exit(0)
     elif opt in ['nocolor']:
         self.color = False
     elif opt in ['noheaders']:
         self.header = False
     elif opt in ['noupdate']:
         self.update = False
     elif opt in ['o', 'output']:
         self.output = arg
     elif opt in ['pidfile']:
         self.pidfile = arg
     elif opt in ['profile']:
         self.profile = 'dstat_profile.log'
     elif opt in ['h']:
         self.usage()
     elif opt in ['V', 'version']:
         self.show_version()
         self.show_plugins()
         sys.exit(0)
     elif opt != '':
         self.plugins.append(opt)
     else:
         raise pmapi.pmUsageErr()
コード例 #24
0
    def __init__(self):
        """ Construct object, parse command line """
        self.context = None
        self.socket = None
        self.sample_count = 0
        self.opts = pmapi.pmOptions()
        self.opts.pmSetShortOptions("a:O:s:T:g:p:P:r:u:m:t:h:t:D:LV?")
        self.opts.pmSetShortUsage("[options] metricname ...")
        self.opts.pmSetOptionCallback(self.option)
        self.opts.pmSetOverrideCallback(self.option_override)
        self.opts.pmSetLongOptionText("""
Description: Periodically, relay raw values of all instances of a
given hierarchies of PCP metrics to a graphite/carbon server on the
network.""")
        self.opts.pmSetLongOptionHeader("Options")
        self.opts.pmSetLongOptionVersion()  # -V
        self.opts.pmSetLongOptionArchive()  # -a FILE
        self.opts.pmSetLongOptionOrigin()  # -O TIME
        self.opts.pmSetLongOptionSamples()  # -s NUMBER
        self.opts.pmSetLongOptionFinish()  # -T NUMBER
        self.opts.pmSetLongOptionDebug()  # -D stuff
        self.opts.pmSetLongOptionHost()  # -h HOST
        self.opts.pmSetLongOptionLocalPMDA()  # -L
        self.opts.pmSetLongOptionInterval()  # -t NUMBER
        self.opts.pmSetLongOption(
            "graphite-host", 1, 'g', '',
            "graphite server host " + "(default \"localhost\")")
        self.opts.pmSetLongOption("pickled-port", 1, 'p', '',
                                  "graphite pickled port (default 2004)")
        self.opts.pmSetLongOption("text-port", 1, 'P', '',
                                  "graphite plaintext port (usually 2003)")
        self.opts.pmSetLongOption(
            "units", 1, 'u', '',
            "rescale units " + "(e.g. \"MB\", will omit incompatible units)")
        self.opts.pmSetLongOption(
            "prefix", 1, 'm', '', "prefix for metric names (default \"pcp.\")")
        self.opts.pmSetLongOption("pickle-protocol", 1, 'r', 'PROTOCOL',
                                  "graphite pickle protocol (default 0)")
        self.opts.pmSetLongOptionHelp()
        self.graphite_host = "localhost"
        self.graphite_port = 2004
        self.pickle = True
        self.pickle_protocol = 0
        self.prefix = "pcp."
        self.unitsstr = None
        self.units = None  # pass verbatim by default
        self.units_mult = None  # pass verbatim by default

        # now actually parse
        self.context = pmapi.pmContext.fromOptions(self.opts, sys.argv)
        self.interval = self.opts.pmGetOptionInterval() or pmapi.timeval(60, 0)
        if self.unitsstr is not None:
            units = self.context.pmParseUnitsStr(self.unitsstr)
            (self.units, self.units_mult) = units
        self.metrics = []
        self.pmids = []
        self.descs = []
        metrics = self.opts.pmGetNonOptionsFromList(sys.argv)
        if metrics:
            for m in metrics:
                try:
                    self.context.pmTraversePMNS(m,
                                                self.handle_candidate_metric)
                except pmapi.pmErr as error:
                    sys.stderr.write("Excluding metric %s (%s)\n" %
                                     (m, str(error)))
            sys.stderr.flush()

        if len(self.metrics) == 0:
            sys.stderr.write("No acceptable metrics specified.\n")
            raise pmapi.pmUsageErr()

        # Report what we're about to do
        print(
            "Relaying %d %smetric(s) with prefix %s from %s "
            "in %s mode to %s:%d every %f s" %
            (len(self.metrics), "rescaled " if self.units else "", self.prefix,
             self.describe_source(), "pickled" if self.pickle else "text",
             self.graphite_host, self.graphite_port, self.interval))
        sys.stdout.flush()
コード例 #25
0
 def option(self, opt, optarg, index):
     """ Perform setup for an individual command line option """
     if index == self.daemonize and opt == '':
         self.daemonize = 1
         return
     if opt == 'K':
         if not self.speclocal or not self.speclocal.startswith("K:"):
             self.speclocal = "K:" + optarg
         else:
             self.speclocal = self.speclocal + "|" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'o':
         if optarg == OUTPUT_ARCHIVE:
             self.output = OUTPUT_ARCHIVE
         elif optarg == OUTPUT_CSV:
             self.output = OUTPUT_CSV
         elif optarg == OUTPUT_STDOUT:
             self.output = OUTPUT_STDOUT
         else:
             sys.stderr.write("Invalid output target %s specified.\n" %
                              optarg)
             sys.exit(1)
     elif opt == 'F':
         if os.path.exists(optarg + ".index"):
             sys.stderr.write("Archive %s already exists.\n" % optarg)
             sys.exit(1)
         if os.path.exists(optarg):
             sys.stderr.write("File %s already exists.\n" % optarg)
             sys.exit(1)
         self.outfile = optarg
     elif opt == 'e':
         self.derived = optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'U':
         self.unitinfo = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'p':
         self.timestamp = 1
     elif opt == 'd':
         self.delay = 1
     elif opt == 'r':
         self.type = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(
             optarg)
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'X':
         self.colxrow = optarg
     elif opt == 'w':
         try:
             self.width = int(optarg)
         except:
             sys.stderr.write(
                 "Error while parsing options: Integer expected.\n")
             sys.exit(1)
     elif opt == 'P':
         try:
             self.precision = int(optarg)
         except:
             sys.stderr.write(
                 "Error while parsing options: Integer expected.\n")
             sys.exit(1)
     elif opt == 'l':
         self.delimiter = optarg
     elif opt == 'k':
         self.extcsv = 1
     elif opt == 'x':
         self.extheader = 1
     elif opt == 'E':
         try:
             self.repeat_header = int(optarg)
         except:
             sys.stderr.write(
                 "Error while parsing options: Integer expected.\n")
             sys.exit(1)
     elif opt == 'f':
         self.timefmt = optarg
     elif opt == 'u':
         self.interpol = 0
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'y':
         self.time_scale = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #26
0
 def option(self, opt, optarg, index):
     """ Perform setup for individual command line option """
     if opt == 'daemonize':
         self.daemonize = 1
     elif opt == 'K':
         if not self.speclocal or not self.speclocal.startswith(";"):
             self.speclocal = ";" + optarg
         else:
             self.speclocal = self.speclocal + ";" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'e':
         if not self.derived or not self.derived.startswith(";"):
             self.derived = ";" + optarg
         else:
             self.derived = self.derived + ";" + optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'r':
         self.type = 1
     elif opt == 'R':
         self.type_prefer = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(optarg)
     elif opt == 'j':
         self.live_filter = 1
     elif opt == 'J':
         self.rank = optarg
     elif opt == '8':
         self.limit_filter = optarg
     elif opt == '9':
         self.limit_filter_force = optarg
     elif opt == 'n':
         self.invert_filter = 1
     elif opt == 'N':
         self.predicate = optarg
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'P':
         self.precision = optarg
     elif opt == '0':
         self.precision_force = optarg
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'Q':
         self.count_scale_force = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'B':
         self.space_scale_force = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'Y':
         self.time_scale_force = optarg
     elif opt == 'g':
         self.spark_server = optarg
     elif opt == 'p':
         self.spark_port = int(optarg)
     else:
         raise pmapi.pmUsageErr()
コード例 #27
0
ファイル: pmconfig.py プロジェクト: rbramwell/pcp
    def prepare_metrics(self):
        """ Construct and prepare the initial metrics set """
        metrics = self.util.opts.pmGetOperands()
        if not metrics:
            sys.stderr.write("No metrics specified.\n")
            raise pmapi.pmUsageErr()

        # Read config
        config = ConfigParser.SafeConfigParser()
        config.optionxform = str
        if self.util.config:
            config.read(self.util.config)

        # First read global metrics (if not disabled already)
        globmet = OrderedDict()
        if self.util.globals == 1:
            if config.has_section('global'):
                parsemet = OrderedDict()
                for key in config.options('global'):
                    if key in self.util.keys:
                        sys.stderr.write(
                            "No options allowed in [global] section.\n")
                        sys.exit(1)
                    self.parse_metric_info(parsemet, key,
                                           config.get('global', key))
                for metric in parsemet:
                    name = parsemet[metric][:1][0]
                    globmet[name] = parsemet[metric][1:]

        # Add command line and configuration file metricsets
        tempmet = OrderedDict()
        for metric in metrics:
            if metric.startswith(":"):
                tempmet[metric[1:]] = None
            else:
                spec, insts = self.parse_metric_spec_instances(metric)
                m = spec.split(",")
                m[2] = insts
                tempmet[m[0]] = m[1:]

        # Get config and set details for configuration file metricsets
        confmet = OrderedDict()
        for spec in tempmet:
            if tempmet[spec] is None:
                if config.has_section(spec):
                    parsemet = OrderedDict()
                    for key in config.options(spec):
                        if key not in self.util.keys:
                            self.parse_metric_info(parsemet, key,
                                                   config.get(spec, key))
                    for metric in parsemet:
                        name = parsemet[metric][:1][0]
                        confmet[name] = parsemet[metric][1:]
                    tempmet[spec] = confmet
                else:
                    raise IOError("Metricset definition '%s' not found." %
                                  metric)

        # Create the combined metrics set
        if self.util.globals == 1:
            for metric in globmet:
                self.util.metrics[metric] = globmet[metric]
        for metric in tempmet:
            if isinstance(tempmet[metric], list):
                self.util.metrics[metric] = tempmet[metric]
            else:
                if tempmet[metric]:
                    for m in tempmet[metric]:
                        self.util.metrics[m] = confmet[m]

        if not self.util.metrics:
            raise IOError("No metrics specified.")
コード例 #28
0
ファイル: pcp2graphite.py プロジェクト: marcliangma8/pcp
    def __init__(self):
        """ Construct object, parse command line """
        self.context = None
        self.opts = pmapi.pmOptions()
        self.opts.pmSetShortOptions("g:p:P:u:m:t:h:Lt:D:V?")  # must include common options
        self.opts.pmSetShortUsage("[options] metricname ...")
        self.opts.pmSetOptionCallback(self.option)
        self.opts.pmSetOverrideCallback(self.option_override)
        # hack to include some explanatory text
        self.opts.pmSetLongOptionHeader(
            """
Description: Periodically, relay raw values of all instances of a
given hierarchies of PCP metrics to a graphite/carbon server on the
network.

Options"""
        )
        self.opts.pmSetLongOptionVersion()  # -V
        # self.opts.pmSetLongOptionArchive() # -a FILE   -- not supported yet; need -S/etc. controls
        self.opts.pmSetLongOptionDebug()  # -D stuff
        self.opts.pmSetLongOptionHost()  # -h HOST
        # self.opts.pmSetLongOptionLocalPMDA() # -L
        self.opts.pmSetLongOptionInterval()  # -t NUMBER
        self.opts.pmSetLongOption("graphite-host", 1, "g", "", 'graphite server host (default "localhost")')
        self.opts.pmSetLongOption("pickled-port", 1, "p", "", "graphite pickled port (default 2004)")
        self.opts.pmSetLongOption("text-port", 1, "P", "", "graphite plaintext port (usually 2003)")
        self.opts.pmSetLongOption("units", 1, "u", "", 'rescale all metric units (e.g., "mbytes/5 sec")')
        self.opts.pmSetLongOption("prefix", 1, "m", "", 'prefix for metric names (default "pcp.")')
        self.opts.pmSetLongOptionHelp()
        self.graphite_host = "localhost"
        self.graphite_port = 2004
        self.pickle = True
        self.prefix = "pcp."
        self.unitsstr = None
        self.units = None  # pass verbatim by default
        self.units_mult = None  # pass verbatim by default

        # now actually parse
        self.context = pmapi.pmContext.fromOptions(self.opts, sys.argv)
        self.interval = self.opts.pmGetOptionInterval() or pmapi.timeval(60, 0)

        if self.unitsstr is not None:
            (self.units, self.units_mult) = self.context.pmParseUnitsStr(self.unitsstr)
        self.metrics = []
        self.pmids = []
        self.descs = []
        metrics = self.opts.pmNonOptionsFromList(sys.argv)
        if metrics:
            for m in metrics:
                try:
                    self.context.pmTraversePMNS(m, self.handle_candidate_metric)
                except pmapi.pmErr as error:
                    sys.stderr.write("Excluding metric %s (%s)\n" % (m, str(error)))
            sys.stderr.flush()

        if len(self.metrics) == 0:
            sys.stderr.write("No acceptable metrics specified.\n")
            raise pmapi.pmUsageErr()

        # Report what we're about to do
        print(
            "Relaying %d %smetric(s) with prefix %s "
            "in %s mode to %s:%d every %f s"
            % (
                len(self.metrics),
                "rescaled " if self.units else "",
                self.prefix,
                "pickled" if self.pickle else "text",
                self.graphite_host,
                self.graphite_port,
                self.interval,
            )
        )
        sys.stdout.flush()
コード例 #29
0
    def __init__(self):
        """ Construct object, parse command line """
        self.opts = pmapi.pmOptions()
        self.opts.pmSetShortOptions("a:O:s:T:g:i:u:m:t:h:t:D:LV?")
        self.opts.pmSetShortUsage("[options] metricname ...")
        self.opts.pmSetOptionCallback(self.option)
        self.opts.pmSetOverrideCallback(self.option_override)
        self.opts.pmSetLongOptionText("""
Description: Periodically, relay raw values of all instances of a
given hierarchies of PCP metrics to a elasticsearch/carbon server on the
network.""")
        self.opts.pmSetLongOptionHeader("Options")
        self.opts.pmSetLongOptionVersion()  # -V
        self.opts.pmSetLongOptionArchive()  # -a FILE
        self.opts.pmSetLongOptionOrigin()  # -O TIME
        self.opts.pmSetLongOptionSamples()  # -s NUMBER
        self.opts.pmSetLongOptionFinish()  # -T NUMBER
        self.opts.pmSetLongOptionDebug()  # -D stuff
        self.opts.pmSetLongOptionHost()  # -h HOST
        self.opts.pmSetLongOptionLocalPMDA()  # -L
        self.opts.pmSetLongOptionInterval()  # -t NUMBER
        self.opts.pmSetLongOption(
            "elasticsearch-host", 1, 'g', '', "elasticsearch server host " +
            "(default \"http://*****:*****@timestamp': {
                                                   'type': 'date'
                                               },
                                               'host-id': {
                                                   'type': 'string'
                                               }
                                           }
                                       }
                                   }
                               })

        # Report what we're about to do
        print("Relaying %d %smetric(s) with es_index %s from %s "
              "to %s every %f s" %
              (len(self.metrics),
               "rescaled " if self.units else "", self.es_index,
               self.describe_source(), self.elasticsearch_host, self.interval))
        sys.stdout.flush()
コード例 #30
0
 def option(self, opt, optarg, _index):
     """ Perform setup for individual command line option """
     if opt == 'daemonize':
         self.daemonize = 1
     elif opt == 'K':
         if not self.speclocal or not self.speclocal.startswith(";"):
             self.speclocal = ";" + optarg
         else:
             self.speclocal = self.speclocal + ";" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'e':
         if not self.derived or not self.derived.startswith(";"):
             self.derived = ";" + optarg
         else:
             self.derived = self.derived + ";" + optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'r':
         self.type = 1
     elif opt == 'R':
         self.type_prefer = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == '5':
         self.ignore_unknown = 1
     elif opt == '4':
         if optarg == 'ignore':
             self.names_change = 0
         elif optarg == 'abort':
             self.names_change = 1
         elif optarg == 'update':
             self.names_change = 2
         else:
             sys.stderr.write(
                 "Unknown names-change action '%s' specified.\n" % optarg)
             sys.exit(1)
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(
             optarg)
     elif opt == 'j':
         self.live_filter = 1
     elif opt == 'J':
         self.rank = optarg
     elif opt == '8':
         self.limit_filter = optarg
     elif opt == '9':
         self.limit_filter_force = optarg
     elif opt == 'n':
         self.invert_filter = 1
     elif opt == 'N':
         self.predicate = optarg
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'P':
         self.precision = optarg
     elif opt == '0':
         self.precision_force = optarg
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'Q':
         self.count_scale_force = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'B':
         self.space_scale_force = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'Y':
         self.time_scale_force = optarg
     elif opt == 'g':
         self.es_server = optarg
     elif opt == 'x':
         self.es_index = optarg
     elif opt == 'X':
         self.es_hostid = optarg
     elif opt == 'p':
         self.es_search_type = optarg
     else:
         raise pmapi.pmUsageErr()
コード例 #31
0
 def option(self, opt, optarg, _index):
     """ Perform setup for individual command line option """
     if opt == 'daemonize':
         self.daemonize = 1
     elif opt == 'K':
         if not self.speclocal or not self.speclocal.startswith(";"):
             self.speclocal = ";" + optarg
         else:
             self.speclocal = self.speclocal + ";" + optarg
     elif opt == 'c':
         self.config = optarg
     elif opt == 'C':
         self.check = 1
     elif opt == 'F':
         if os.path.exists(optarg):
             sys.stderr.write("File %s already exists.\n" % optarg)
             sys.exit(1)
         self.outfile = optarg
     elif opt == 'e':
         if not self.derived or not self.derived.startswith(";"):
             self.derived = ";" + optarg
         else:
             self.derived = self.derived + ";" + optarg
     elif opt == 'H':
         self.header = 0
     elif opt == 'G':
         self.globals = 0
     elif opt == 'r':
         self.type = 1
     elif opt == 'R':
         self.type_prefer = 1
     elif opt == 'I':
         self.ignore_incompat = 1
     elif opt == '5':
         self.ignore_unknown = 1
     elif opt == '4':
         if optarg == 'ignore':
             self.names_change = 0
         elif optarg == 'abort':
             self.names_change = 1
         else:
             raise pmapi.pmUsageErr()
     elif opt == 'i':
         self.instances = self.instances + self.pmconfig.parse_instances(
             optarg)
     elif opt == 'j':
         self.live_filter = 1
     elif opt == 'J':
         self.rank = optarg
     elif opt == '8':
         self.limit_filter = optarg
     elif opt == '9':
         self.limit_filter_force = optarg
     elif opt == 'n':
         self.invert_filter = 1
     elif opt == 'N':
         self.predicate = optarg
     elif opt == 'v':
         self.omit_flat = 1
     elif opt == 'P':
         self.precision = optarg
     elif opt == '0':
         self.precision_force = optarg
     elif opt == 'f':
         self.timefmt = optarg
     elif opt == 'q':
         self.count_scale = optarg
     elif opt == 'Q':
         self.count_scale_force = optarg
     elif opt == 'b':
         self.space_scale = optarg
     elif opt == 'B':
         self.space_scale_force = optarg
     elif opt == 'y':
         self.time_scale = optarg
     elif opt == 'Y':
         self.time_scale_force = optarg
     elif opt == 'x':
         self.extended = 1
     elif opt == 'X':
         self.everything = 1
     elif opt == 'E':
         self.exact_types = 1
     else:
         raise pmapi.pmUsageErr()