blob: 7acfb5e97d41123b3858f1092a69e47aa3a09b80 [file] [log] [blame]
Sean Dague97fcc7b2014-06-16 17:24:14 -04001#!/usr/bin/env python
2#
3# Copyright 2014 Hewlett-Packard Development Company, L.P.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17"""Dump the state of the world for post mortem."""
18
19import argparse
20import datetime
Sean Dague737e9422015-05-12 19:51:39 -040021import fnmatch
Sean Dague97fcc7b2014-06-16 17:24:14 -040022import os
23import os.path
24import sys
25
26
27def get_options():
28 parser = argparse.ArgumentParser(
29 description='Dump world state for debugging')
30 parser.add_argument('-d', '--dir',
31 default='.',
32 help='Output directory for worlddump')
33 return parser.parse_args()
34
35
36def filename(dirname):
37 now = datetime.datetime.utcnow()
38 return os.path.join(dirname, now.strftime("worlddump-%Y-%m-%d-%H%M%S.txt"))
39
40
41def warn(msg):
42 print "WARN: %s" % msg
43
44
Sean Dague60a14052015-05-11 14:53:39 -040045def _dump_cmd(cmd):
46 print cmd
47 print "-" * len(cmd)
48 print
49 print os.popen(cmd).read()
50
51
52def _header(name):
53 print
54 print name
55 print "=" * len(name)
56 print
57
58
Sean Dague97fcc7b2014-06-16 17:24:14 -040059def disk_space():
60 # the df output
Sean Dague60a14052015-05-11 14:53:39 -040061 _header("File System Summary")
62
Sean Dague97fcc7b2014-06-16 17:24:14 -040063 dfraw = os.popen("df -Ph").read()
64 df = [s.split() for s in dfraw.splitlines()]
65 for fs in df:
66 try:
67 if int(fs[4][:-1]) > 95:
68 warn("Device %s (%s) is %s full, might be an issue" % (
69 fs[0], fs[5], fs[4]))
70 except ValueError:
71 # if it doesn't look like an int, that's fine
72 pass
73
74 print dfraw
75
76
Sean Dague168b7c22015-05-07 08:57:28 -040077def iptables_dump():
78 tables = ['filter', 'nat', 'mangle']
Sean Dague60a14052015-05-11 14:53:39 -040079 _header("IP Tables Dump")
80
Sean Dague168b7c22015-05-07 08:57:28 -040081 for table in tables:
Sean Dague60a14052015-05-11 14:53:39 -040082 _dump_cmd("sudo iptables --line-numbers -L -nv -t %s" % table)
83
84
85def network_dump():
86 _header("Network Dump")
87
88 _dump_cmd("brctl show")
89 _dump_cmd("arp -n")
90 _dump_cmd("ip addr")
91 _dump_cmd("ip link")
92 _dump_cmd("ip route")
Sean Dague168b7c22015-05-07 08:57:28 -040093
94
Sean Dague97fcc7b2014-06-16 17:24:14 -040095def process_list():
Sean Dague60a14052015-05-11 14:53:39 -040096 _header("Process Listing")
97 _dump_cmd("ps axo "
98 "user,ppid,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,args")
Sean Dague97fcc7b2014-06-16 17:24:14 -040099
100
Sean Dague737e9422015-05-12 19:51:39 -0400101def compute_consoles():
102 _header("Compute consoles")
103 for root, dirnames, filenames in os.walk('/opt/stack'):
104 for filename in fnmatch.filter(filenames, 'console.log'):
105 fullpath = os.path.join(root, filename)
106 _dump_cmd("sudo cat %s" % fullpath)
107
108
Joe Gordon2ebe9932015-06-07 16:57:34 +0900109def guru_meditation_report():
110 _header("nova-compute Guru Meditation Report")
111 _dump_cmd("kill -s USR1 `pgrep nova-compute`")
112 print "guru meditation report in nova-compute log"
113
114
Sean Dague97fcc7b2014-06-16 17:24:14 -0400115def main():
116 opts = get_options()
117 fname = filename(opts.dir)
118 print "World dumping... see %s for details" % fname
119 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
120 with open(fname, 'w') as f:
121 os.dup2(f.fileno(), sys.stdout.fileno())
122 disk_space()
123 process_list()
Sean Dague60a14052015-05-11 14:53:39 -0400124 network_dump()
Sean Dague168b7c22015-05-07 08:57:28 -0400125 iptables_dump()
Sean Dague737e9422015-05-12 19:51:39 -0400126 compute_consoles()
Joe Gordon2ebe9932015-06-07 16:57:34 +0900127 guru_meditation_report()
Sean Dague97fcc7b2014-06-16 17:24:14 -0400128
129
130if __name__ == '__main__':
131 try:
132 sys.exit(main())
133 except KeyboardInterrupt:
134 sys.exit(1)