Commit a12c6db8 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch...

Merge branch '29302-improve-the-prometheus-queries-for-multiple-container-environments' into 'master'

Resolve "Fix the Prometheus queries for multiple container environments"

Closes #29302

See merge request !9949
parents fa7f409f 222cfda9
/* eslint-disable no-new */ /* eslint-disable no-new*/
/* global Flash */ /* global Flash */
import d3 from 'd3'; import d3 from 'd3';
...@@ -180,7 +180,7 @@ class PrometheusGraph { ...@@ -180,7 +180,7 @@ class PrometheusGraph {
// Metric Usage // Metric Usage
axisLabelContainer.append('rect') axisLabelContainer.append('rect')
.attr('x', this.originalWidth - 170) .attr('x', this.originalWidth - 170)
.attr('y', (this.originalHeight / 2) - 80) .attr('y', (this.originalHeight / 2) - 60)
.style('fill', graphSpecifics.area_fill_color) .style('fill', graphSpecifics.area_fill_color)
.attr('width', 20) .attr('width', 20)
.attr('height', 35); .attr('height', 35);
...@@ -188,13 +188,13 @@ class PrometheusGraph { ...@@ -188,13 +188,13 @@ class PrometheusGraph {
axisLabelContainer.append('text') axisLabelContainer.append('text')
.attr('class', 'label-axis-text') .attr('class', 'label-axis-text')
.attr('x', this.originalWidth - 140) .attr('x', this.originalWidth - 140)
.attr('y', (this.originalHeight / 2) - 65) .attr('y', (this.originalHeight / 2) - 50)
.text(graphSpecifics.graph_legend_title); .text('Average');
axisLabelContainer.append('text') axisLabelContainer.append('text')
.attr('class', 'text-metric-usage') .attr('class', 'text-metric-usage')
.attr('x', this.originalWidth - 140) .attr('x', this.originalWidth - 140)
.attr('y', (this.originalHeight / 2) - 50); .attr('y', (this.originalHeight / 2) - 25);
} }
handleMouseOverGraph(x, y, valuesToPlot, chart, prometheusGraphContainer, key) { handleMouseOverGraph(x, y, valuesToPlot, chart, prometheusGraphContainer, key) {
...@@ -263,12 +263,12 @@ class PrometheusGraph { ...@@ -263,12 +263,12 @@ class PrometheusGraph {
cpu_values: { cpu_values: {
area_fill_color: '#edf3fc', area_fill_color: '#edf3fc',
line_color: '#5b99f7', line_color: '#5b99f7',
graph_legend_title: 'CPU Usage (Cores)', graph_legend_title: 'CPU utilization (%)',
}, },
memory_values: { memory_values: {
area_fill_color: '#fca326', area_fill_color: '#fca326',
line_color: '#fc6d26', line_color: '#fc6d26',
graph_legend_title: 'Memory Usage (MB)', graph_legend_title: 'Memory usage (MB)',
}, },
}; };
......
...@@ -74,16 +74,16 @@ class PrometheusService < MonitoringService ...@@ -74,16 +74,16 @@ class PrometheusService < MonitoringService
def calculate_reactive_cache(environment_slug) def calculate_reactive_cache(environment_slug)
return unless active? && project && !project.pending_delete? return unless active? && project && !project.pending_delete?
memory_query = %{sum(container_memory_usage_bytes{container_name="app",environment="#{environment_slug}"})/1024/1024} memory_query = %{(sum(container_memory_usage_bytes{container_name="app",environment="#{environment_slug}"}) / count(container_memory_usage_bytes{container_name="app",environment="#{environment_slug}"})) /1024/1024}
cpu_query = %{sum(rate(container_cpu_usage_seconds_total{container_name="app",environment="#{environment_slug}"}[2m]))} cpu_query = %{sum(rate(container_cpu_usage_seconds_total{container_name="app",environment="#{environment_slug}"}[2m])) / count(container_cpu_usage_seconds_total{container_name="app",environment="#{environment_slug}"}) * 100}
{ {
success: true, success: true,
metrics: { metrics: {
# Memory used in MB # Average Memory used in MB
memory_values: client.query_range(memory_query, start: 8.hours.ago), memory_values: client.query_range(memory_query, start: 8.hours.ago),
memory_current: client.query(memory_query), memory_current: client.query(memory_query),
# CPU Usage rate in cores. # Average CPU Utilization
cpu_values: client.query_range(cpu_query, start: 8.hours.ago), cpu_values: client.query_range(cpu_query, start: 8.hours.ago),
cpu_current: client.query(cpu_query) cpu_current: client.query(cpu_query)
}, },
......
...@@ -18,7 +18,11 @@ ...@@ -18,7 +18,11 @@
= render 'projects/deployments/actions', deployment: @environment.last_deployment = render 'projects/deployments/actions', deployment: @environment.last_deployment
.row .row
.col-sm-12 .col-sm-12
%h4
CPU utilization
%svg.prometheus-graph{ 'graph-type' => 'cpu_values' } %svg.prometheus-graph{ 'graph-type' => 'cpu_values' }
.row .row
.col-sm-12 .col-sm-12
%h4
Memory usage
%svg.prometheus-graph{ 'graph-type' => 'memory_values' } %svg.prometheus-graph{ 'graph-type' => 'memory_values' }
module PrometheusHelpers module PrometheusHelpers
def prometheus_memory_query(environment_slug) def prometheus_memory_query(environment_slug)
%{sum(container_memory_usage_bytes{container_name="app",environment="#{environment_slug}"})/1024/1024} %{(sum(container_memory_usage_bytes{container_name="app",environment="#{environment_slug}"}) / count(container_memory_usage_bytes{container_name="app",environment="#{environment_slug}"})) /1024/1024}
end end
def prometheus_cpu_query(environment_slug) def prometheus_cpu_query(environment_slug)
%{sum(rate(container_cpu_usage_seconds_total{container_name="app",environment="#{environment_slug}"}[2m]))} %{sum(rate(container_cpu_usage_seconds_total{container_name="app",environment="#{environment_slug}"}[2m])) / count(container_cpu_usage_seconds_total{container_name="app",environment="#{environment_slug}"}) * 100}
end end
def prometheus_query_url(prometheus_query) def prometheus_query_url(prometheus_query)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment