If I understand correctly in order to fetch metrics from PMAPI one first needs to create a new context and then use the context ID in query URLs. Is there a way to workaround this, ie. by having a static context with predefined ID?
I am asking this question, because I want to monitor my CentOS 7 servers with Prometheus. The version of the PCP suite on CentOS 7 is (at most) 4.3. I was able to install all the packages and have pmwebd running. I can connect Grafana to plot live metrics from target hosts, but I also want to make active monitoring checks with Prometheus. In Prometheus config file I have this job defined as:
- job_name: 'pcp'
file_sd_configs:
- files: ['hosts/*.yml']
metrics_path: '/pmapi/399165479/metrics'
params:
target: ['kernel', 'mem', 'disk', 'network', 'proc']
where 399165479 is the context number that I got from:
> wget localhost:44323/pmapi/context?hostname=localhost
So getting the context number and inserting it into the config file was a manual process suitable for the sandbox setup, but not feasible in production, because it would be difficult to automate.
Any advice on this issue (other than PCP upgrade to v.5) will be greatly appreciated.
Apparently it is possible to set a static context number by using --context
command line parameter for pmwebd. It must be used together with the -L
parameter. To enable these settings in the daemon mode on CentOS 7 the following line needs to be added to /etc/pcp/pmwebd/pmwebd.options
:
OPTIONS="$OPTIONS -L --context=1"
Any integer other than 1 can be used as well. After systemctl restart pmwebd
all queries can be sent to the /pmapi/1/metrics
endpoint, so in Prometheus config the scrape definition can look like this:
- job_name: 'pcp'
file_sd_configs:
- files: ['hosts/*.yml']
metrics_path: '/pmapi/1/metrics'
params:
target: ['kernel', 'mem', 'disk', 'network', 'proc']