Merge lp:~tcuthbert/charms/trusty/squid-reverseproxy/trunk into lp:charms/trusty/squid-reverseproxy

Proposed by Thomas Cuthbert
Status: Merged
Merged at revision: 57
Proposed branch: lp:~tcuthbert/charms/trusty/squid-reverseproxy/trunk
Merge into: lp:charms/trusty/squid-reverseproxy
Diff against target: 99 lines (+25/-7)
3 files modified
config.yaml (+11/-0)
files/check_squidpeers (+13/-6)
hooks/hooks.py (+1/-1)
To merge this branch: bzr merge lp:~tcuthbert/charms/trusty/squid-reverseproxy/trunk
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Barry Price Approve
Review via email: mp+313908@code.launchpad.net

Description of the change

This changes the way we monitor squid peers.

With the introduction of the nagios_servicegroups config option we are able to statically assign which nagios groups the checks will be in. This is useful in situation where the default group causes unnecessary critical alerts for minor events such as single peers going down.

The second change is a configurable weight option. This weight option influences the check_squidpeers script to alert when a percentage of the hosts are down (defaults at 50%). This can be optimised further by providing weights on individual peers (for example do we care if random peer in Eastern Europe goes down?).

To post a comment you must log in.
58. By Thomas Cuthbert

[tcuthbert] Added calucalate percent up function and modified get_status to work off a configurable percentage down instead of all

Revision history for this message
Barry Price (barryprice) wrote :

The alert weighting option is a welcome addition, LGTM +1

review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

Yup. Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2015-07-14 02:52:30 +0000
3+++ config.yaml 2016-12-29 03:20:43 +0000
4@@ -91,6 +91,11 @@
5 type: int
6 default: 3401
7 description: Port for snmp service
8+ nagios_down_threshold:
9+ default: 50
10+ type: int
11+ description: >
12+ The percentage of downed squid peers that we care to alert on.
13 nagios_context:
14 default: "juju"
15 type: string
16@@ -116,6 +121,12 @@
17 type: string
18 description: >
19 What service this component forms part of, e.g. supermassive-squid-cluster. Used by nrpe.
20+ nagios_servicegroups:
21+ default: ""
22+ type: string
23+ description: >
24+ A comma-separated list of nagios servicegroups. If left empty,
25+ the nagios_context will be used as the servicegroup.
26 package_status:
27 default: "install"
28 type: "string"
29
30=== modified file 'files/check_squidpeers'
31--- files/check_squidpeers 2014-12-22 13:18:59 +0000
32+++ files/check_squidpeers 2016-12-29 03:20:43 +0000
33@@ -1,10 +1,10 @@
34 #!/usr/bin/python
35
36 import argparse
37-from operator import itemgetter
38 import re
39 import subprocess
40 import sys
41+from operator import iadd
42
43
44 parent_re = re.compile(r'^Parent\s+:\s*(?P<name>\S+)')
45@@ -42,14 +42,19 @@
46 return peers
47
48
49-def get_status(peers):
50- ok = all(map(itemgetter('up'), peers))
51+def calculate_perc_up(peers):
52+ return ((reduce(iadd, [1. for i in peers if i['status'] == STATUS_UP]))
53+ / len(peers)) * 100
54+
55+
56+def get_status(peers, weight):
57+ perc = calculate_perc_up(peers)
58 if not peers:
59 retcode = 1
60 message = 'Squid has no configured peers.'
61- elif ok:
62+ elif perc > float(weight):
63 retcode = 0
64- message = 'All peers are UP according to squid.'
65+ message = '{:.0f}% of peers are UP according to squid.'.format(perc)
66 else:
67 retcode = 2
68 peer_info = ["{}: {}".format(p['name'], p['status']) for p in peers
69@@ -63,6 +68,8 @@
70 parser = argparse.ArgumentParser(description='check_squidpeers')
71 parser.add_argument('-p', '--port', default=3128,
72 help='Port number squid listens on')
73+ parser.add_argument('-w', '--weight', default=50,
74+ help='Percentage of down hosts to alert on')
75 args = parser.parse_args()
76 proc = subprocess.Popen(['squidclient', '-p', str(args.port), 'mgr:server_list'],
77 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
78@@ -71,7 +78,7 @@
79 print("Error running squidclient: %s" % stderr)
80 return 2
81 peers = parse(stdout)
82- retcode, message = get_status(peers)
83+ retcode, message = get_status(peers, args.weight)
84 print(message)
85 return retcode
86
87
88=== modified file 'hooks/hooks.py'
89--- hooks/hooks.py 2015-05-13 04:42:30 +0000
90+++ hooks/hooks.py 2016-12-29 03:20:43 +0000
91@@ -374,7 +374,7 @@
92 nrpe_compat.add_check(
93 shortname='squidpeers',
94 description='Check Squid Peers',
95- check_cmd='check_squidpeers -p {port}'.format(**config_data)
96+ check_cmd='check_squidpeers -p {port} -w {nagios_down_threshold}'.format(**config_data)
97 )
98 check_http_params = conf.get('nagios_check_http_params')
99 if check_http_params:

Subscribers

People subscribed via source and target branches

to all changes: