def getindomdict(ctx, metric_id_array): """ build a list of dicts that contain the instance domain id to text mappings The nth list entry is the nth metric in the metric_id_array @throw MissingIndomException if the instance information is not available """ indomdict = [] for i in xrange(len(metric_id_array)): metric_desc = ctx.pmLookupDesc(metric_id_array[i]) if 4294967295 != pmapi.get_indom(metric_desc): try: ivals, inames = ctx.pmGetInDom(metric_desc) if ivals == None: indomdict.append({}) else: indomdict.append(dict(zip(ivals, inames))) except pmapi.pmErr as exp: if exp.args[0] == c_pmapi.PM_ERR_INDOM: indomdict.append({}) elif exp.args[0] == c_pmapi.PM_ERR_INDOM_LOG: return None else: raise exp else: indomdict.append({}) return indomdict
def getdescription(ctx, metric_id_array): """ return an array of the names of the instance domains for the requested metrics """ description = [] for i in xrange(len(metric_id_array)): metric_desc = ctx.pmLookupDesc(metric_id_array[i]) if 4294967295 != pmapi.get_indom(metric_desc): description.append(ctx.pmGetInDom(metric_desc)) return description
def processforpreproc(self, ctx, mdata, preproc): """ fetch the data from the archive, reformat as a python data structure and call the analytic process function """ preproc.hoststart(mdata.nodename) metric_id_array = self.getmetricstofetch(ctx, preproc) if len(metric_id_array) == 0: logging.debug("Skipping %s (%s)" % (type(preproc).__name__, preproc.name)) preproc.hostend() return mtypes = self.getmetrictypes(ctx, metric_id_array) done = False while not done: try: result = ctx.pmFetch(metric_id_array) description = [] for i in xrange(len(metric_id_array)): # TODO - make this more efficient and move to a function metric_desc = ctx.pmLookupDesc(metric_id_array[i]) if 4294967295 != pmapi.get_indom(metric_desc): ivals, inames = ctx.pmGetInDom(metric_desc) if ivals == None: self.logerror(mdata.nodename, preproc.name, "missing indoms") preproc.hostend() return description.append(dict(zip(ivals, inames))) if False == self.runpreproccall(preproc, result, mtypes, ctx, mdata, description): # A return value of false from process indicates the computation # failed and no more data should be sent. done = True ctx.pmFreeResult(result) except pmapi.pmErr as e: if e.args[0] == c_pmapi.PM_ERR_EOL: done = True elif e.args[0] == c_pmapi.PM_ERR_INDOM or e.args[0] == c_pmapi.PM_ERR_INDOM_LOG: self.logerror(mdata.nodename, preproc.name, e.message()) else: raise e preproc.status = "complete" preproc.hostend()