Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zen 31589 #3737

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bin/metrics/connection_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
mysql -s --skip-column-names -B <<SQL

USE zodb;
SELECT info
FROM connection_info
WHERE ts >= (NOW() - INTERVAL 5 MINUTE)
ORDER BY ts;

SQL

45 changes: 44 additions & 1 deletion bin/metrics/storagestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
import subprocess
import time
from collections import Counter

from gather import MetricGatherer, ServiceMetrics

Expand All @@ -37,7 +38,6 @@ def __init__(self, name):
MetricGatherer.__init__(self)
self.name = name


def get_metrics(self):
metrics = []
ts = time.time()
Expand All @@ -59,9 +59,52 @@ def get_metrics(self):
metrics.append(self.build_metric(table_size, size, ts, tags))
metrics.append(self.build_metric(table_free, free, ts, tags))
metrics.append(self.build_metric('zenoss.%s.total.size' % self.name, total_size, ts, tags))

total, byscript = _get_connection_info()
metrics.append(self.build_metric('zenoss.%s.connection_info.total' % self.name, total, ts, tags))
for k, v in byscript.items():
tgk = {'zenoss_daemon': k}
tgk.update(tags)
metrics.append(self.build_metric('zenoss.%s.connection_info.rate' % self.name, v, ts, tgk))

return metrics


def _get_connection_info():
"""
Get the info field from connection_info table for recent time (see connection_info.sh),
Get name of the script that caused the connection to the DB from the traceback (info field).
:return:
total: the total number of new connections for last n min.
counter: it's a dictionary where the key is the name of the script that caused the connection to DB, value is the number of connections.
"""
try:
response = subprocess.check_output("/opt/zenoss/bin/metrics/connection_info.sh")
except Exception as e:
log.error("Error gathering mysql connection info: %s" % e)
return 0, {}

total = 0
counter = Counter()

for line in response.split('\n'):
if not line: continue
lines = line.split()
try:
ind = lines.index("File")
except ValueError:
continue

script_name = lines[ind+1]
slash = script_name.rfind('/')
point = script_name.rfind('.')
if slash >= 0 and point >= 0:
script_name = script_name[slash+1:point]
total += 1
counter[script_name] += 1
return total, counter


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--interval", dest="interval", type=float,
Expand Down