Hi,
On 2016-07-01 03:09, Jamie Bainbridge wrote:
> On 17 June 2016 at 18:44, Marko Myllynen <myllynen@xxxxxxxxxx> wrote:
>>
>> Agreed, this on the TODO list already (see pcp.git/src/pmrep/TODO):
>>
>> - includedir config file support (?)
>>
>> There was also this item:
>>
>> - look for config in ./, ~/.pcp, ~/, /etc/pcp or so
>>
>> Do you think that would be helpful or should we just drop that item?
>
> I like the idea of cwd, user-specific config, then system-wide config.
>
> This allows users to easily have their own tools just work without
> having root access to modify the system-wide files.
Ok, how about the patch below?
---
src/pmrep/TODO | 1 -
src/pmrep/pmrep.1 | 16 ++++++++++------
src/pmrep/pmrep.conf.5 | 7 ++-----
src/pmrep/pmrep.py | 12 ++++++++----
4 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/pmrep/TODO b/src/pmrep/TODO
index 805be88..23f6cb4 100644
--- a/src/pmrep/TODO
+++ b/src/pmrep/TODO
@@ -11,7 +11,6 @@
- add JSON output support
- add XML output support (like sadf)
- add XLS output support (like sar2xls)
-- look for config in ./, ~/.pcp, ~/, /etc/pcp or so
- possibly add more command line switch sanity checking
- modularize code to allow creating custom output plugins
- (e.g. pcp2graphite type socket, top-like output, separate pcp2zabbix)
diff --git a/src/pmrep/pmrep.1 b/src/pmrep/pmrep.1
index 2e91f92..d6593d4 100644
--- a/src/pmrep/pmrep.1
+++ b/src/pmrep/pmrep.1
@@ -251,8 +251,12 @@ See also
Specify the
.I config
file to use.
-The default is
-.BR ./pmrep.conf .
+The default is the first found of:
+.BR ./pmrep.conf ,
+.BR $HOME/.pmrep.conf ,
+.BR $HOME/pcp/pmrep.conf ,
+and
+.BR $PCP_SYSCONF_DIR/pmrep/pmrep.conf .
See
.BR pmrep.conf (5).
Unlike with other options,
@@ -681,11 +685,11 @@ $ pmrep -o archive -F ./a -t 5s -T 5m ds389 xfs
kernel.all.cpu disk mem
.SH FILES
.PD 0
.TP 10
-.BI ./pmrep.conf
-Default configuration file.
+.BI pmrep.conf
+\fBpmrep\fR configuration file (see \fB-c\fR).
.TP 10
-.BI /etc/pcp/pmrep/pmrep.conf
-Example configuration file.
+.BI $PCP_SYSCONF_DIR/pmrep/pmrep.conf
+System provided configuration file.
.PD
.SH BUGS
No command line option can follow metrics.
diff --git a/src/pmrep/pmrep.conf.5 b/src/pmrep/pmrep.conf.5
index c4bbfa1..937ddce 100644
--- a/src/pmrep/pmrep.conf.5
+++ b/src/pmrep/pmrep.conf.5
@@ -465,11 +465,8 @@ pswitch.width = 8
.SH FILES
.PD 0
.TP 10
-.BI ./pmrep.conf
-Default configuration file.
-.TP 10
-.BI /etc/pcp/pmrep/pmrep.conf
-Example configuration file.
+.BI $PCP_SYSCONF_DIR/pmrep/pmrep.conf
+System provided configuration file.
.PD
.SH SEE ALSO
.BR PCPIntro (1),
diff --git a/src/pmrep/pmrep.py b/src/pmrep/pmrep.py
index bf817f5..15f852d 100755
--- a/src/pmrep/pmrep.py
+++ b/src/pmrep/pmrep.py
@@ -72,7 +72,7 @@ if sys.version_info[0] >= 3:
long = int
# Default config
-DEFAULT_CONFIG = "./pmrep.conf"
+DEFAULT_CONFIG = [ "./pmrep.conf", "$HOME/.pmrep.conf",
"$HOME/.pcp/pmrep.conf", "$PCP_SYSCONF_DIR/pmrep/pmrep.conf" ]
# Default field separators, config/time formats, missing/truncated values
CSVSEP = ","
@@ -368,7 +368,13 @@ class PMReporter(object):
def set_config_file(self):
""" Set configuration file """
- config = DEFAULT_CONFIG
+ config = DEFAULT_CONFIG[0]
+ for conf in DEFAULT_CONFIG:
+ conf = conf.replace("$HOME", os.getenv("HOME"))
+ conf = conf.replace("$PCP_SYSCONF_DIR",
os.getenv("PCP_SYSCONF_DIR"))
+ if os.path.isfile(conf) or os.access(conf, os.R_OK):
+ config = conf
+ break
# Possibly override the built-in default config file before
# parsing the rest of the command line options
@@ -415,8 +421,6 @@ class PMReporter(object):
def read_config(self):
""" Read options from configuration file """
- if self.config is None:
- return
config = ConfigParser.SafeConfigParser()
config.read(self.config)
if not config.has_section('options'):
Thanks,
--
Marko Myllynen
|