Commit 272c350b authored by Timothy Stack's avatar Timothy Stack

Checkpoint some nfstrace fixes. It should behave much better now, but

still needs some work.
parent a467a28a
/*
* $Id: nfs_v2.c,v 1.1 2005-11-28 15:44:00 stack Exp $
* $Id: nfs_v2.c,v 1.2 2005-11-30 17:30:57 stack Exp $
*/
#ifdef HAVE_CONFIG_H
......@@ -32,7 +32,7 @@ static int compute_pct (int n, int d);
#define PRINT_STATUS(s, p) \
if (p) { if ((s) == NFS_OK) { fprintf (OutFile, "OK "); } \
else { fprintf (OutFile, "%x ", (s)); } \
else { fprintf (OutFile, "%d ", (s)); } \
}
/*
......@@ -445,13 +445,13 @@ u_int32_t *print_sattr2 (u_int32_t *p, u_int32_t *e, int print)
fprintf (OutFile, "mode %x ", ntohl (p [0]));
}
if (ntohl (p [1]) != -1) {
fprintf (OutFile, "uid %x ", ntohl (p [1]));
fprintf (OutFile, "uid %d ", ntohl (p [1]));
}
if (ntohl (p [2]) != -1) {
fprintf (OutFile, "gid %x ", ntohl (p [2]));
fprintf (OutFile, "gid %d ", ntohl (p [2]));
}
if (ntohl (p [3]) != -1) {
fprintf (OutFile, "size %x ", ntohl (p [3]));
fprintf (OutFile, "size %d ", ntohl (p [3]));
}
/*
......@@ -570,8 +570,8 @@ u_int32_t *print_fattr2 (u_int32_t *p, u_int32_t *e, int print)
fprintf (OutFile, "ftype %x ", ntohl (p [0])); /* ftype */
fprintf (OutFile, "mode %x ", ntohl (p [1])); /* mode */
fprintf (OutFile, "nlink %x ", ntohl (p [2])); /* nlink */
fprintf (OutFile, "uid %x ", ntohl (p [3])); /* uid */
fprintf (OutFile, "gid %x ", ntohl (p [4])); /* gid */
fprintf (OutFile, "uid %d ", ntohl (p [3])); /* uid */
fprintf (OutFile, "gid %d ", ntohl (p [4])); /* gid */
fprintf (OutFile, "size %x ", ntohl (p [5])); /* size */
fprintf (OutFile, "blksize %x ", ntohl (p [6])); /* blksize */
fprintf (OutFile, "rdev %x ", ntohl (p [7])); /* rdev */
......
/*
* $Id: nfs_v3.c,v 1.1 2005-11-28 15:44:00 stack Exp $
* $Id: nfs_v3.c,v 1.2 2005-11-30 17:30:57 stack Exp $
*
*/
......@@ -959,10 +959,10 @@ int print_sattr3_x (sattr3 *s)
fprintf (OutFile, "mode %x ", s->mode.set_mode3_u.mode);
}
if (s->uid.set_it) {
fprintf (OutFile, "uid %x ", s->uid.set_uid3_u.uid);
fprintf (OutFile, "uid %d ", s->uid.set_uid3_u.uid);
}
if (s->gid.set_it) {
fprintf (OutFile, "gid %x ", s->gid.set_gid3_u.gid);
fprintf (OutFile, "gid %d ", s->gid.set_gid3_u.gid);
}
if (s->size.set_it) {
print_uint64_x ((u_int32_t *) &(s->size.set_size3_u.size),
......
/*
* $Id: nfsrecord.c,v 1.1 2005-11-28 15:44:00 stack Exp $
* $Id: nfsrecord.c,v 1.2 2005-11-30 17:30:57 stack Exp $
*/
#ifdef HAVE_CONFIG_H
......@@ -471,9 +471,9 @@ int processPacket (struct pcap_pkthdr *h, /* Captured stuff */
fprintf (OutFile, ".%.4x ", 0xffff & record->dstPort);
fprintf (OutFile, "%c ", proto == IPPROTO_TCP ? 'T' : 'U');
fprintf (OutFile, "C%d %x 1 mnt fn \"%s\" ", record->nfsVersion, ntohl (rpc_b->rm_xid), payload_data);
fprintf (OutFile, "C%d %d 1 mnt fn \"%s\" ", record->nfsVersion, ntohl (rpc_b->rm_xid), payload_data);
if (euid != -1 && egid != -1) {
fprintf (OutFile, "euid %x egid %x ",
fprintf (OutFile, "euid %d egid %d ",
euid, egid);
}
fprintf (OutFile, "con = %d len = %d",
......@@ -490,7 +490,7 @@ int processPacket (struct pcap_pkthdr *h, /* Captured stuff */
fprintf (OutFile, ".%.4x ", 0xffff & record->dstPort);
fprintf (OutFile, "%c ", proto == IPPROTO_TCP ? 'T' : 'U');
fprintf (OutFile, "R%d %x ", record->nfsVersion, ntohl (rpc_b->rm_xid));
fprintf (OutFile, "R%d %d ", record->nfsVersion, ntohl (rpc_b->rm_xid));
if (record->rpcStatus == 0) {
fprintf(OutFile, "1 mnt OK ");
if (record->nfsVersion == 1 || record->nfsVersion == 2) {
......@@ -502,9 +502,9 @@ int processPacket (struct pcap_pkthdr *h, /* Captured stuff */
}
}
else {
fprintf(OutFile, "1 mnt %x ", record->rpcStatus);
fprintf(OutFile, "1 mnt %d ", record->rpcStatus);
}
fprintf (OutFile, "status=%x ", record->rpcStatus);
fprintf (OutFile, "status=%d ", record->rpcStatus);
fprintf (OutFile, "pl = %d ", payload_len);
fprintf (OutFile, "con = %d len = %d",
......@@ -520,7 +520,7 @@ int processPacket (struct pcap_pkthdr *h, /* Captured stuff */
tot_len - consumed);
if (euid != -1 && egid != -1) {
fprintf (OutFile, "euid %x egid %x ",
fprintf (OutFile, "euid %d egid %d ",
euid, egid);
}
......@@ -623,7 +623,7 @@ void printRecord (nfs_pkt_t *record, void *xdr, u_int32_t payload_len,
fprintf (OutFile, "RU%d\n", record->nfsVersion);
}
fprintf (OutFile, "status=%x ", record->rpcStatus);
fprintf (OutFile, "status=%d ", record->rpcStatus);
fprintf (OutFile, "pl = %d ", payload_len);
}
......
This diff is collapsed.
......@@ -10,7 +10,14 @@ import MySQLdb
DBNAME = "nfsdb"
DBUSER = "nfstrace"
DBPASS = open("/var/nfstrace/dbpass").read().strip()
try:
DBPASS = open("/var/nfstrace/dbpass").read().strip()
pass
except IOError:
sys.stderr.write("error: permission denied\n")
sys.exit(1)
pass
VERBOSITY = 1
......@@ -113,8 +120,6 @@ def do_gc(args):
"(" + ",".join(("%s",) * len(ips)) + ")", ips)
pass
cur.execute("DELETE FROM handle_map where complete=0")
for lpc in range(0, len(ips)):
if args[lpc] != ips[lpc]:
cur.execute("REPLACE INTO node_ids (node_id, node_ip) VALUES "
......@@ -123,7 +128,7 @@ def do_gc(args):
pass
pass
# con.commit();
con.commit();
return retval
......@@ -153,17 +158,26 @@ def do_get(args):
get_usage()
return 2
cur.execute("select distinct hm.fn,fa.fh,"
missing = 0
cur.execute("select hm.fn,"
" IFNULL(MAX(fa.last_access)>MAX(fd.last_remove),1) "
" from file_access as fa "
"left join file_dropped as fd on fa.fh=fd.fh "
"left join handle_map as hm on hm.fh=fa.fh "
"where fa.node_ip in (" + ",".join(("%s",) * len(args))
+ ") group by fa.fh", args)
for (fn, fh, alive) in cur:
+ ") group by hm.fn", args)
for (fn, alive) in cur:
if alive and fn:
print fn
pass
elif not fn:
missing += 1
pass
pass
if missing > 0:
print `missing` + " unknown file(s) accessed."
pass
return retval
......@@ -193,18 +207,34 @@ def do_stats(args):
return 2
print "Top readers:"
cur.execute("select r.node_ip,ni.node_id,count(1) as wc from reads as r "
"left join node_ids as ni on ni.node_ip=r.node_ip "
cur.execute("select r.node_ip,count(1) as wc from reads as r "
"where timestamp > (UNIX_TIMESTAMP() - (60 * %s)) "
"group by r.node_ip order by wc desc limit %s",
(over_last, row_count))
for (node_ip,node_id,count) in cur:
if not node_id:
readers = cur.fetchall()
for (node_ip,count) in readers:
cur.execute("select node_id from node_ids where node_ip=%s",
(node_ip,))
node_id = cur.fetchone()
if node_id:
node_id = node_id[0];
pass
else:
he = socket.gethostbyaddr(node_ip)
node_id = he[0].split('.')[0]
pass
print " %8d\t%s" % (count, node_id)
pass
print "Top read files:"
cur.execute("select hm.fn,count(1) as rc from reads as r "
"left join handle_map as hm on hm.fh=r.fh "
"where timestamp > (UNIX_TIMESTAMP() - (60 * %s)) "
"group by r.fh order by rc desc limit %s",
(over_last, row_count))
for (fn,count) in cur:
print " %8d\t%s" % (count, fn or "<unknown>")
pass
print "Top writers:"
cur.execute("select w.node_ip,ni.node_id,count(1) as wc,sum(amount) "
......@@ -221,6 +251,16 @@ def do_stats(args):
print " %8d\t%16d\t%s" % (count, amount, node_id)
pass
print "Top written files:"
cur.execute("select hm.fn,count(1) as wc from writes as w "
"left join handle_map as hm on hm.fh=w.fh "
"where timestamp > (UNIX_TIMESTAMP() - (60 * %s)) "
"group by w.fh order by wc desc limit %s",
(over_last, row_count))
for (fn,count) in cur:
print " %8d\t%s" % (count, fn or "<unknown>")
pass
return retval
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment