Monitor HDFS bad block scripts

Source: Internet
Author: User

Recently, a hive computing problem occurs due to bad HDFS blocks. Therefore, a monitoring script is written to monitor bad HDFS blocks. The script is as follows:

#! /Usr/bin/Python #-*-coding: utf8-*-# edit by ericni #20140724 # monitor HDFS upload uptimport sysimport propertyimport sendmailimport re, osreload (sys) sys. setdefaultencoding ('utf-8') If _ name _ = "_ main __": corruptlist = [] cmd = "hadoop fsck-list-corruptfileblocks" Re = OS. popen (CMD) Result = Re. readlines () print result for line in result: If "BLK _" in line and ". trash "not in line: # If" BLK _ "in Lin E: corruptlist. append (line) If Len (corruptlist )! = 0: mailcontent = "" <meta http-equiv = "Content-Type" content = "text/html "; charset = UTF-8> <title> hadoop cluster bad block monitoring </title> <style type = "text/CSS"> body {font-size: 14px; color: #333; background-color: # FFF;} TD {border: 1px solid # c1dad7; padding: "4px 10px"; line-Height: 24px;} table {border-collapse: collapse; width: 96% s ;}. divtd {color: # e28e40 ;}. divcss5 {color: # f00 ;}</style> "% (" % ") mailcontent + =" <P style = "margin: 0; padding: 5px 0; line-Height: 28px; Font: bold 18px/1.5; "> Number of Bad blocks % s, details: </P> <div> <Table Style = "border-collapse: collapse; width: 96% S; "> <tbody> <tr> <TD> <Div class =" divtd "> NO. </div> </TD> <Div class =" divtd "> Block </div> </TD> <Div class = "divtd"> File Information </div> </TD> </tr> "" % (Str (LEN (corruptlist )), "%") id = 1 for clist in corruptlist: Print "blkid is" + clist. split () [0] + "file is" + clist. split () [1] mailcontent + = "<tr>" mailcontent + = "<TD> <div> % S </div> </TD> """ % ID mailcontent + = "" <TD> <div> % S </div> </TD> "% clist. split () [0] mailcontent + = "" <TD> <div> % S </div> </TD> "% clist. split () [1] mailcontent + = "</tr>" "id = ID + 1 mailcontent + =" </tbody> </table> </div> "Print mailcontent mailto = ['[email protected]'] Subject = "haddop cluster bad block monitoring" Sendmail. send_mail_withoutssl (subject, mailcontent. encode ('utf-8'), mailto)

This article from the "Food light blog" blog, please be sure to keep this source http://caiguangguang.blog.51cto.com/1652935/1532988

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.