trying to save objects at the end...
This commit is contained in:
1 parent
bc76c60a11
commit
062ee7a521
1 file changed
+42
-1
+42
-1
@@ -19,6 +19,10 @@ parser.add_argument('--num-pings', dest='num_pings', type=int, default=5,\
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
#project_path = '/opt/django/dns_mdb/'
|
||||
#if project_path not in sys.path:
|
||||
# sys.path.append(project_path)
|
||||
|
||||
from django.core.management import setup_environ
|
||||
from django.core.mail import mail_admins
|
||||
from dns_mdb import settings
|
||||
@@ -29,6 +33,37 @@ PING_CMD='ping -W 1 -c %d -n -q %s | grep rtt | cut -d " " -f4'
|
||||
|
||||
queue = Queue.Queue()
|
||||
|
||||
|
||||
RRD_CREATE = "%s/%s_%s.rrd " \
|
||||
"DS:ttl:GAUGE:600:U:U "\
|
||||
"RRA:AVERAGE:0.5:1:576 "\
|
||||
"RRA:AVERAGE:0.5:6:336 "\
|
||||
"RRA:AVERAGE:0.5:72:124 "\
|
||||
"RRA:AVERAGE:0.5:288:365"
|
||||
|
||||
RRD_DIR = "../rrd"
|
||||
|
||||
class RrdService():
|
||||
def __init__(self, host, interface):
|
||||
self.host = host
|
||||
self.interface = interface
|
||||
|
||||
def log(self, avg_ping):
|
||||
self.update_rrd(avg_ping)
|
||||
|
||||
def update_rrd(self, avg_ping):
|
||||
self.create_rrd()
|
||||
|
||||
def create_rrd(self):
|
||||
rrd_file = RRD_CREATE % (RRD_DIR, host.hostname, interface.name)
|
||||
if args.debug:
|
||||
print "RRD_FILE : %s " % rrd_file
|
||||
# if not os.system(RRD_CREATE % (RRD_DIR, host.hostname, interface.name)):
|
||||
# if args.debug:
|
||||
# print "Could not create RRD database."
|
||||
# return False
|
||||
return True
|
||||
|
||||
class PingThread(threading.Thread):
|
||||
""" Threaded ping """
|
||||
def __init__(self, host_queue):
|
||||
@@ -55,7 +90,7 @@ class PingThread(threading.Thread):
|
||||
return
|
||||
interface.ip4address.last_contact = datetime.datetime.now()
|
||||
interface.ip4address.ping_avg_rtt = float(res[1])
|
||||
interface.ip4address.save()
|
||||
# interface.ip4address.save()
|
||||
if args.debug:
|
||||
print "%s (%s/%s) : %s" % (host, interface.name, \
|
||||
interface.ip4address.address, res)
|
||||
@@ -100,3 +135,9 @@ for host in hosts:
|
||||
|
||||
# Wait for all threads to finish, eg. queue is empty.
|
||||
queue.join()
|
||||
|
||||
# Finally, we update all hosts.
|
||||
for host in hosts:
|
||||
for interface in host.interface_set.all():
|
||||
print "Saving interface %s " % interface.ip4address
|
||||
interface.ip4address.save()
|
||||
Reference in new issue
Block a user