Skip to content
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

Add consul_service_weight metric. #101

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading