Grafana templates for Prometheus - grafana

I am trying to update the node-exporter-full Grafana dashboard with some of our internal labels as templates. We have labels for "pod" and "servertype" which can be used to get a subset of "nodes" to list at the top of the dashboard.
I can add "pod" like:
label_values(pod)
Then I can reference "pod" in the node query as follows:
label_values(node_boot_time{job="clients",pod="$pod"}, instance)
This works. If I want to add servertype in the middle how would I pull a list of "servertype" based on "pod" which is selected?
I already know the "node" can be filtered with:
label_values(node_boot_time{job="clients",pod="$pod"},servertype="$servertype", instance)

Answer was pretty simple once I reread the documentation. Using "up" function currently and it is working fine but there may be a better solution.

node_boot_time has been changed to node_boot_time_seconds
Refer to this link to get all the name changes since prometheus 0.16.0
https://github.com/prometheus/node_exporter/issues/830

Related

How can I find an existing node and then link it to another node?

Would something like this work?
Basically what I am trying to do is to link an edge to a node but in return linking the node to an existing node but I need to query the node to find it to link it.
here -[people_link(id="123")]-> node::person(name==w);
This should work in version 1.4 of Jaseci. Try somethign like
here +[people_link(id="123")]+> node::person(name==w);

Conftest Policy for Kubernetes manifests for checking that images come from a specific registry

I'm using conftest for validating policies on Kubernetes manifests.
Below policy validates that images in StatefulSet manifests have to come from specific registry reg_url
package main
deny[msg] {
input.kind == "StatefulSet"
not regex.match("[reg_url]/.+", input.spec.template.spec.initContainers[0].image)
msg := "images come from artifactory"
}
Is there a way to enforce such policy for all kubernetes resources that have image field somewhere in their description? This may be useful for policy validation on all helm chart manifests, for instance.
I'm looking for something like:
package main
deny[msg] {
input.kind == "*" // all resources
not regex.match("[reg_url]/.+", input.*.image) // any nested image field
msg := "images come from artifactory"
}
You could do this using something like the walk built-in function. However, I would recommend against it, because:
You'd need to scan every attribute of every request/resource (expensive).
You can't know for sure that e.g. "image" means the same thing across all current and future resouce manifests, including CRDs.
I'd probably just stick with checking for a match of resource kind here, and include any resource type known to have an image attribute with a shared meaning.

Can't Change Metric Alias in Grafana Using a Zabbix Plugin

I want to show multiple CPU Usage from different hosts in one graph but they all end up with the same name and I can't tell which line represents which host:
here's the snapshot.
I'm using Grafana 5.2.4 with a Zabbix plugin 3.9.1. My Zabbix version is 3.0.12.
I've tried overriding legends in Grafana but there's no such option. Also, Zabbix plugin doesn't allow connecting directly to DB, so I can't use the ALIAS BY option either. I've tried using macros in Zabbix to include host name in item name, but {HOST.NAME} just ends up as is in the item name (and not replaced by the actual values).
Any solutions will be hugely appreciated.
You should use the templating feature of the Zabbix Grafana plugin,see the attached screens and the following description for a working example.
I have a Routers Zabbix Hostgroup, so I define a Router Grafana variable to match the hosts (Routers.*), see the first screenshot.
Enable both multi-value and Select All
Then in the metrics configuration use a single metric configured this way:
Group: Routers
Host: $Router (mind the $, the variable will be expanded in real time accordingly to the selection)
Item: the common item name (i.e.: ICMP Response Time)
And you will get something similar to the second screenshot, with a host picker on top and multiple selections.
So There's a "Functions" button below each metric when we are configuring and editing our graph. There's an "Alias" option and when you hover over it you see more options. If you click on "setAlias", you can define an alias for each metric.
Since this solution requires setting each alias individually, I recommend the solution that was suggested by Simone Zabberoni above. but this one is also worth knowing since it might come in handy at times.

Grafana templating merge variables

I'm looking for a solution to merge two templating variables in grafana(data source: prometheus).
My use case is:
I've my first variable:
deployment = label_values(kube_deployment_labels{namespace="$namespace"},deployment)
and the second one:
statefulset = label_values(kube_statefulset_labels{namespace="$namespace"},statefulset)
What I'm looking for is a only one dropdown menu(selector) because in my dashboard I wan't to be able to select a deployment or a statefulset but not both at the same time.
I've tried at the different side:
1) With prometheus by using a query like this:
kube_deployment_labels{namespace="$namespace"} or kube_statefulset_labels{namespace="$namespace"}
But in this case I'm not able to extract the labels(could be "deployment" or statefulset")
2) It seems not possible to perform a merge of two template variables in grafana like this:
$deployment,$statefulset
Maybe I've missed something...
Thanks,
Matt
I do it by creating two separate variable and give them same label name.
Since the label name is same it will only show one drop-down.
https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#basic-variable-options

Chef API: Adding runlists to a node

I am trying to figure out how to use the Chef API to add a runlist to a node, such that, when I go to the https://mychefserver/nodes/myapp01 node, I see the runlist under the Run List section.
But the Chef API doesn't appear to allow this. Am I wrong, if so, what's the endpoint and how do I call it?
Run lists aren't their own object, it is just part of the data in the Node object so you would use the normal GET /nodes/foo and PUT /nodes/foo. The run list is under the key run_list and should be an array of strings.