pcp
[Top] [All Lists]

Re: [pcp] Shouldn't pmrep use the default config file?

To: Jamie Bainbridge <jamie.bainbridge@xxxxxxxxx>
Subject: Re: [pcp] Shouldn't pmrep use the default config file?
From: Marko Myllynen <myllynen@xxxxxxxxxx>
Date: Thu, 21 Jul 2016 16:42:16 +0300
Cc: pcp@xxxxxxxxxxx
Delivered-to: pcp@xxxxxxxxxxx
In-reply-to: <577D24E9.1090900@xxxxxxxxxx>
Organization: Red Hat
References: <CAAvyFNhgfmuLhAHfA3d1rUuiPE791=04QXQHeLy9Dq4F=_756w@xxxxxxxxxxxxxx> <CAAvyFNh7hKSQ0gYD1+kjwQr116xWQGpz=3zqp4gLEZk8jm9T4g@xxxxxxxxxxxxxx> <5763B86B.1070506@xxxxxxxxxx> <CAAvyFNj48Ci13OvsmoqjoE7d5AQb2+uHObtE5DtOtzrSASwi0A@xxxxxxxxxxxxxx> <577D24E9.1090900@xxxxxxxxxx>
Reply-to: Marko Myllynen <myllynen@xxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2
Hi Jamie,

Did you have a chance to check this one out? I think we could apply this
patch unless you have any concerns.

Thanks,

On 2016-07-06 18:34, Marko Myllynen wrote:
> 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

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