-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guillaume Subiron
committed
Oct 17, 2017
1 parent
c13db68
commit fe1abab
Showing
6 changed files
with
240 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/python | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2009-2012: | ||
# Guillaume Subiron, [email protected] | ||
# | ||
# This file is part of Shinken. | ||
# | ||
# Shinken is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Shinken is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with Shinken. If not, see <http://www.gnu.org/licenses/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/python | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2009-2014: | ||
# Guillaume Subiron, [email protected] | ||
# | ||
# This file is part of Shinken. | ||
# | ||
# Shinken is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Shinken is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with Shinken. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import time | ||
import urllib | ||
|
||
from collections import Counter | ||
|
||
### Will be populated by the UI with it's own value | ||
app = None | ||
|
||
|
||
def get_global_stats(): | ||
user = app.bottle.request.environ['USER'] | ||
user.is_administrator() or app.redirect403() | ||
|
||
range_end = int(time.time()) | ||
range_start = int(app.request.GET.get('range_start', range_end - 2592000)) | ||
|
||
logs = list(app.logs_module.get_ui_logs(range_start=range_start, range_end=range_end, filters={'type': 'SERVICE NOTIFICATION', 'command_name': 'notify-service-by-hubot'}, limit=None)) | ||
hosts = Counter() | ||
services = Counter() | ||
hostsservices = Counter() | ||
for l in logs: | ||
hosts[l['host_name']] += 1 | ||
services[l['service_description']] += 1 | ||
hostsservices[l['host_name'] + '/' + l['service_description']] += 1 | ||
return {'hosts': hosts, 'services': services, 'hostsservices': hostsservices} | ||
|
||
def get_service_stats(name): | ||
user = app.bottle.request.environ['USER'] | ||
user.is_administrator() or app.redirect403() | ||
|
||
range_end = int(time.time()) | ||
range_start = int(app.request.GET.get('range_start', range_end - 2592000)) | ||
|
||
logs = list(app.logs_module.get_ui_logs(range_start=range_start, range_end=range_end, filters={'type': 'SERVICE NOTIFICATION', 'command_name': 'notify-service-by-hubot', 'service_description': name}, limit=None)) | ||
hosts = Counter() | ||
for l in logs: | ||
hosts[l['host_name']] += 1 | ||
return {'service': name, 'hosts': hosts} | ||
|
||
def get_host_stats(name): | ||
user = app.bottle.request.environ['USER'] | ||
user.is_administrator() or app.redirect403() | ||
|
||
range_end = int(time.time()) | ||
range_start = int(app.request.GET.get('range_start', range_end - 2592000)) | ||
|
||
logs = list(app.logs_module.get_ui_logs(range_start=range_start, range_end=range_end, filters={'type': 'SERVICE NOTIFICATION', 'command_name': 'notify-service-by-hubot', 'host_name': name}, limit=None)) | ||
services = Counter() | ||
for l in logs: | ||
services[l['service_description']] += 1 | ||
return {'host': name, 'services': services} | ||
|
||
|
||
pages = { | ||
get_global_stats: { | ||
'name': 'GlobalStats', 'route': '/stats', 'view': 'stats' | ||
}, | ||
|
||
get_service_stats: { | ||
'name': 'Stats', 'route': '/stats/service/<name:path>', 'view': 'stats_service' | ||
}, | ||
|
||
get_host_stats: { | ||
'name': 'Stats', 'route': '/stats/host/<name:path>', 'view': 'stats_host' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
%rebase("layout", css=['logs/css/logs.css'], js=['logs/js/history.js'], title='Alert Statistics on the last 30 days') | ||
|
||
%total = sum(hosts.values()) | ||
|
||
<div class="col-lg-4"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"><h3 class="panel-title">{{ total }} host alerts</h3></div> | ||
<table class="table table-striped table-condensed"> | ||
%for l in hosts.most_common(15): | ||
<tr><td width="160px">{{ l[1] }} ({{ round((l[1] / float(total)) * 100, 1) }}%)</td><td><a href="/stats/host/{{ l[0] }}">{{ l[0] }}</a></td></tr> | ||
%end | ||
%other = sum((h[1] for h in hosts.most_common()[15:])) | ||
<tr><td>{{ other }} ({{ round((other / float(total)) * 100, 1) }}%)</td><td><strong>Others</strong></td></tr> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div class="col-lg-4"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"><h3 class="panel-title">{{ total }} services alerts</h3></div> | ||
<table class="table table-striped table-condensed"> | ||
%for l in services.most_common(15): | ||
<tr><td width="160px">{{ l[1] }} ({{ round((l[1] / float(total)) * 100, 1) }}%)</td><td><a href="/stats/service/{{ l[0] }}">{{ l[0] }}</a></td></tr> | ||
%end | ||
%other = sum((s[1] for s in services.most_common()[15:])) | ||
<tr><td>{{ other }} ({{ round((other / float(total)) * 100, 1) }}%)</td><td><strong>Others</strong></td></tr> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div class="col-lg-4"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"><h3 class="panel-title">{{ total }} hosts/services alerts</h3></div> | ||
<table class="table table-striped table-condensed"> | ||
%for l in hostsservices.most_common(15): | ||
<tr><td width="160px">{{ l[1] }} ({{ round((l[1] / float(total)) * 100, 1) }}%)</td><td>{{ l[0] }}</td></tr> | ||
%end | ||
%other = sum((h[1] for h in hostsservices.most_common()[15:])) | ||
<tr><td>{{ other }} ({{ round((other / float(total)) * 100, 1) }}%)</td><td><strong>Others</strong></td></tr> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div class="col-xs-12"> | ||
<div class="panel panel-default"> | ||
<div class="panel-body"> | ||
<div id="inner_history" data-logclass="3" data-commandname="notify-service-by-slack"> | ||
</div> | ||
|
||
<div class="text-center" id="loading-spinner"> | ||
<h3><i class="fa fa-spinner fa-spin"></i> Loading history data…</h3> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
%rebase("layout", css=['logs/css/logs.css'], js=['logs/js/history.js'], title='Alert Statistics on the last 30 days for ' + host) | ||
|
||
%total = sum(services.values()) | ||
|
||
<div class="col-lg-4"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"><h3 class="panel-title">{{ total }} {{ host }} alerts</h3></div> | ||
<table class="table table-striped table-condensed"> | ||
%for l in services.most_common(15): | ||
<tr><td>{{ l[1] }} ({{ round((l[1] / float(total)) * 100, 1) }}%)</td><td><a href="/stats/service/{{ l[0] }}">{{ l[0] }}</a></td></tr> | ||
%end | ||
%other = sum((h[1] for h in services.most_common()[15:])) | ||
<tr><td>{{ other }} ({{ round((other / float(total)) * 100, 1) }}%)</td><td><strong>Others</strong></td></tr> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div class="col-xs-12"> | ||
<div class="panel panel-default"> | ||
<div class="panel-body"> | ||
<div id="inner_history" data-host='{{ host }}' data-logclass="3" data-commandname="notify-service-by-slack"> | ||
</div> | ||
|
||
<div class="text-center" id="loading-spinner"> | ||
<h3><i class="fa fa-spinner fa-spin"></i> Loading history data…</h3> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
%rebase("layout", css=['logs/css/logs.css'], js=['logs/js/history.js'], title='Alert Statistics on the last 30 days for ' + service) | ||
|
||
%total = sum(hosts.values()) | ||
|
||
<div class="col-lg-4"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"><h3 class="panel-title">{{ total }} {{ service }} alerts</h3></div> | ||
<table class="table table-striped table-condensed"> | ||
%for l in hosts.most_common(15): | ||
<tr><td>{{ l[1] }} ({{ round((l[1] / float(total)) * 100, 1) }}%)</td><td><a href="/stats/host/{{ l[0] }}">{{ l[0] }}</a></td></tr> | ||
%end | ||
%other = sum((h[1] for h in hosts.most_common()[15:])) | ||
<tr><td>{{ other }} ({{ round((other / float(total)) * 100, 1) }}%)</td><td><strong>Others</strong></td></tr> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div class="col-xs-12"> | ||
<div class="panel panel-default"> | ||
<div class="panel-body"> | ||
<div id="inner_history" data-service='{{ service }}' data-logclass="3" data-commandname="notify-service-by-slack"> | ||
</div> | ||
|
||
<div class="text-center" id="loading-spinner"> | ||
<h3><i class="fa fa-spinner fa-spin"></i> Loading history data…</h3> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters