-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to automatic fetch all the LoadBalancer (With Target Group) tags #571
Comments
P.D: You can use this for NLB too. Only need to change the namespace of the metric from AWS/ApplicationELB to AWS/NetworkELB, and change the resource_type_selection, from :loadbalancer/app to :loadbalancer/net. |
Oh this is awesome, thank you for the writeup! There is an example configuration for ALB, but it is very basic right now – could you extend it with your tricks and add some comments as explanation? Instead of
(haven't tested this) |
thanks @matthiasr , i´ve tested what you say and the right config for it is:
it´s a great thing to modify label values at job instead of replacing labels on each metric, thanks for the advice. |
Hi again @matthiasr , Do you have a special procedure to create a pull request? i mean, i.e do you need me to create a new branch with specific name? |
Fork, branch, and create a PR. You will have to |
When you have a bunch of Load Balancers, and each one has multiple target groups, its really hard to manually specify tags with group_left (tag_xxx, tag_yyy, tag_zzz) instead of doing it with group_right, which automatically joins all tags to the metric.
Here i give you an example of my configuration to scrape metrics and a query, for use in graph or alerts.
First of all, you have to define wich metrics you want to collect, and pay attention on the dimension of each metric.
See how i set the aws_tag_select section when the metric has only LoadBalancer Dimension, or when it has two dimensions, like UnHealthyHostCount, wich has LoadBalancer and TargetGroup dimensions.
With this settings you will recieve the aws_resource_info for only LoadBalancer dimension and for TargetGroup separately, something like:
LoadBalancer Dimension:
aws_resource_info{arn="arn:aws:elasticloadbalancing:eu-west-1:************:loadbalancer/app/MY-LB/MY-LB-ID", exported_job="aws_applicationelb", instance="localhost:PORT", job="The name of the job", load_balancer="app/MY-LB/MY-LB-ID", tag_Application="APP-CODE", tag_Domain="DOM", tag_Environment="PRO", tag_Product="PRODUCT-CODE", tag_Terraform="True"}
With TargetGroup Dimension:
aws_resource_info{arn="arn:aws:elasticloadbalancing:eu-west-1:************:targetgroup/MY-LB-TARGETGROUP-0/TargetGroup-ID", exported_job="aws_applicationelb", instance="localhost:PORT", job="The name of the job", tag_Application="APP-CODE", tag_Domain="DOM", tag_Environment="PRO", tag_Product="PRODUCT-CODE", tag_Terraform="True", target_group="MY-LB-TARGETGROUP-0/TargetGroup-ID"}
And here is the second part of the magic trick :P
You should change the value of the target_group label from the metric, because tag value is like 'target_group="targetgroup/MY-LB-TARGETGROUP-0/TargetGroup-ID", removing the first part of its value 'targetgroup/'. To do this you must use the function label_replace.
The query:
label_replace(aws_applicationelb_un_healthy_host_count_average, "target_group", "$1", "target_group", "targetgroup/(.+)") * on (target_group) group_right (load_balancer) (aws_resource_info{exported_job="aws_applicationelb"})
I hope I have explained it as well as possible, and that it will be useful for everyone.
The text was updated successfully, but these errors were encountered: