Does Grafana support equality/binary operators in the Variable section? - grafana-loki

I'm creating a dashboard to show the canary instance data. I am planning to create a variable that contains the canary instance IPs and we always create one instance in a stack for the canary. So we can assume that if a stack contains one instance then it should be a canary instance.
The below query will provide the canary instance hostname/ip.
count by(location,environment)(cadvisor_version_info{aws_cloudformation_stack_name=~".Green.",cloud=~"${cloud}",location=~"${location}",environment=~"${environment}"})
== 1
Is it possible to create a variable with the above query? Does Grafana support equality/binary operators in the Variable section?

Related

PromQL change label value (not name) into a specific metric in all TSDB

I would like to change the value (not the label name) of label instance in the Prometheus DB using a PromQL from metric rundeck_system_stats_uptime_since.
I managed to do this before ingestion using this:
- source_labels: [__meta_kubernetes_pod_container_name,__meta_kubernetes_pod_container_port_number]
action: replace
separator: ":"
target_label: instance
So I'm covered for future metrics, but I would like to do this for existing values for instance label.
Expected result:
rundeck_system_stats_uptime_since{app="rdk-exporter", instance="rdk-exporter:9620", [...]}
Since it's a container in k8s I'm not interested in the IP of that container/host/node etc. because it's always changing, I'm only interested in the metrics.
Thank you
You can use label_replace from MetricsQL
How it is work you can check in victoriametrics play
So for example I have three metrics
process_cpu_seconds_total{cluster_num="1"cluster_retention="1m"instance="play-1m-1-vmagent.us-east1-b.c.victoriametrics-test.internal:8429"job="vmagent"}
process_cpu_seconds_total{cluster_num="1"cluster_retention="accounting"instance="play-accounting-1-vmagent.us-east1-b.c.victoriametrics-test.internal:8429"job="vmagent"}
process_cpu_seconds_total{cluster_num="1"cluster_retention="admin"instance="play-admin-1-vmagent.us-east1-b.c.victoriametrics-test.internal:8429"job="vmagent"}
if I will use this query
label_replace(process_cpu_seconds_total{instance=~".*:8429"}, "instance", "some:$2", "instance", "(.*):(.*)")
I will get next response
process_cpu_seconds_total{cluster_num="1"cluster_retention="1m"instance="some:8429"job="vmagent"}
process_cpu_seconds_total{cluster_num="1"cluster_retention="accounting"instance="some:8429"job="vmagent"}
process_cpu_seconds_total{cluster_num="1"cluster_retention="admin"instance="some:8429"job="vmagent"}
where instance will have same host.
Hope this solution will help you.

AWS filtering out all instance profiles that have no roles attached

I am writing a cleanup script that cleans up after Ansible's iam_role inability to clean instance profiles. In general, this instance profile has no roles attached, so I would like to filter all instance profiles that has empty roles object. However, jmespath has not_null function but not is_null function. So, my question is - how can filter out only instance profiles with no roles attached (boto3 or shell). Thanks!
Using boto3, you can try this. This is assuming the Roles value is an empty list, []. If it's something else, you just have to fix the code to what is returned.
client = boto3.client('iam')
r = client.list_instance_profiles()
for ip in r['InstanceProfiles']:
if len(ip['Roles']) == 0:
print(ip)

Build list from nested object in apache freemarker?

I have a list of object and I want to get a list from its field.
Say I pass List<Auto> autos from java side to the template on the document side. Each Auto has a field of speed.
So the result should be list of speed.
I can do it manually looping through the autos and building a new list from the speed fields.
Is there any easier solution built in for this in the freemarker something like 'autos.speed?tolist'
You are looking for the sequence built-in map, which is available from version 2.3.29. It returns a new sequence where all elements are replaced with the result of the parameter lambda, function, or method. This allows you to do:
autos?map(auto -> auto.speed)
If you want to do this in Java, see:
Create list of object from another using Java 8 Streams
There it comes down to:
autos.stream().map(Auto::getSpeed).collect(Collectors.toList());

Listing nodes using jclouds

Is it possible to list nodes in a non-default AWS VPC? This can be done easily using EC2::DescribeInstances by passing a filter with vpc-id= but I can't figure out how to do it using jclouds.
I know how to create an instance in a specified VPC using template options, but I cannot find an equivalent approach for listing nodes. I'm currently using listNodesDetailsMatching(...).
You cannot eagerly filter that on the provider. Using the portable interface you can just provide a predicate to filter nodes once you have them all. You can directly use the underlying AWS EC2 API to do what you want. It could be something like the following:
AWSEC2Api aws = computeServiceContext.unwrapApi(AWSEC2Api.class);
AWSInstanceApi instanceApi = aws.getInstanceApi().get();
instanceApi.describeInstancesInRegionWithFilter("region", ImmutableMultimap.of("vpc-id", "myvpc"));

creating an ec2 instance from an image - finding kernel id attributes using boto

I've got an EC2 snapshot from a running machine. When I create an image and then an instance out of it, it fails the reachability test, and I can't connect to it. I checked the volume and it's got no errors by attaching to another machine.
I now suspect that I have to choose the right kernel-id, and that the default might not be compatible.
Looking at other EC2 instances I have, they are running kernel id aki-427d952b, but this kernel is not available from the dropdown list (even in the same availability zone).
How do I find the next-best kernel id? Is there some list of kernel ids and which versions/architectures they support?
EDIT: can e.g. python boto or another library be used to list all kernel-ids and attributes to allow choosing a different kernel-id from aki-427d952b (which is missing from the dropdown list).
Boto can certainly be used to list images, and you can get data about their configuration. Whether that's the best way to search for a replacement is another question, but, if you want to do it, here's the python/boto code
# use your AWS id and Secret here
conn = EC2Connection(awsid, awssecret)
# returns array of all images your account can use
all_images = conn.get_all_images()
for img in all_images:
attrs = img.__dict__
# attrs will be a dictionary of key-value pairs associated
# with the image. Look through them to find what you want.
if img.kernel_id == 'aki-427d952b':
print "found aki-427d952b: imgid=" + img.id

Resources