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()
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()
def connect(self): """ Establish a fetchgroup PMAPI context to archive, host or local, via environment passed in by pcp(1). The ss(1) command has many clashes with standard PCP arguments so this is the only supported invocation. Debug options (if any) are set for us by pcp(1). Return True or False if we fail to connect. """ # source pcp_host = os.getenv("PCP_HOST") pcp_archive = os.getenv("PCP_ARCHIVE") # time window pcp_origin = os.getenv("PCP_ORIGIN_TIME") pcp_start_time = os.getenv("PCP_START_TIME") pcp_align_time = os.getenv("PCP_ALIGN_TIME") pcp_timezone = os.getenv("PCP_TIMEZONE") pcp_hostzone = os.getenv("PCP_HOSTZONE") pcp_debug = os.getenv("PCP_DEBUG") if pcp_archive is not None: self.context_type = PM_CONTEXT_ARCHIVE if pcp_origin is None and pcp_start_time is None: pcp_origin = "-0" # end of archive self.source = pcp_archive else: self.context_type = PM_CONTEXT_HOST if pcp_host is not None: self.source = pcp_host else: self.source = "localhost" try: self.pmfg = pmapi.fetchgroup(self.context_type, self.source) self.context = self.pmfg.get_context() if pcp_archive: options = pmapi.pmOptions("a:A:O:S:D:zZ:") optargv = ["pcp-ss", pcp_archive] if pcp_debug: optargv.append("-D%s" % pcp_debug) if pcp_align_time: optargv.append("-A%s" % pcp_align_time) if pcp_timezone: optargv.append("-Z%s" % pcp_timezone) if pcp_hostzone: optargv.append("-z") if pcp_origin: optargv.append("-O%s" % pcp_origin) pmapi.pmContext.fromOptions(options, optargv) origin = options.pmGetOptionOrigin() self.context.pmSetMode(PM_MODE_INTERP, origin, 0) elif pcp_start_time: optargv.append("-S%s" % pcp_start_time) pmapi.pmContext.fromOptions(options, optargv) start = options.pmGetOptionStart() self.context.pmSetMode(PM_MODE_INTERP, start, 0) except pmapi.pmErr as error: sys.stderr.write("%s: %s '%s'\n" % (error.progname(), error.message(), self.source)) return False # check network.persocket metrics are available try: self.context.pmLookupName((pmns + ".filter")) except Exception: if self.context_type == PM_CONTEXT_HOST: msg = "on host %s.\nIs the 'sockets' PMDA installed and enabled? See pmdasockets(1)." % self.source else: msg = "in archive %s" % self.source print("Error: metrics for '%s' not found %s" % (pmns, msg)) return False return True