@@ -133,7 +133,7 @@ Defaults to `undef`.
133133## Usage
134134
135135
136- ### Grepping Metrics
136+ ### Searching Metrics
137137
138138Metrics are formatted as a JSON hash on one line.
139139In order to convert the metric files into a multi-line format, they can be processed with ` python -m json.tool ` as per below.
@@ -143,40 +143,68 @@ cd /opt/puppetlabs/puppet-metrics-collector
143143for i in < service_name> /primary.example.com/* .json; do echo " $( python -m json.tool < $i ) " > $i ; done
144144```
145145
146- You can search for useful information by performing a ` grep ` , run from inside the directory containing the metrics.
146+ You can search for useful information by performing a ` grep ` , run from inside the directory containing the metrics
147147
148148``` bash
149149cd /opt/puppetlabs/puppet-metrics-collector
150- grep < metric_name> < service_name> /primary.example.com/* .json
150+ grep -oP ' "<metric_name>,*?,' < service_name> /primary.example.com/* .json
151+ ```
152+
153+ or JQ if available
154+ ``` bash
155+ cd /opt/puppetlabs/puppet-metrics-collector
156+ jq ' .. |."<metric_name>"? | select(. != null)| input_filename , .' -- < service_name> /primary.example.com/* .json
151157```
152158
153159Since the metrics are archived once per day, you can only search metrics for the current day.
154160To search older metrics, decompress the archived files into a subdirectory of ` /tmp ` and run your search from inside that directory.
155161
156- #### Grepping Puppetserver Metrics
162+ #### Searching Puppetserver Metrics
157163
158164Example:
159165
160166``` bash
161- grep average-free-jrubies puppetserver/primary.example.com/* .json
167+ grep -oP ' "average-free-jrubies.*?,' puppetserver/primary.example.com/* .json
168+
169+ puppetserver/primary.example.com/20190404T170501Z.json:" average-free-jrubies" :0.9950009285369501,
170+ puppetserver/primary.example.com/20190404T171001Z.json:" average-free-jrubies" :0.9999444653324225,
171+ puppetserver/primary.example.com/20190404T171502Z.json:" average-free-jrubies" :0.9999993830655706,
172+ ```
162173
163- puppetserver/primary.example.com/20190404T170501Z.json: " average-free-jrubies" : 0.9950009285369501,
164- puppetserver/primary.example.com/20190404T171001Z.json: " average-free-jrubies" : 0.9999444653324225,
165- puppetserver/primary.example.com/20190404T171502Z.json: " average-free-jrubies" : 0.9999993830655706,
174+ ``` bash
175+ jq ' .. |."average-free-jrubies"? | select(. != null)| input_filename , .' -- puppetserver/primary.example.com/* .json
176+
177+ " puppetserver/primary.example.com/20190404T170501Z.json"
178+ 0.9950009285369501
179+ " puppetserver/primary.example.com/20190404T171001Z.json"
180+ 0.9999444653324225,
181+ " puppetserver/primary.example.com/20190404T171502Z.json"
182+ 0.9999993830655706,
166183```
167184
168- #### Grepping PuppetDB Metrics
185+ #### Searching PuppetDB Metrics
169186
170187Example:
171188
172189``` bash
173- grep queue_depth puppetdb/primary.example.com/* .json
190+ grep -oP ' " queue_depth.*?, ' puppetdb/primary.example.com/* .json
174191
175192puppetdb/primary.example.com/20190404T170501Z.json: " queue_depth" : 0,
176193puppetdb/primary.example.com/20190404T171001Z.json: " queue_depth" : 0,
177194puppetdb/primary.example.com/20190404T171502Z.json: " queue_depth" : 0,
178195```
179196
197+ ``` bash
198+ jq ' .. |."queue_depth "? | select(. != null)| input_filename , .' -- puppetdb/primary.example.com/* .json
199+
200+ " puppetdb/primary.example.com/20190404T170501Z.json"
201+ 0
202+ " puppetdb/primary.example.com/20190404T171001Z.json"
203+ 0
204+ " puppetdb/primary.example.com/20190404T171502Z.json"
205+ 0
206+ ```
207+
180208### Sharing Metrics Data
181209
182210When working with Support, you may be asked for an archive of collected metrics data.
0 commit comments