Complete the code to display the last 10 lines of the Hadoop log file.
tail -n [1] /var/log/hadoop/hadoop.logThe tail -n 10 command shows the last 10 lines of the log file, which is useful for quick troubleshooting.
Complete the command to search for error messages in the Hadoop log file.
grep '[1]' /var/log/hadoop/hadoop.log
info or debug shows too much detail.warning might miss actual errors.The keyword error helps find error messages in the log for troubleshooting.
Fix the error in the command to continuously monitor the Hadoop log file.
tail [1] /var/log/hadoop/hadoop.log-n only shows a fixed number of lines and exits.-r reverses the output order, not follow.The -f option makes tail follow the file, showing new lines as they are added.
Fill both blanks to create a dictionary of log levels and their counts from a log file.
import collections log_counts = [1](line.split()[2] for line in open('/var/log/hadoop/hadoop.log')) print(log_counts.[2]())
defaultdict alone does not count automatically.items() returns all items but not sorted by frequency.collections.Counter counts occurrences of log levels. most_common() shows counts sorted by frequency.
Fill all three blanks to filter and print unique IP addresses from Hadoop access logs.
with open('/var/log/hadoop/access.log') as f: ips = set() for line in f: if '[1]' in line: ip = line.split()[[2]] ips.[3](ip) print(ips)
POST instead of GET filters different requests.append instead of add on a set causes errors.This code filters lines with GET requests, extracts the IP address at index 0, and adds it to a set to keep unique IPs.