-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ceph-crash runs from systemd and watches /var/lib/ceph/crash for crashdumps, posting them to the mgrs using the mgr's crash plugin Signed-off-by: Dan Mick <[email protected]>
- Loading branch information
Showing
8 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!@PYTHON_EXECUTABLE@ | ||
# -*- mode:python -*- | ||
# vim: ts=4 sw=4 smarttab expandtab | ||
|
||
import argparse | ||
import logging | ||
import os | ||
import subprocess | ||
import sys | ||
import time | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
'-p', '--path', default='/var/lib/ceph/crash', | ||
help='base path to monitor for crash dumps') | ||
parser.add_argument( | ||
'-d', '--delay', default=10.0, type=float, | ||
help='minutes to delay between scans (0 to exit after one)', | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def post_crash(path): | ||
pr = subprocess.Popen( | ||
args=['timeout', '30', 'ceph', 'crash', 'post', '-i', '-'], | ||
stdin=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
f = open(os.path.join(path, 'meta'), 'r') | ||
stdout, stderr = pr.communicate(input=f.read()) | ||
rc = pr.wait() | ||
f.close() | ||
if rc != 0: | ||
log.warning('post %s failed: %s' % (path, stderr)) | ||
return rc | ||
|
||
|
||
def scrape_path(path): | ||
for p in os.listdir(path): | ||
crashpath = os.path.join(path, p) | ||
metapath = os.path.join(crashpath, 'meta') | ||
donepath = os.path.join(crashpath, 'done') | ||
if os.path.isfile(metapath): | ||
if not os.path.isfile(donepath): | ||
# hang out just for a bit; either we interrupted the dump | ||
# or the daemon crashed before finishing it | ||
time.sleep(1) | ||
if not os.path.isfile(donepath): | ||
return | ||
# ok, we can process this one | ||
rc = post_crash(crashpath) | ||
if rc == 0: | ||
os.rename(crashpath, os.path.join(path, 'posted/', p)) | ||
log.debug( | ||
"posted %s and renamed %s -> %s " % | ||
(metapath, p, os.path.join('posted/', p)) | ||
) | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
postdir = os.path.join(args.path, 'posted') | ||
|
||
while not os.path.isdir(postdir): | ||
log.error("%s does not exist; please create" % postdir) | ||
time.sleep(30) | ||
|
||
log.info("monitoring path %s, delay %ds" % (args.path, args.delay * 60.0)) | ||
while True: | ||
scrape_path(args.path) | ||
if args.delay == 0: | ||
sys.exit(0) | ||
time.sleep(args.delay * 60) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Ceph crash dump collector | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/bin/ceph-crash | ||
Restart=always | ||
RestartSec=10 | ||
StartLimitInterval=10min | ||
StartLimitBurst=10 | ||
|
||
[Install] | ||
WantedBy=ceph.target |