Narrow down a whole metric to an instance in grafana - grafana

If I have a prometheus metric as
((node_memory_MemTotal - node_memory_MemFree - node_memory_Buffers - node_memory_Cached) / node_memory_MemTotal) * 100
How can I apply that only to the current $instance ? I have tried surrounding it in brackets and adding:
{instance="$instance"}
(For which I have declared a variable), but it doesn't like it. Surely I don't have to repeat it after every metric name?

Surely I don't have to repeat it after every metric name?
Yes, for the best performance you should use the full selector with each metric:
((node_memory_MemTotal{instance="$instance"}
- node_memory_MemFree{instance="$instance"}
- node_memory_Buffers{instance="$instance"}
- node_memory_Cached{instance="$instance"}
) / node_memory_MemTotal{instance="$instance"}
) * 100

Related

Argo Workflow use podSpecPatch to dynamically increase memory resource request in retries

I'm looking for a way to dynamically increase memory resource requests in Argo Workflow retries, based on what is described here.
However, in my case, the original memory request parameters need to be taken from input parameters.
I have input parameters memreqnum (e.g. 250) and memrequnit (e.g. Mi), and I'm trying to define a podSpecPatch
that will enable me to specify the memory request as a multiple of memreqnum (based on retries) with the original
memrequnit.
I have made all kinds of attempts, such as the following, but none seem to work:
podSpecPatch: |
containers:
- name: main
resources:
requests:
memory: "{{={{=(asInt{{retries}} + 1)}} * {{inputs.parameters.memreqnum}}}}{{inputs.parameters.memrequnit}}"
The above podSpecPatch gives me the following error:
invalid podSpecPatch "{\"containers\":[{\"name\":\"main\",\"resources\":{\"requests\":{\"memory\":\"{{={{=(asInt{{retries}} + 1)}} * 250}}Mi\"}}}]}": quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'
Can someone please point me in the right direction?
Many thanks!

How to join 2 sets of Prometheus metrics?

AKS = 1.17.9
Prometheus = 2.16.0
kube-state-metrics = 1.8.0
My use case: I want to alert when 1 of my persistent volumes are not in a "Bound" phase and only when this falls within a predefined set of namespaces.
This got me to my first attempt at joining Prometheus metrics - so, please bear with me : )
I opted to use the following to obtain the pv phase:
kube_persistentvolume_status_phase{phase="Bound",job="kube-state-metrics"}
Renders:
kube_persistentvolume_status_phase{instance="10.147.5.110:8080",job="kube-state-metrics",persistentvolume="pvc-33197ae6-d42a-777e-b8ca-efbd66a8750d",phase="Bound"} 1
kube_persistentvolume_status_phase{instance="10.147.5.110:8080",job="kube-state-metrics",persistentvolume="pvc-165d5006-erd4-481e-8acc-eed4a04a3bce",phase="Bound"} 1
This worked well, except for the fact that it does not include the namespace.
So I managed to determine the persistentvolumeclaim namespaces with this:
kube_persistentvolumeclaim_info{namespace=~"monitoring|vault"}
Renders:
kube_persistentvolumeclaim_info{instance="10.147.5.110:8080",job="kube-state-metrics",namespace="vault",persistentvolumeclaim="vault-file",storageclass="default",volumename="pvc-33197ae6-d42a-777e-b8ca-efbd66a8750d"} 1
kube_persistentvolumeclaim_info{instance="10.147.5.110:8080",job="kube-state-metrics",namespace="monitoring",persistentvolumeclaim="prometheus-prometheus-db-prometheus-prometheus-0",storageclass="default",volumename="pvc-165d5006-erd4-481e-8acc-eed4a04a3bce"} 1
So my idea was to join these sets with the matching values in the following fields:
(kube_persistentvolume_status_phase)persistentvolume
on
(kube_persistentvolumeclaim_info)volumename  
BUT, if I understood it correctly you are only able to join two metrics sets on labels that match exactly (text and their values). I hence opted for the "instance" and "job" labels as these were common on both sides and matching. 
kube_persistentvolume_status_phase{phase!="Bound",job="kube-state-metrics"}  * on(instance,job) group_left(namespace) kube_persistentvolumeclaim_info{namespace=~"monitoring|vault"}
Renders:
Error executing query: found duplicate series for the match group {instance="10.147.5.110:8080" , job="kube-state-metrics"} on the right hand-side of the operation: [{__name__="kube_persistentvolumeclaim_info", instance="10.147.5.110:8080", job="kube-state-metrics", namespace="monitoring", persistentvolumeclaim="alertmanager-prometheusam-db-alertmanager-prometheusam-0", storageclass="default", volumename="pvc-b8406fb8-3262-7777-8da8-151815e05d75"}, {__name__="kube_persistentvolumeclaim_info", instance="10.147.5.110:8080", job="kube-state-metrics", namespace="vault", persistentvolumeclaim="vault-file", storageclass="default", volumename="pvc-33197ae6-d42a-777e-b8ca-efbd66a8750d"}];many-to-many matching not allowed: matching labels must be unique on one side
So in all fairness, the query does communicate well on what the problem is - so I attempted to solve this with the "ignoring" option - attempting to keep only the matching labels and values (instance and job) and "excluding/ignoring" the non-matching ones on both sides. This did not work either - resulting in a parsing error. Which in turn nudged me to take a step back and reassess what I am doing.
I am just a bit concerned that I am perhaps barking up the wrong tree here.
My question is: Is this at all possible and if so how? or is there perhaps another, more prudent way to achieve this?
Thanks in advance!

grafana variables in panel

Could you please explane me what does $instance mean in expression:
100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle",instance=~"$instance"}[$interval])) * 100) * ON(instance)
and why i see No data points
but when I change $instance to .*
graph was shown.
in prometheus I see than node_cpu_seconds_total return data like this:
✔node_cpu_seconds_total{cpu="1",instance="10.0.97.140:9100",job="node-exporter",mode="idle"}
Thanks.
These are variables coming from the Grafana templating feature.
Two notations exist:
$variable
[[variable]]
More information in the Grafana docs: https://grafana.com/docs/reference/templating/
The reason you don't see any values in your example is simple: The variable is not defined as a template variable. If you change it to .* you simply allow any value as a regular expression.

Anylogic - delay dependent on resources

I am trying to create a service that varies depending on the resources that are used.
For example if a nurse were to carry out the service it could take 10 - 35 mins, whereas if this is carried out by another member of staff it could take 5-25 minutes.
I have had a go - as in the picture below, however, what I've written doesn't seem to be working.
Resource dependent delays
Any help would be massively appreciated!
First, since the parameter "Delay time" accepts a value, you need to replace if-else statement with conditional expression "? :". The syntax is the following: condition ? value if true : value if false.
Moreover, your should use another condition to check if the agent has a resource unit from "Nurse":
agent.resourceUnitOfPool(Nurse) != null ? triangular(10, 15, 35) :
triangular(5, 10, 25)

Stata: append two datasets, retain value labels

I'm using Stata14 and I'm trying to append two survey datasets that have ~200 variables with same names but different values and value labels. I would like to do the appending so that value labels are retained from the dataset 'on disk'.
Here is an example describing my problem:
Variable in dataset 1 (master):
value - label
1 - yes
2 - no
Same variable in dataset 2 (appended to master):
value - label
1 - yes absolutely
2 - no definitely not
3 - maybe
4 - don't know
Result with append using "dataset 2.dta"
value - label
1 - yes
2 - no
3 - 3
4 - 4
Desired result:
value - label
1 - yes
2 - no
3 - maybe
4 - don't know
Is there any way to do this directly using append? If not, any suggestions on doing the task efficiently are most welcome.
You want to make value labels consistent, which is sensible, fine and easy to do.
When you have appended all the datasets, you then overwrite any value label assignment with a quick
label define whatever 1 yes 2 no 3 maybe 4 "don't know"
label val myvar whatever
with a , modify on the first if a set of value labels with that name already exists.
It's a task to do late. It doesn't need to be fixed before or during the append, and it can most easily be done at that point.
Naturally, this is tedious for several variables, but it's not difficult to understand. Furthermore, even if append were able to take instructions on which labels to use, you would still have to spell that out. In your example, the value labels you want are not actually in use in any of the datasets. So, there will be some inevitable pain. There is a mess to sort out and what the fix is can't be fully automated because it depends on your ideas of what labels are best.
in short, the answer is
NOPE
so you have to be smart. Try to use this trick http://www.stata.com/support/faqs/data-management/keeping-same-variable-with-collapse/ where you get a local copy of the labels that you will be attaching to the full dataset afterwards.