I am running the SNMP_Exporter package towards some SNMP enabled devices, the snmp.yml is generated via the generator tool.
Now this is a value that is stored in Prometheus:
RefclockOffset{instance="10.0.2.8",job="snmp",RefclockOffset="-0.001258"}
As you can see the SNMP_Exporter stores the float value inside a label.
How can i plot this in grafana?
I am no power-user.
I can't find what MIB this is coming from, but this is due to the MIB exposing the value as a string.
You can add an override to your module in your generator.yml to extract the float from the string:
overrides:
RefclockOffset:
regex_extracts:
'':
- regex: '(.*)'
value: '$1'
Related
How to force integer value in kubernetes template (without helm)
In variables.yaml
-name: PORT
value: 80
In template.yaml
ports:
- containerPort: $(PORT) --> output '80', expected: 80 (int)
protocol: TCP
In the Kubernetes template, you can use the "int" function to force the value of PORT to be an integer. you can make those changes on your template.yaml:
The "int" function converts PORT to an integer for the "containerPort" field. The "int" function around PORT ensures that the template treats it as an integer.
Helm utilizes variables differently than Kubernetes. Helm uses parentheses (()) to access variables, while Kubernetes uses double curly braces ().
ports:
- containerPort: {{int .Values.PORT}}
protocol: TCP
Can you try that script above if that can help you out?
To convert a string to an integer while converting from YAML to JSON, you can use a custom function to parse the string and convert it to an integer. Here is an example implementation in Python:
import yaml
import json
def parse_int(val):
try:
return int(val)
except ValueError:
return val
# Load YAML data from file or string
with open('data.yaml', 'r') as file:
yaml_data = yaml.safe_load(file)
# Parse string values as integers
parsed_data = json.loads(json.dumps(yaml_data, default=parse_int))
# Save JSON data to file or output to console
with open('data.json', 'w') as file:
json.dump(parsed_data, file, indent=2)
In this code, the parse_int function tries to parse the given value as an integer using the int function. If the value is not a valid integer, the function returns the original value. When converting the YAML data to JSON, we pass the parse_int function as the default argument to the json.dumps function. This tells the function to use our custom function to serialize any non-standard types (in this case, strings that represent integers) instead of raising an error.
Note that this implementation only works for integer values represented as strings in the YAML data. If you have other types of data that need to be converted, you will need to modify the 'parse_int' function or create additional functions to handle those cases.
I use kubectl to list Kubernetes custom resources of a kind mykind with an additional table column LABEL that contains the value of a label a.b.c.com/key if present:
kubectl get mykind -o=custom-columns=LABEL:.metadata.labels.'a\.b\.c\.com/key'
This works, i.e., the label value is properly displayed.
Subsequently, I wanted to add a corresponding additional printer column to the custom resource definition of mykind:
- description: Label value
jsonPath: .metadata.labels.'a\.b\.c\.com/key'
name: LABEL
type: string
Although the additional column is added to kubectl get mykind, it is empty and no label value is shown (in contrast to above kubectl command). My only suspicion were problems with escaping of the special characters - but no variation helped.
Are you aware of any difference between the JSON path handling in kubectl and additional printer columns? I expected strongly that they are exactly the same.
mdaniel's comment works!
- description: Label value
jsonPath: '.metadata.labels.a\.b\.c\.com/key'
name: LABEL
type: string
You need to use \. instead of . and use single quotes ' '. It doesn't work with double quotes for the reasons I don't understand
My incoming field -->double datattype (veeva)--> for eg.s, 134.0 , 45.4,61.234
My output needs to be always 2 places of decimal --->file ---> field value: 134.00, 45.40, 61.23
I have tried creating an expression on informatica cloud:
TO_DECIMAL( IN_TAX, 2 )
but its not giving the expected output.
Keep the data type to double with decimal point =2 and use round(). I am assuming your target is a flat file.
create an out port in exp transformation like below -
out_tax = ROUND(in_tax,2) -- data type is DOUBLE(xx,2), where xx is your precision.
Link this port to target.
I have a Grafana dashboard which has 3 different global variables for the user to choose from: cloud(aws, azure, gcp), environment(dev, stage, prod), location(eastus2, westus2, westeurope, northeurope, etc..)
The user can choose a specific dashboard with the combination of these three variables.
I want to add a string constant(say, a uuid), which is unique for different combination of these three variables, such that:
aws-dev-eastus2 => b3207989-162c-4be6-a3d0-3a17444cff7d
azure-stage-westeurope => 5340aad8-ea3d-416b-8ab2-1cafd7c301ca
gcp-prod-westus2 => 2f2b3a9c-c179-4b70-b688-36d9f3548bc2
...
I wonder if it is possible to have a constant type variable, in the format of map/dictionary, so that when the three variables "cloud/environment/location" are fix, this variable can return the corresponding uuid.
Any ideas?
1.) Global variables - No they can't be "global". Grafana has only some builtin variables, which are global - doc: https://grafana.com/docs/grafana/latest/variables/variable-types/global-variables/. User can define only dasbhoard variable (so scope of the variable is only for one particular dashboard, not for whole Grafana instance)
2.) Key => value variable - yes/no, only some SQL (e.g. PotgreSQL, MySQL) datasources support it and also Custom variable supports it (make sure you have Grafana version, with support for that - ). Doc: https://grafana.com/docs/grafana/latest/variables/variable-types/add-custom-variable/#enter-custom-options
In my Grafana dashboard (with Prometheus as a data source), I have a custom $tier variable, which allows the user to pick the tier from a dropdown. It's defined as:
Values separated by comma: production, stage, development
I need to filter a Prometheus metric by a label which contains a shortened version of the tier name:
"foo-dev"
"foo-stage"
"foo-prod"
I was thinking that I'd create a hidden variable $shortened_tier so I could use that in my query filter, like this:
my_label=~"foo-$shortened_tier"
I'd like to define it based on the value of $tier:
"development" -> "dev"
"stage" -> "stage"
"production" -> "prod"
How do I do that?
I figured out a workaround for this, but it is suuuuper hacky:
Name: shortened_tier
Type: Query
Data Source: Prometheus
Query: label_values(up{env="$tier"}, env)
Regex: (dev|stage|prod).*
What I wanted to do was simply Query: $tier, but since Grafana wouldn't let me do that, I had to use a completely different metric (up) where I could pass in $tier and get back the same exact value as a string. Then I use regex to just look for dev|stage|prod at the beginning of the string, capture that part, and throw away the rest.
This has the result that I'm looking for, with the value of $shortened_tier dynamically changing based on the value that's selected and assigned to $tier. But man I wish Grafana had a less hacky way to do this.