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

Proposed solution for issue #533 #534

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ class PrometheusCaptureContext
def collect_node_metrics
# set node labels
labels = labels_to_s(:id => "/", :node => @target.name)
ne_labels = labels_to_s_ne(
:node => "",
)

@metrics = %w(cpu_usage_rate_average mem_usage_absolute_average net_usage_rate_average)
collect_metrics_for_labels(labels)
collect_metrics_for_labels(labels,ne_labels)
end

def collect_container_metrics
Expand All @@ -31,9 +34,14 @@ def collect_container_metrics
:pod => @target.container_group.name,
:namespace => @target.container_project.name,
)
#set container labels with not equal to condition
ne_labels = labels_to_s_ne(
:container => "",
:container => "POD",
)

@metrics = %w(cpu_usage_rate_average mem_usage_absolute_average)
collect_metrics_for_labels(labels)
collect_metrics_for_labels(labels,ne_labels)
end

def collect_group_metrics
Expand All @@ -46,17 +54,21 @@ def collect_group_metrics
:pod => @target.name,
:namespace => @target.container_project.name,
)
ne_labels = labels_to_s_ne(
:container => "",
:container => "POD",
)

@metrics = %w(cpu_usage_rate_average mem_usage_absolute_average net_usage_rate_average)
collect_metrics_for_labels(labels)
collect_metrics_for_labels(labels,ne_labels)
end

def collect_metrics_for_labels(labels)
def collect_metrics_for_labels(labels,ne_labels)
# prometheus field is in core usage per sec
# miq field is in pct of node cpu
#
# rate is the "usage per sec" readings avg over last 5m
cpu_resid = "sum(rate(container_cpu_usage_seconds_total{#{labels}}[#{AVG_OVER}]))"
cpu_resid = "sum(rate(container_cpu_usage_seconds_total{#{ne_labels},#{labels}}[#{AVG_OVER}]))"
fetch_counters_data(cpu_resid, 'cpu_usage_rate_average', @node_cores / 100.0)

# prometheus field is in bytes, @node_memory is in mb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def prometheus_options
def labels_to_s(labels, job = "kubelet")
labels.merge(:job => job).compact.sort.map { |k, v| "#{k}=\"#{v}\"" }.join(',')
end
# added as a fix for https://github.com/ManageIQ/manageiq-providers-kubernetes/issues/533
def labels_to_s_ne(labels, job = "kubelet")
labels.merge(:job => job).compact.sort.map { |k, v| "#{k}!=\"#{v}\"" }.join(',')
end

def prometheus_try_connect
# NOTE: we do not catch errors from prometheus_client here
Expand Down