### Start Fake JSON Server Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md Starts a fake JSON server using json-server for testing purposes. It serves static files from './test/tmp/' and uses '/tmp/db.json' as its database, accessible on all interfaces. ```shell touch /tmp/db.json; json-server --host '0.0.0.0' --port 3001 --static ./test/tmp/ /tmp/db.json ``` -------------------------------- ### Kubernetes Proxy Command Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md Starts a Kubernetes proxy server. This command allows external access to the Kubernetes API, binding to all interfaces and accepting all hosts, while rejecting specific HTTP methods for security. ```shell kubectl proxy --address 0.0.0.0 --accept-hosts='.*' --reject-methods=POST,PUT,PATCH -v5 ``` -------------------------------- ### Kubernetes API Access via kubectl proxy Source: https://github.com/pgillich/grafana-tree-panel/blob/main/README.md Starts a local proxy to access the Kubernetes API from outside the cluster. It binds to all interfaces, accepts all hosts, and restricts methods to POST, PUT, PATCH operations. ```sh kubectl proxy --address 0.0.0.0 --accept-hosts='.*' --reject-methods=POST,PUT,PATCH -v5 ``` -------------------------------- ### Copy Plugin to Grafana Container and Restart Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md A sequence of shell commands to copy the built plugin files into a running Grafana container, clean up old files, and then restart the Grafana pod. It also verifies the plugin version. ```shell export GRAFANA_POD=$(kubectl get pod -n monitoring -l 'app.kubernetes.io/name=grafana' -o name | sed 's#^pod/##g'); kubectl exec -n monitoring ${GRAFANA_POD} -c grafana -- /bin/sh -c 'rm -rf /var/lib/grafana/plugins/pgillich-tree-panel'; kubectl cp ./dist -n monitoring -c grafana ${GRAFANA_POD}:/var/lib/grafana/plugins/pgillich-tree-panel; kubectl exec -n monitoring ${GRAFANA_POD} -c grafana -- /bin/sh -c 'rm -f /var/lib/grafana/plugins/pgillich-tree-panel/MANIFEST.txt'; kubectl exec -n monitoring ${GRAFANA_POD} -c grafana -- /bin/sh -c 'grep version /var/lib/grafana/plugins/pgillich-tree-panel/plugin.json'; ``` -------------------------------- ### Restart Grafana Container via kubectl Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md Executes a command within the Grafana container to list running processes and then sends a kill signal to the init process (PID 1), effectively restarting the container. ```shell kubectl exec -n monitoring ${GRAFANA_POD} -c grafana -- /bin/sh -c 'ps -ef; kill 1' ``` -------------------------------- ### Grafana Tree Panel Handlebars Template Syntax Source: https://github.com/pgillich/grafana-tree-panel/blob/main/README.md Supports Handlebars for more complex templating in panel options, using a `{{field}}`-style syntax. Enables advanced logic and data rendering within the panel. ```text Handlebars {{field}} ``` -------------------------------- ### Grafana Tree Panel Default Template Syntax Source: https://github.com/pgillich/grafana-tree-panel/blob/main/README.md Uses a simple `${field}`-style expression processor for templating panel options. Allows direct insertion of field values into the display. ```text ${statusPhase} ${namespace} ${appName} ${name} ${containerImage} ``` -------------------------------- ### Grafana Docker Compose Volume Mount Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md Configuration snippet for a docker-compose.yml file. It mounts the local './grafana/grafana-tree-panel/dist' directory to the Grafana container's plugin directory and allows unsigned plugins. ```yaml services: grafana: volumes: - ./grafana/grafana-tree-panel/dist:/var/lib/grafana/plugins/pgillich-tree-panel environment: - GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=pgillich-tree-panel ``` -------------------------------- ### Check Grafana Container Processes Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md Retrieves the Grafana pod name and then executes a command inside the container to list all running processes. This is used to verify if the Grafana container has restarted successfully. ```shell GRAFANA_POD=$(kubectl get pod -n monitoring -l 'app.kubernetes.io/name=grafana' -o name | sed 's#^pod/##g'); kubectl exec -n monitoring ${GRAFANA_POD} -c grafana -- /bin/sh -c 'ps -ef' ``` -------------------------------- ### Handlebars: Print Kubernetes Pod Column Data Source: https://github.com/pgillich/grafana-tree-panel/blob/main/README.md This snippet demonstrates the usage of the `printPodColumn` Handlebars helper, ported from Kubernetes, to display specific columns of Kubernetes Pod data. It allows dynamic access to fields like NAME, READY, STATUS, AGE, IP, and MESSAGE, enhancing pod visualization in Grafana. ```Handlebars {{printPodColumn rawPod "STATUS"}} {{namespace}} {{appName}} {{name}} {{containerImage}} {{printPodColumn rawPod "MESSAGE"}} ``` -------------------------------- ### Kubernetes API Data Transformation with JSONata Source: https://github.com/pgillich/grafana-tree-panel/blob/main/README.md Transforms Kubernetes API responses using JSONata, handling missing values and formatting data for display. It maps items, substitutes labels, counts containers, joins images, and converts states to strings. ```jsonata $map(items, function($v) {{"namespace": $v.metadata.namespace, "name": $v.metadata.name, "appName": $v.metadata.labels."app.kubernetes.io/name" ? $v.metadata.labels."app.kubernetes.io/name" : ($v.metadata.labels."app" ? $v.metadata.labels."app" : "-"), "statusPhase": $v.status.phase, "containerCount": $count($v.spec.containers), "containerImage": $join($v.spec.containers[*].image, " "), "containerState": $v.status.containerStatuses[*].state ? $string($v.status.containerStatuses[*].state) : "-"}}) ``` -------------------------------- ### Run Specific Test Case Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md Execute only a specific test case using Yarn. This is useful for debugging or focusing on a particular test scenario. ```shell yarn test --testNamePattern='simple data' ``` -------------------------------- ### Kubernetes Pod and ConfigMap Editing Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md Shell commands to identify a Grafana pod and then edit its ConfigMap. This is used to remove the plugin from Grafana's configuration, potentially for uninstallation or updates. ```shell GRAFANA_POD=$(kubectl get pod -n monitoring -l 'app.kubernetes.io/name=grafana' -o name | sed 's#^pod/##g'); kubectl edit cm -n monitoring prometheus-stack-grafana; ``` -------------------------------- ### Restart Grafana Docker Compose Service Source: https://github.com/pgillich/grafana-tree-panel/blob/main/CONTRIBUTING.md Stops, removes, and then recreates the Grafana service within a Docker Compose environment. This is typically used after making changes to the Grafana container configuration or volumes. ```shell docker-compose stop grafana && docker-compose rm -f grafana && docker-compose up -d grafana ``` -------------------------------- ### JSONata: Transform Pod Data for Grafana Source: https://github.com/pgillich/grafana-tree-panel/blob/main/README.md This JSONata expression is designed to map raw Kubernetes Pod data into a format suitable for Grafana. It extracts and transforms fields such as namespace, name, appName, statusPhase, container count, and container images, preparing them for templating engines like Handlebars. ```JSONata $map(items, function($v) {{"rawPod": $v, "namespace": $v.metadata.namespace, "name": $v.metadata.name, "appName": $v.metadata.labels."app.kubernetes.io/name" ? $v.metadata.labels."app.kubernetes.io/name" : ($v.metadata.labels."app" ? $v.metadata.labels."app" : "-"), "statusPhase": $v.status.phase, "containerCount": $count($v.spec.containers), "containerImage": $join($v.spec.containers[*].image, " "), "containerState": $v.status.containerStatuses[*].state ? $string($v.status.containerStatuses[*].state) : "-"}}) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.