Skip to content

Commit 08b03ab

Browse files
committed
docs: use JMESPath extensions for remaining jq conversions
Leverage redisctl's extended JMESPath functions to convert additional jq examples that require advanced features: - group_by() for grouping arrays by field value - divide()/multiply() for arithmetic operations - sprintf() for formatted string output - has() for key existence checks - join() for array-to-string conversion Remaining jq usage is limited to: - @csv output formatting (no JMESPath equivalent) - Pretty-printing raw JSON (jq .)
1 parent 6cd28a4 commit 08b03ab

File tree

3 files changed

+48
-43
lines changed

3 files changed

+48
-43
lines changed

docs/src/cookbook/enterprise/node-management.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,16 @@ redisctl enterprise node get --node-id 1 -o json -q '{
149149
echo "Node Health Report"
150150
echo "=================="
151151

152-
# Using jq for complex string formatting
153-
redisctl enterprise node list -o json | jq -r '
154-
.[] |
155-
"Node \(.uid): \(.status) - CPU: \(.cpu_idle)% idle, " +
156-
"Memory: \((.used_memory / .total_memory * 100 | floor))% used, " +
157-
"Shards: \(.shard_count)"
158-
'
159-
160-
# Alternative: Use JMESPath for structured output
152+
# Using JMESPath sprintf() for formatted string output
153+
redisctl enterprise node list -q '
154+
[].sprintf(
155+
`"Node %s: %s - CPU: %.0f%% idle, Memory: %.0f%% used, Shards: %d"`,
156+
uid, status, cpu_idle,
157+
multiply(divide(used_memory, total_memory), `100`),
158+
shard_count
159+
)' --raw
160+
161+
# Alternative: Use JMESPath for structured table output
161162
redisctl enterprise node list -q '[].{node: uid, status: status, cpu_idle: cpu_idle, shards: shard_count}' -o table
162163
```
163164

docs/src/enterprise/advanced/jsonschema.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,17 @@ echo "$PAYLOAD" | jq --argjson schema "$SCHEMA" '
182182
Convert to OpenAPI specification:
183183

184184
```bash
185-
# Extract and format for OpenAPI
186-
redisctl enterprise jsonschema get -o json | jq '{
187-
openapi: "3.0.0",
185+
# Extract and format for OpenAPI using JMESPath
186+
redisctl enterprise jsonschema get -q '{
187+
openapi: `"3.0.0"`,
188188
info: {
189-
title: "Redis Enterprise API",
190-
version: .version
189+
title: `"Redis Enterprise API"`,
190+
version: version
191191
},
192192
components: {
193-
schemas: .definitions
193+
schemas: definitions
194194
},
195-
paths: .paths
195+
paths: paths
196196
}' > openapi.json
197197
```
198198

@@ -244,14 +244,14 @@ curl -k -u "$REDIS_ENTERPRISE_USER:$REDIS_ENTERPRISE_PASSWORD" \
244244
Validate that the schema is well-formed:
245245

246246
```bash
247-
# Check if valid JSON (using jq for JSON validation)
248-
redisctl enterprise jsonschema get | jq empty && echo "Valid JSON"
247+
# Check if valid JSON - redisctl will error if invalid
248+
redisctl enterprise jsonschema get -q 'length(@)' > /dev/null && echo "Valid JSON"
249249

250-
# Validate schema structure (jq for boolean expressions)
251-
redisctl enterprise jsonschema get | jq 'has("definitions") and has("$schema")'
250+
# Validate schema structure using JMESPath has() function
251+
redisctl enterprise jsonschema get -q 'has(@, `"definitions"`) && has(@, `"$schema"`)'
252252

253-
# Check for required sections
254-
redisctl enterprise jsonschema get -q '[has("definitions"), has("properties"), has("paths")] | all'
253+
# Check for required sections using has() function
254+
redisctl enterprise jsonschema get -q '[has(@, `"definitions"`), has(@, `"properties"`), has(@, `"paths"`)] | all_expr(@, &@)'
255255
```
256256

257257
## Related Commands

docs/src/enterprise/monitoring/usage-report.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,16 @@ for team in team-a team-b team-c; do
204204
-o table
205205
done
206206

207-
# Calculate team memory usage
208-
redisctl enterprise usage-report get -q 'databases[].{
209-
team: split(name, `-`)[0],
210-
memory_mb: memory_mb
211-
}' | jq -s 'group_by(.team) | map({
212-
team: .[0].team,
213-
total_memory_mb: map(.memory_mb) | add,
214-
database_count: length
215-
})'
207+
# Calculate team memory usage using JMESPath extensions
208+
# group_by and sum are available as extended functions
209+
redisctl enterprise usage-report get -q '
210+
group_by(databases[].{team: split(name, `-`)[0], memory_mb: memory_mb}, `"team"`)
211+
| items(@)
212+
| [*].{
213+
team: [0],
214+
total_memory_mb: sum([1][].memory_mb),
215+
database_count: length([1])
216+
}'
216217
```
217218

218219
## Export Formats
@@ -256,15 +257,16 @@ gdrive upload /tmp/usage.csv
256257
Send usage metrics to monitoring systems:
257258

258259
```bash
259-
# Prometheus metrics format
260-
redisctl enterprise usage-report get -o json | jq -r '
261-
"redis_cluster_databases \(.usage.total_databases)",
262-
"redis_cluster_shards \(.usage.total_shards)",
263-
"redis_cluster_memory_gb \(.usage.total_memory_gb)",
264-
"redis_cluster_nodes \(.usage.total_nodes)",
265-
"redis_license_shards_limit \(.license.shards_limit)",
266-
"redis_license_memory_limit_gb \(.license.memory_limit_gb)"
267-
' | curl -X POST http://pushgateway:9091/metrics/job/redis-usage --data-binary @-
260+
# Prometheus metrics format using JMESPath sprintf()
261+
redisctl enterprise usage-report get -q '
262+
join(`"\n"`, [
263+
sprintf(`"redis_cluster_databases %d"`, usage.total_databases),
264+
sprintf(`"redis_cluster_shards %d"`, usage.total_shards),
265+
sprintf(`"redis_cluster_memory_gb %.2f"`, usage.total_memory_gb),
266+
sprintf(`"redis_cluster_nodes %d"`, usage.total_nodes),
267+
sprintf(`"redis_license_shards_limit %d"`, license.shards_limit),
268+
sprintf(`"redis_license_memory_limit_gb %.2f"`, license.memory_limit_gb)
269+
])' --raw | curl -X POST http://pushgateway:9091/metrics/job/redis-usage --data-binary @-
268270

269271
# Datadog metrics
270272
redisctl enterprise usage-report get -o json | \
@@ -288,9 +290,11 @@ Create tickets for capacity warnings:
288290
#!/bin/bash
289291
# Check usage and create tickets
290292

291-
USAGE=$(redisctl enterprise usage-report get -o json)
292-
SHARD_PCT=$(echo $USAGE | jq '.usage.total_shards / .license.shards_limit * 100')
293-
MEMORY_PCT=$(echo $USAGE | jq '.usage.total_memory_gb / .license.memory_limit_gb * 100')
293+
# Use JMESPath divide() and multiply() for percentage calculations
294+
SHARD_PCT=$(redisctl enterprise usage-report get \
295+
-q 'multiply(divide(usage.total_shards, license.shards_limit), `100`)' --raw)
296+
MEMORY_PCT=$(redisctl enterprise usage-report get \
297+
-q 'multiply(divide(usage.total_memory_gb, license.memory_limit_gb), `100`)' --raw)
294298

295299
if (( $(echo "$SHARD_PCT > 80" | bc -l) )); then
296300
echo "High shard usage: ${SHARD_PCT}%" | \

0 commit comments

Comments
 (0)