Skip to content

Commit

Permalink
Add consul_service_weight metric.
Browse files Browse the repository at this point in the history
- This metrics will give total weight for a service,
- It will have the same labels as existing consul_service_count metric.
  • Loading branch information
Damien Filliat authored and manu-ns committed Mar 25, 2024
1 parent fbad21b commit 15a113a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions samples/metrics.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,31 @@ consul_members_count{serf="lan",status="<%= k %>"} <%= v %><%
metas: metas,
service_name: service_name,
state: {
'passing' => 0,
'warning' => 0,
'critical' => 0,
'passing' => {
instances: 0,
weight: 0
},
'warning' => {
instances: 0,
weight: 0
},
'critical' => {
instances: 0,
weight: 0
}
}
}
backends[key] = back
end
state = snode.status
back[:state][state] += 1
# Increment instance number.
back[:state][state][:instances] += 1
# Increment total weight regarding current node's state.
if state == 'passing'
back[:state][state][:weight] += snode['Service']['Weights']['Passing']
elsif state == 'warning'
back[:state][state][:weight] += snode['Service']['Weights']['Warning']
end
end
end
end
Expand Down Expand Up @@ -118,7 +134,8 @@ end
meta_string+=",#{k}=\"#{escape_meta(v)}\""
end
service_info[:state].each_pair do |state_name, state_count|
%>consul_service_count{service="<%= service_name %>",state="<%= state_name %>"<%= meta_string %>} <%= state_count %>
%>consul_service_count{service="<%= service_name %>",state="<%= state_name %>"<%= meta_string %>} <%= state_count[:instances] %>
consul_service_weight{service="<%= service_name %>",state="<%= state_name %>"<%= meta_string %>} <%= state_count[:weight] %>
<%
end
end
Expand Down

0 comments on commit 15a113a

Please sign in to comment.