object-replicator now optionally updates recon stats directly. also updated swift-recon-cron with a cleaner python version.
This commit is contained in:
3 changed files with 146 additions and 51 deletions
@@ -1,56 +1,60 @@
#!/bin/bash
#!/usr/bin/env python
"""
swift-recon-cron.py
"""
#ghetto temporary cronjob to pull some of the stats for swift-recon
#usage: swift-recon-cron /var/log/swift/storage.log
# run it as frequently as you like, will skip runs during periods
# of high async pendings when the find takes a while.
#todo: everything.
SYSLOG_FACILITY="local2"
ASYNC_PATH="/srv/node/sd[a-z]/async_pending/"
RECON_CACHE_PATH="/var/cache/swift"
LOCKFILE="/var/lock/swift-recon-object.lock"
if [ -e $LOCKFILE ]; then
echo "NOTICE - 0ドル lock present - cron jobs overlapping ?"
echo "0ドル lock file present" | /usr/bin/logger -p $SYSLOG_FACILITY.err
exit 1
else
touch $LOCKFILE
fi
import os
import sys
import optparse
from tempfile import NamedTemporaryFile
import simplejson
from ConfigParser import ConfigParser
from swift.common.utils import get_logger, dump_recon_cache
if [ -z "1ドル" ]; then
LOGFILE="/var/log/swift/storage.log"
else
LOGFILE=1ドル
fi
def async_count(device_dir, logger):
async_count = 0
for i in os.listdir(device_dir):
asyncdir = os.path.join(device_dir, i, "async_pending")
if os.path.isdir(asyncdir):
for entry in os.listdir(asyncdir):
if os.path.isdir(os.path.join(asyncdir, entry)):
async_hdir = os.path.join(asyncdir, entry)
async_count += len(os.listdir(async_hdir))
return async_count
if [ ! -r "$LOGFILE" ]; then
echo "0ドル: error $LOGFILE not readable" | /usr/bin/logger -p $SYSLOG_FACILITY.err
rm $LOCKFILE
exit 1
fi
if [ ! -d "$RECON_CACHE_PATH" ]; then
mkdir $RECON_CACHE_PATH
fi
def main():
c = ConfigParser()
try:
conf_path = sys.argv[1]
except Exception:
print "Usage: %s CONF_FILE" % sys.argv[0].split('/')[-1]
print "ex: swift-recon-cron /etc/swift/object-server.conf"
sys.exit(1)
if not c.read(conf_path):
print "Unable to read config file %s" % conf_path
sys.exit(1)
conf = dict(c.items('filter:recon'))
device_dir = conf.get('devices', '/srv/node')
recon_cache_path = conf.get('recon_cache_path', '/var/cache/swift')
cache_file = os.path.join(recon_cache_path, "object.recon")
conf['log_name'] = conf.get('log_name', 'recon-cron')
logger = get_logger(conf, log_route='recon-cron')
try:
os.mkdir("/var/lock/swift-recon-object-cron")
except OSError as e:
logger.critical("%s" % e)
sys.exit(1)
asyncs = async_count(device_dir, logger)
try:
dump_recon_cache('object_replication_time', total, cache_file)
except ValueError:
logger.exception(_('Exception decoding recon cache'))
except Exception:
logger.exception(_('Exception dumping recon cache'))
os.rmdir("/var/lock/swift-recon-object-cron")
TMPF=`/bin/mktemp`
asyncs=$(find $ASYNC_PATH -type f 2> /dev/null| wc -l)
#asyncs=$(find /srv/[1-4]/node/sd[a-z]1/async_pending/ -type f 2> /dev/null| wc -l) #saio
objrep=$(grep "Object replication complete." $LOGFILE | tail -n 1 | awk '{print 9ドル}' | sed -e 's/(//g')
objincoming=$(netstat -aln | egrep "tcp.*:6000.*:.*ESTABLISHED" -c)
#objtw=$(netstat -aln | egrep "tcp.*:6000.*:.*TIME_WAIT" -c)
echo "{\"async_pending\":$asyncs, \"object_replication_time\":$objrep, \"object_established_conns\":$objincoming}" > $TMPF
mv $TMPF $RECON_CACHE_PATH/object.recon
if [ $? -ne 0 ]; then
echo "0ドル: $TMPF rename failed" | /usr/bin/logger -p $SYSLOG_FACILITY.err
rm -f $TMPF $LOCKFILE
exit 1
fi
rm -f $TMPF $LOCKFILE
exit 0
if __name__ == '__main__':
main()
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.