Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
222cfda9
Commit
222cfda9
authored
Mar 21, 2017
by
Jose Ivan Vargas Lopez
Committed by
Rémy Coutable
Mar 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Fix the Prometheus queries for multiple container environments"
parent
fa7f409f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
13 deletions
+17
-13
app/assets/javascripts/monitoring/prometheus_graph.js
app/assets/javascripts/monitoring/prometheus_graph.js
+7
-7
app/models/project_services/prometheus_service.rb
app/models/project_services/prometheus_service.rb
+4
-4
app/views/projects/environments/metrics.html.haml
app/views/projects/environments/metrics.html.haml
+4
-0
spec/support/prometheus_helpers.rb
spec/support/prometheus_helpers.rb
+2
-2
No files found.
app/assets/javascripts/monitoring/prometheus_graph.js
View file @
222cfda9
/* eslint-disable no-new
*/
/* eslint-disable no-new*/
/* global Flash */
import
d3
from
'
d3
'
;
...
...
@@ -180,7 +180,7 @@ class PrometheusGraph {
// Metric Usage
axisLabelContainer
.
append
(
'
rect
'
)
.
attr
(
'
x
'
,
this
.
originalWidth
-
170
)
.
attr
(
'
y
'
,
(
this
.
originalHeight
/
2
)
-
8
0
)
.
attr
(
'
y
'
,
(
this
.
originalHeight
/
2
)
-
6
0
)
.
style
(
'
fill
'
,
graphSpecifics
.
area_fill_color
)
.
attr
(
'
width
'
,
20
)
.
attr
(
'
height
'
,
35
);
...
...
@@ -188,13 +188,13 @@ class PrometheusGraph {
axisLabelContainer
.
append
(
'
text
'
)
.
attr
(
'
class
'
,
'
label-axis-text
'
)
.
attr
(
'
x
'
,
this
.
originalWidth
-
140
)
.
attr
(
'
y
'
,
(
this
.
originalHeight
/
2
)
-
65
)
.
text
(
graphSpecifics
.
graph_legend_title
);
.
attr
(
'
y
'
,
(
this
.
originalHeight
/
2
)
-
50
)
.
text
(
'
Average
'
);
axisLabelContainer
.
append
(
'
text
'
)
.
attr
(
'
class
'
,
'
text-metric-usage
'
)
.
attr
(
'
x
'
,
this
.
originalWidth
-
140
)
.
attr
(
'
y
'
,
(
this
.
originalHeight
/
2
)
-
50
);
.
attr
(
'
y
'
,
(
this
.
originalHeight
/
2
)
-
25
);
}
handleMouseOverGraph
(
x
,
y
,
valuesToPlot
,
chart
,
prometheusGraphContainer
,
key
)
{
...
...
@@ -263,12 +263,12 @@ class PrometheusGraph {
cpu_values
:
{
area_fill_color
:
'
#edf3fc
'
,
line_color
:
'
#5b99f7
'
,
graph_legend_title
:
'
CPU
Usage (Cores
)
'
,
graph_legend_title
:
'
CPU
utilization (%
)
'
,
},
memory_values
:
{
area_fill_color
:
'
#fca326
'
,
line_color
:
'
#fc6d26
'
,
graph_legend_title
:
'
Memory
U
sage (MB)
'
,
graph_legend_title
:
'
Memory
u
sage (MB)
'
,
},
};
...
...
app/models/project_services/prometheus_service.rb
View file @
222cfda9
...
...
@@ -74,16 +74,16 @@ class PrometheusService < MonitoringService
def
calculate_reactive_cache
(
environment_slug
)
return
unless
active?
&&
project
&&
!
project
.
pending_delete?
memory_query
=
%{
sum(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]))}
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]))
/ count(container_cpu_usage_seconds_total{container_name="app",environment="#{environment_slug}"}) * 100
}
{
success:
true
,
metrics:
{
# Memory used in MB
#
Average
Memory used in MB
memory_values:
client
.
query_range
(
memory_query
,
start:
8
.
hours
.
ago
),
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_current:
client
.
query
(
cpu_query
)
},
...
...
app/views/projects/environments/metrics.html.haml
View file @
222cfda9
...
...
@@ -18,7 +18,11 @@
=
render
'projects/deployments/actions'
,
deployment:
@environment
.
last_deployment
.row
.col-sm-12
%h4
CPU utilization
%svg
.prometheus-graph
{
'graph-type'
=>
'cpu_values'
}
.row
.col-sm-12
%h4
Memory usage
%svg
.prometheus-graph
{
'graph-type'
=>
'memory_values'
}
spec/support/prometheus_helpers.rb
View file @
222cfda9
module
PrometheusHelpers
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
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
def
prometheus_query_url
(
prometheus_query
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment