Manage Advisor with the CLI
You can use gcx, the Grafana CLI, to manage Advisor checks and checktypes as resources. To install and configure it, refer to the Grafana CLI documentation (opens in new tab).
Before you begin
- Grafana permissions: The
Adminrole. - Tools:
gcx, configured for your Grafana instance, andjq(opens in new tab) for the JSON examples.
Get the list of checks
To get the list of checks, run:
gcx resources get checks -o wide
For a more detailed view of the elements checked and failing, inspect the JSON output:
gcx resources get checks -o json | jq -r '
["TYPE","CHECKED","FAILURES"],
(
[.items[] | {
type: .metadata.labels["advisor.grafana.app/type"],
ts: .metadata.creationTimestamp,
count: (.status.report.count // 0),
failures: ((.status.report.failures // []) | length)
}]
| group_by(.type)
| map(sort_by(.ts) | last)
| sort_by(.type)
| .[]
| [.type, (.count | tostring), (.failures | tostring)]
)
| @tsv
' | column -t -s $'\t'
Get the list of check types
To get the list of check types, run:
gcx resources get checktypes -o wide
Show all failures across every check type
To see all failures in your instance, run:
gcx resources get checks -o json | jq -r '
["SEVERITY","ITEM","RULE","TYPE"],
(
[.items[] | {
type: .metadata.labels["advisor.grafana.app/type"],
ts: .metadata.creationTimestamp,
failures: (.status.report.failures // [])
}]
| group_by(.type)
| map(sort_by(.ts) | last)
| map(select((.failures | length) > 0))
| .[]
| .type as $t
| .failures[]
| [.severity, .item, .stepID, $t]
)
| @tsv
' | column -t -s $'\t'
Run checks for a type
To run the checks for a specific type, create the check resource and push it:
mkdir -p resources/Check/
echo '{
"kind":"Check",
"metadata":{
"name":"check-manual",
"labels":{"advisor.grafana.app/type":"<CHECK_TYPE>"},
"namespace":"<NAMESPACE>"
},
"apiVersion":"advisor.grafana.app/v0alpha1",
"spec":{"data":{}},
"status":{
"report":{
"count":0,
"failures":[]
}
}
}' > resources/Check/check-manual.json
gcx push checks/check-manual
Replace the following placeholders:
<CHECK_TYPE>: The check type to run, for exampledatasource.<NAMESPACE>: The namespace of your Grafana instance, ordefaultfor self-managed instances.
Wait for the check to run, then read the results:
gcx resources get checks/check-manual -o json | jq '.status.report'
Get plugins that need an update
To identify the plugins that need an update, run:
gcx resources get checks -o json | jq -r '
["PLUGIN","SEVERITY","PLUGIN PATH"],
(
[.items[] | select(.metadata.labels["advisor.grafana.app/type"] == "plugin")]
| sort_by(.metadata.creationTimestamp) | last
| .status.report.failures[]?
| select(.stepID == "update")
| [.item, .severity, (.links[0].url // "-")]
)
| @tsv
' | column -t -s $'\t'
Find unhealthy data sources
To look for unhealthy data sources, run:
gcx resources get checks -o json | jq -r '
["DATASOURCE","SEVERITY","DATASOURCE PATH"],
(
[.items[] | select(.metadata.labels["advisor.grafana.app/type"] == "datasource")]
| sort_by(.metadata.creationTimestamp) | last
| .status.report.failures[]?
| select(.stepID == "health-check")
| [.item, .severity, (.links[0].url // "-")]
)
| @tsv
' | column -t -s $'\t'