This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Max gerrit-no-reply at lists.osmocom.orgHello Neels Hofmeyr, Harald Welte, Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/5029
to look at the new patch set (#12).
Add rate counter dumper
This simple tool dump all the rate counters available via ctrl interface
to cvs file (or stdout).
Change-Id: I12b369434e4ee9b38f92872f297e1f3d4f0698c2
Fixes: OS#2550
---
M README
M contrib/jenkins.sh
A scripts/osmo_rate_ctr2csv.py
M setup.py
4 files changed, 89 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/29/5029/12
diff --git a/README b/README
index e85c1c4..2c04047 100644
--- a/README
+++ b/README
@@ -9,6 +9,7 @@
There are currently following scripts in this package:
osmotestconfig.py - test that apps start/write with example configs
soap.py - implementation of SOAP <-> Ctrl proxy implemented on top of Twisted
+osmo_rate_ctr2csv.py - rate counter dumper on top of osmo_ipa
osmo_interact_vty.py - pipe stdin/stdout to a VTY session
osmo_interact_ctrl.py - pipe stdin/stdout to a CTRL port
osmo_verify_transcript_vty.py - VTY testing by VTY session screen dumps
diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh
index ac67d85..08908a4 100755
--- a/contrib/jenkins.sh
+++ b/contrib/jenkins.sh
@@ -16,7 +16,7 @@
rm -rf ./build
PY3=python3
-PY3_LIST="osmopy scripts/osmo_ctrl.py scripts/osmodumpdoc.py scripts/osmotestvty.py scripts/osmotestconfig.py scripts/osmo_interact_ctrl.py scripts/osmo_interact_vty.py scripts/osmo_verify_transcript_ctrl.py scripts/osmo_verify_transcript_vty.py scripts/soap.py scripts/twisted_ipa.py"
+PY3_LIST="osmopy scripts/osmo_ctrl.py scripts/osmo_rate_ctr2csv.py scripts/osmodumpdoc.py scripts/osmotestvty.py scripts/osmotestconfig.py scripts/osmo_interact_ctrl.py scripts/osmo_interact_vty.py scripts/osmo_verify_transcript_ctrl.py scripts/osmo_verify_transcript_vty.py scripts/soap.py scripts/twisted_ipa.py"
$PY3 ./setup.py install
$PY3 tests/test_py3.py
for f in $PY3_LIST
diff --git a/scripts/osmo_rate_ctr2csv.py b/scripts/osmo_rate_ctr2csv.py
new file mode 100644
index 0000000..1e3fc9f
--- /dev/null
+++ b/scripts/osmo_rate_ctr2csv.py
@@ -0,0 +1,86 @@
+#!/usr/bin/python3
+# -*- mode: python-mode; py-indent-tabs-mode: nil -*-
+"""
+/*
+ * Copyright (C) 2017 sysmocom s.f.m.c. GmbH
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+"""
+
+from osmopy.osmo_ipa import Ctrl
+import socket, argparse, sys, logging, csv
+
+__version__ = "0.0.1" # bump this on every non-trivial change
+
+def connect(host, port):
+ sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sck.setblocking(1)
+ sck.connect((host, port))
+ return sck
+
+def get_var(sck, var):
+ (_, c) = Ctrl().cmd(var, None)
+ sck.send(c)
+ return Ctrl().parse_kv(sck.recv(4096))
+
+def get_interval(group_name, group_counters, interval):
+ log.debug('Getting %s counter values: %s...' % (group_name, interval))
+ (_, c) = get_var(sock, 'rate_ctr.%s.%s' % (interval, group_name))
+ for ctr in c.split(';'):
+ if len(ctr):
+ (k, v) = ctr.split()
+ group_counters[k] = group_counters.get(k, (group_name,)) + (v,)
+ return len(group_counters)
+
+
+if __name__ == '__main__':
+ p = argparse.ArgumentParser(description='Dump rate counters into csv via Osmocom CTRL protocol.')
+ p.add_argument('-v', '--version', action='version', version=("%(prog)s v" + __version__))
+ p.add_argument('-p', '--port', type=int, default=4249, help="Port to use for CTRL interface, defaults to 4249")
+ p.add_argument('-c', '--ctrl', default='localhost', help="Adress to use for CTRL interface, defaults to localhost")
+ p.add_argument('-d', '--debug', action='store_true', help="Enable debug log")
+ p.add_argument('--header', action='store_true', help="Prepend column header to output")
+ p.add_argument('-o', '--output', nargs='?', type=argparse.FileType('w'), default=sys.stdout, help="Output file, defaults to stdout")
+ args = p.parse_args()
+
+ log = logging.getLogger('rate_ctr2csv')
+ log.setLevel(logging.DEBUG if args.debug else logging.INFO)
+ log.addHandler(logging.StreamHandler(sys.stderr))
+
+ log.info('Connecting to %s:%d...' % (args.ctrl, args.port))
+ sock = connect(args.ctrl, args.port)
+
+ log.info('Getting rate counter groups info...')
+ (_, g) = get_var(sock, 'rate_ctr.*')
+
+ w = csv.writer(args.output, dialect='unix')
+ total_groups = 0
+ total_rows = 0
+
+ if args.header:
+ w.writerow(['group', 'counter', 'absolute', 'second', 'minute', 'hour', 'day'])
+
+ for group in g.split(';'):
+ if len(group):
+ g_counters = {}
+ total_groups += 1
+ total_rows += list(map(lambda x: get_interval(group, g_counters, x), ('abs', 'per_sec', 'per_min', 'per_hour', 'per_day')))[0]
+ for (k, (gr, absolute, per_sec, per_min, per_hour, per_day)) in g_counters.items():
+ w.writerow([gr, k, absolute, per_sec, per_min, per_hour, per_day])
+
+ log.info('Completed: %d counters from %d groups received.' % (total_rows, total_groups))
diff --git a/setup.py b/setup.py
index bbb4b93..e1bdafe 100755
--- a/setup.py
+++ b/setup.py
@@ -29,6 +29,7 @@
"scripts/osmo_interact_vty.py",
"scripts/osmo_interact_ctrl.py",
"scripts/osmo_ctrl.py",
+ "scripts/osmo_rate_ctr2csv.py",
"scripts/soap.py",
"scripts/twisted_ipa.py",
"scripts/osmo_verify_transcript_vty.py",
--
To view, visit https://gerrit.osmocom.org/5029
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I12b369434e4ee9b38f92872f297e1f3d4f0698c2
Gerrit-PatchSet: 12
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>