Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Video AG Infrastruktur
website
Commits
336d7c1a
Commit
336d7c1a
authored
8 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Added db cluster status page
parent
311d687d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
db.py
+26
-0
26 additions, 0 deletions
db.py
server.py
+28
-2
28 additions, 2 deletions
server.py
templates/dbstatus.html
+53
-0
53 additions, 0 deletions
templates/dbstatus.html
with
107 additions
and
2 deletions
db.py
+
26
−
0
View file @
336d7c1a
...
...
@@ -42,6 +42,9 @@ if config['DB_ENGINE'] == 'sqlite':
params
=
[(
p
.
replace
(
microsecond
=
0
)
if
isinstance
(
p
,
datetime
)
else
p
)
for
p
in
params
]
return
operation
,
params
def
show
(
operation
,
host
=
None
):
return
{}
elif
config
[
'
DB_ENGINE
'
]
==
'
mysql
'
:
import
mysql.connector
...
...
@@ -57,6 +60,29 @@ elif config['DB_ENGINE'] == 'mysql':
params
=
[(
p
.
replace
(
microsecond
=
0
)
if
isinstance
(
p
,
datetime
)
else
p
)
for
p
in
params
]
return
operation
,
params
def
show
(
operation
,
host
=
config
.
get
(
'
MYSQL_HOST
'
,
None
)):
if
host
:
db
=
mysql
.
connector
.
connect
(
user
=
config
[
'
MYSQL_USER
'
],
password
=
config
[
'
MYSQL_PASSWD
'
],
host
=
host
,
port
=
config
.
get
(
'
MYSQL_PORT
'
,
3306
))
else
:
db
=
mysql
.
connector
.
connect
(
user
=
config
[
'
MYSQL_USER
'
],
password
=
config
[
'
MYSQL_PASSWD
'
],
unix_socket
=
config
.
get
(
'
MYSQL_UNIX
'
,
None
))
cur
=
db
.
cursor
()
cur
.
execute
(
operation
)
rows
=
[]
try
:
rows
=
cur
.
fetchall
()
except
mysql
.
connector
.
errors
.
InterfaceError
as
ie
:
if
ie
.
msg
==
'
No result set to fetch from.
'
:
# no problem, we were just at the end of the result set
pass
else
:
raise
res
=
{}
for
row
in
rows
:
res
[
row
[
0
]]
=
row
[
1
]
cur
.
close
()
db
.
close
()
return
res
def
query
(
operation
,
*
params
,
delim
=
"
sep
"
):
operation
,
params
=
fix_query
(
operation
,
params
)
cur
=
get_dbcursor
()
...
...
This diff is collapsed.
Click to expand it.
server.py
+
28
−
2
View file @
336d7c1a
...
...
@@ -70,7 +70,7 @@ app.jinja_env.globals['gitversion'] = { 'hash': output[1], 'longhash': output[0]
if
not
config
.
get
(
'
SECRET_KEY
'
,
None
):
config
[
'
SECRET_KEY
'
]
=
os
.
urandom
(
24
)
from
db
import
query
,
modify
,
searchquery
,
ldapauth
,
ldapget
from
db
import
query
,
modify
,
show
,
searchquery
,
ldapauth
,
ldapget
mod_endpoints
=
[]
...
...
@@ -617,7 +617,33 @@ def legacy(phpfile=None):
return
redirect
(
url_for
(
'
feed
'
,
handle
=
request
.
args
.
copy
().
popitem
()[
0
]),
code
=
302
)
print
(
"
Unknown legacy url:
"
,
request
.
url
)
return
redirect
(
url_for
(
'
index
'
),
code
=
302
)
import
json
@app.route
(
'
/internal/dbstatus
'
)
@register_navbar
(
'
DB-Status
'
,
icon
=
'
ok
'
)
@mod_required
def
dbstatus
():
hosts
=
set
()
clusters
=
{}
status
=
{}
variables
=
{}
for
host
in
config
.
get
(
'
MYSQL_DBSTATUS_HOSTS
'
,
[])
+
[
config
.
get
(
'
MYSQL_HOST
'
,
None
)]:
for
_host
in
show
(
'
SHOW VARIABLES LIKE
"
wsrep_cluster_address
"'
,
host
=
host
)[
'
wsrep_cluster_address
'
][
len
(
'
gcomm://
'
):].
split
(
'
,
'
):
hosts
.
add
(
_host
)
for
host
in
hosts
:
try
:
status
[
host
]
=
show
(
'
SHOW GLOBAL STATUS LIKE
"
wsrep%
"'
,
host
=
host
)
variables
[
host
]
=
show
(
'
SHOW GLOBAL VARIABLES LIKE
"
wsrep%
"'
,
host
=
host
)
except
:
status
[
host
]
=
{
'
wsrep_cluster_state_uuid
'
:
''
,
'
wsrep_local_state_comment
'
:
'
Not reachable
'
,
'
wsrep_cluster_conf_id
'
:
'
0
'
,
'
wsrep_cluster_status
'
:
'
Unknown
'
}
variables
[
host
]
=
{
'
wsrep_node_name
'
:
host
,
'
wsrep_cluster_name
'
:
'
unknown
'
}
cluster
=
variables
[
host
][
'
wsrep_cluster_name
'
]
+
'
-
'
+
status
[
host
][
'
wsrep_cluster_conf_id
'
]
if
cluster
not
in
clusters
:
clusters
[
cluster
]
=
[]
clusters
[
cluster
].
append
(
host
)
return
render_template
(
'
dbstatus.html
'
,
clusters
=
clusters
,
statuses
=
status
,
vars
=
variables
),
200
import
edit
import
feeds
import
importer
...
...
This diff is collapsed.
Click to expand it.
templates/dbstatus.html
0 → 100644
+
53
−
0
View file @
336d7c1a
{% extends "base.html" %}
{% block content %}
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
><h1
class=
"panel-title"
>
Cluster
</b></h1></div>
<ul
class=
"list-group"
>
{% for clustername, clusternodes in clusters.items() %}
<li
class=
"list-group-item"
><strong>
{{vars[clusternodes|first]['wsrep_cluster_name']}}
</strong>
({{statuses[clusternodes|first]['wsrep_cluster_status']}}, Größe={{statuses[clusternodes|first]['wsrep_cluster_size']}}, Konfiguration={{statuses[clusternodes|first]['wsrep_cluster_conf_id']}})
<ul
class=
"list-group"
>
{% for host in clusternodes %}
<li
class=
"list-group-item list-group-item-{{{'1': 'warning', '2': 'warning', '3': 'info', '4': 'success'}.get(statuses[host]['wsrep_local_state'], 'danger')}}"
><a
href=
"#{{host|tagid}}"
>
{{vars[host]['wsrep_node_name']}}
</a>
({{statuses[host]['wsrep_local_state_comment']}}, Letzte Änderung={{statuses[host]['wsrep_last_committed']}}, Recv.-Avg.={{statuses[host]['wsrep_local_recv_queue_avg']}}, Send-Avg.={{statuses[host]['wsrep_local_send_queue_avg']}})
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</table>
</div>
{% for host, status in statuses.items() %}
<div
class=
"panel panel-default"
id=
"{{host|tagid}}"
>
<div
class=
"panel-heading"
><h1
class=
"panel-title"
>
{{vars[host]['wsrep_node_name']}}
</h1></div>
<div
class=
"row"
style=
"margin: 0px;"
>
<div
class=
"col-xs-6 table-responsive"
>
<table
class=
"table"
>
<tr>
<th>
Variable
</th>
<th>
Wert
</th>
</tr>
{% for key, value in vars[host].items() %}
<tr>
<td>
{{key}}
</td>
<td>
{{value}}
</td>
</tr>
{% endfor %}
</table>
</div>
<div
class=
"col-xs-6 table-responsive"
>
<table
class=
"table"
>
<tr>
<th>
Status-Variable
</th>
<th>
Wert
</th>
</tr>
{% for key, value in status.items() %}
<tr>
<td>
{{key}}
</td>
<td>
{{value}}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment