pcp
[Top] [All Lists]

pmrep: handle known/duplicate derived metrics

To: pcp developers <pcp@xxxxxxxxxxx>
Subject: pmrep: handle known/duplicate derived metrics
From: Marko Myllynen <myllynen@xxxxxxxxxx>
Date: Mon, 7 Dec 2015 08:03:50 +0200
Delivered-to: pcp@xxxxxxxxxxx
Organization: Red Hat
Reply-to: myllynen@xxxxxxxxxx
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
---
 src/pmrep/TODO     | 1 -
 src/pmrep/pmrep.py | 9 +++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/pmrep/TODO b/src/pmrep/TODO
index ea9c9d2..af9d37a 100644
--- a/src/pmrep/TODO
+++ b/src/pmrep/TODO
@@ -9,7 +9,6 @@
 -  switch using logimport instead pmgui for archive writing (no folios)
 -  -X to support pmdumptext -X like output (or shorten inst names if needed)
 -  bash/zsh completion with short help (allow description for sets?)
--  handle derived metrics with archives
 -  enable counter wrap logic
 -  containers support
 -  verify CSV format
diff --git a/src/pmrep/pmrep.py b/src/pmrep/pmrep.py
index 8d83cd9..a9ae8ea 100644
--- a/src/pmrep/pmrep.py
+++ b/src/pmrep/pmrep.py
@@ -61,7 +61,7 @@ import os
 import re
 
 from pcp import pmapi, pmgui, pmi
-from cpmapi import PM_CONTEXT_ARCHIVE, PM_CONTEXT_HOST, PM_CONTEXT_LOCAL, 
PM_MODE_FORW, PM_MODE_INTERP, PM_ERR_TYPE, PM_ERR_EOL, PM_IN_NULL, 
PM_SEM_COUNTER, PM_TIME_MSEC, PM_TIME_SEC, PM_XTB_SET
+from cpmapi import PM_CONTEXT_ARCHIVE, PM_CONTEXT_HOST, PM_CONTEXT_LOCAL, 
PM_MODE_FORW, PM_MODE_INTERP, PM_ERR_TYPE, PM_ERR_EOL, PM_ERR_NAME, PM_IN_NULL, 
PM_SEM_COUNTER, PM_TIME_MSEC, PM_TIME_SEC, PM_XTB_SET
 from cpmapi import PM_TYPE_32, PM_TYPE_U32, PM_TYPE_64, PM_TYPE_U64, 
PM_TYPE_FLOAT, PM_TYPE_DOUBLE, PM_TYPE_STRING
 from cpmgui import PM_REC_ON, PM_REC_OFF, PM_REC_SETARG
 
@@ -618,7 +618,12 @@ class PMReporter(object):
                     err = ""
                     try:
                         name, expr = definition.split("=")
-                        self.context.pmRegisterDerived(name.strip(), 
expr.strip())
+                        self.context.pmLookupName(name.strip())
+                    except pmapi.pmErr as error:
+                        if error.args[0] == PM_ERR_NAME:
+                            self.context.pmRegisterDerived(name.strip(), 
expr.strip())
+                            continue
+                        err = error.message()
                     except ValueError as error:
                         err = "Invalid syntax (expected metric=expression)"
                     except Exception as error:

Thanks,

-- 
Marko Myllynen

<Prev in Thread] Current Thread [Next in Thread>