Skip to content

Commit

Permalink
freebsd collectors cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vasiliyk committed May 27, 2024
1 parent f80c724 commit 04171ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
28 changes: 14 additions & 14 deletions collectors/available/freebsd/long-lived/gstat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# This file is part of tcollector.
# Copyright (C) 2012 The tcollector Authors.
# Copyright (C) 2012-2014 The tcollector Authors.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand All @@ -13,7 +13,7 @@
# see <http://www.gnu.org/licenses/>.
#

'''
"""
Disks detailed statistics for TSDB
This plugin tracks, for all FreeBSD disks:
Expand Down Expand Up @@ -41,7 +41,7 @@
Requirements :
- FreeBSD : gstat (with the following patch https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=212726)
'''
"""

import errno
import sys
Expand All @@ -59,12 +59,12 @@
gstat_conf = None

DEFAULT_COLLECTION_INTERVAL = 15
signal_received = None
SIGNAL_RECEIVED = None


def handlesignal(signum, stack):
global signal_received
signal_received = signum
global SIGNAL_RECEIVED
SIGNAL_RECEIVED = signum


def main():
Expand All @@ -74,10 +74,10 @@ def main():
collection_filter = ".*"
if gstat_conf:
config = gstat_conf.get_config()
collection_interval=config['collection_interval']
collection_filter=config['collection_filter']
collection_interval = config['collection_interval']
collection_filter = config['collection_filter']

global signal_received
global SIGNAL_RECEIVED

signal.signal(signal.SIGTERM, handlesignal)
signal.signal(signal.SIGINT, handlesignal)
Expand All @@ -95,7 +95,7 @@ def main():

timestamp = 0

while signal_received is None:
while SIGNAL_RECEIVED is None:
try:
line = p_gstat.stdout.readline()
except (IOError, OSError) as e:
Expand All @@ -107,7 +107,7 @@ def main():
# end of the program, die
break

if (not re.match("^ *[0-9]",line)):
if not re.match("^ *[0-9]",line):
timestamp = int(time.time())
continue

Expand All @@ -132,10 +132,10 @@ def main():

sys.stdout.flush()

if signal_received is None:
signal_received = signal.SIGTERM
if SIGNAL_RECEIVED is None:
SIGNAL_RECEIVED = signal.SIGTERM
try:
os.kill(p_gstat.pid, signal_received)
os.kill(p_gstat.pid, SIGNAL_RECEIVED)
except Exception:
pass
p_gstat.wait()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# This file is part of tcollector.
# Copyright (C) 2012 The tcollector Authors.
# Copyright (C) 2012-2014 The tcollector Authors.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand All @@ -13,7 +13,7 @@
# see <http://www.gnu.org/licenses/>.
#

'''
"""
Network interfaces detailed statistics for TSDB
This plugin tracks, for interfaces named in configuration file:
Expand All @@ -30,7 +30,7 @@
Requirements :
- FreeBSD : netstat
'''
"""

import errno
import sys
Expand All @@ -49,26 +49,26 @@
ifrate_conf = None

DEFAULT_COLLECTION_INTERVAL = 15
signal_received = None
SIGNAL_RECEIVED = None


def handlesignal(signum, stack):
global signal_received
signal_received = signum
global SIGNAL_RECEIVED
SIGNAL_RECEIVED = signum


def main():
"""top main loop"""

collection_interval=DEFAULT_COLLECTION_INTERVAL
collection_interval = DEFAULT_COLLECTION_INTERVAL
if ifrate_conf:
config = ifrate_conf.get_config()
collection_interval = config['collection_interval']
interfaces = config['interfaces']
report_packets = config['report_packets']
merge_err_in_out = config['merge_err_in_out']

global signal_received
global SIGNAL_RECEIVED

signal.signal(signal.SIGTERM, handlesignal)
signal.signal(signal.SIGINT, handlesignal)
Expand All @@ -94,7 +94,7 @@ def main():
timestamp = 0
procnum = 0

while signal_received is None:
while SIGNAL_RECEIVED is None:
if procnum >= intnum:
procnum=0
try:
Expand All @@ -108,7 +108,7 @@ def main():
# end of the program, die
break

if (re.match("^[0-9 ]+$",line)):
if re.match("^[0-9 ]+$", line):
fields = line.split()
if len(fields) == 9:
if procnum == 0:
Expand All @@ -133,11 +133,11 @@ def main():

sys.stdout.flush()

if signal_received is None:
signal_received = signal.SIGTERM
if SIGNAL_RECEIVED is None:
SIGNAL_RECEIVED = signal.SIGTERM
try:
for procnum in range(0, intnum):
os.kill(p_net[procnum].pid, signal_received)
os.kill(p_net[procnum].pid, SIGNAL_RECEIVED)
except Exception:
pass
for procnum in range(0, intnum):
Expand Down

0 comments on commit 04171ff

Please sign in to comment.