diff --git a/src/pmatop/pmatop.py b/src/pmatop/pmatop.py index 057bacc..ee11432 100755 --- a/src/pmatop/pmatop.py +++ b/src/pmatop/pmatop.py @@ -631,7 +631,7 @@ def main (stdscr_p): return "Cannot open PCP archive: " + archive else: if host == "": - host = "localhost" + host = "local:" try: pmc = pmapi.pmContext(target=host) except pmapi.pmErr, e: diff --git a/src/pmcollectl/pmcollectl.py b/src/pmcollectl/pmcollectl.py index f87241e..38eed95 100755 --- a/src/pmcollectl/pmcollectl.py +++ b/src/pmcollectl/pmcollectl.py @@ -604,7 +604,7 @@ if __name__ == '__main__': sys.exit(1) else: if host == "": - host = "localhost" + host = "local:" try: pm = pmapi.pmContext(target=host) except pmapi.pmErr, e: @@ -665,8 +665,6 @@ if __name__ == '__main__': print host = pm.pmGetContextHostName() - if host == "localhost": - host = os.uname()[1] try: i_samples = 0 diff --git a/src/python/pcp/pmapi.py b/src/python/pcp/pmapi.py index 2f8693a..c631c44 100644 --- a/src/python/pcp/pmapi.py +++ b/src/python/pcp/pmapi.py @@ -32,7 +32,7 @@ import cpmapi as c_api # Create a pcp class - context = pmapi.pmContext(c_api.PM_CONTEXT_HOST, "localhost") + context = pmapi.pmContext(c_api.PM_CONTEXT_HOST, "local:") # Get ids for number cpus and load metrics metric_ids = context.pmLookupName(("hinv.ncpu","kernel.all.load")) @@ -625,7 +625,7 @@ ctypes.pythonapi.PyFile_AsFile.argtypes = [ctypes.py_object] class pmContext(object): """Defines a metrics source context (e.g. host, archive, etc) to operate on - pmContext(c_api.PM_CONTEXT_HOST,"localhost") + pmContext(c_api.PM_CONTEXT_HOST,"local:") pmContext(c_api.PM_CONTEXT_ARCHIVE,"FILENAME") This object defines a PMAPI context, and its methods wrap calls to PMAPI @@ -666,7 +666,7 @@ class pmContext(object): ## # overloads - def __init__(self, typed = c_api.PM_CONTEXT_HOST, target = "localhost"): + def __init__(self, typed = c_api.PM_CONTEXT_HOST, target = "local:"): self._type = typed # the context type self._target = target # the context target self._ctx = LIBPCP.pmNewContext(typed, target) # the context handle @@ -1092,18 +1092,19 @@ class pmContext(object): raise pmErr, status return status - def pmGetContextHostName( self ): + def pmGetContextHostName(self): """PMAPI - Lookup the hostname for the given context Unlike the underlying PMAPI function, this method takes no parameter. - This method simply returns the name of the context belonging to its - pmContext instance object. + This method simply returns the hostname for the context belonging to + its pmContext instance object. "hostname" = pmGetContextHostName() """ - status = LIBPCP.pmGetContextHostName(self.ctx) - if status < 0: - raise pmErr, status + hp = c_char_p() + hp = LIBPCP.pmGetContextHostName(self.ctx) + hostname = hp + LIBC.free(hp) return status ##