Skip to content

Instantly share code, notes, and snippets.

@tzz
Created March 19, 2019 21:37
Show Gist options
  • Save tzz/de12b2e188dea89cb0aafb18d1b121ad to your computer and use it in GitHub Desktop.
Save tzz/de12b2e188dea89cb0aafb18d1b121ad to your computer and use it in GitHub Desktop.
Chef inventory to Prometheus conversion example
#!/usr/bin/jq -Sf
def chef_fields:
# special field adjustments go here
.
;
.rows|
map(select(.name)) | sort_by(.name) |
map(chef_fields |
[
.automatic,
.automatic.dmi,
. # the current data
] | add |
{
labels:
{
kernel_release: .kernel.release,
os,
os_version,
platform,
platform_version,
platform_family,
},
targets: ["\(.name):9100"]
# remove all empty or null labels
} | delpaths([path(.labels[]| select(. == "" or . == null))])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment