Resolve DPISDN-34 "Feature "
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var coredump_config types.Coredump_config
|
var coredump_config types.Coredump_config
|
||||||
|
var percent int64
|
||||||
|
|
||||||
func argsJudge() error {
|
func argsJudge() error {
|
||||||
|
|
||||||
@@ -57,32 +58,18 @@ func argsJudge() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// judge disk's space is sufficient or not
|
// judge disk's space is sufficient or not
|
||||||
func isDiskSufficient(pipe_config types.Pipeconfig) (bool, error) {
|
func isDiskSufficient(pipe_config types.Pipeconfig) (bool, string, error) {
|
||||||
percent, err := strconv.ParseInt(pipe_config.Total_file_mem_limit[:len(pipe_config.Total_file_mem_limit)-1], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
wd := pipe_config.Storage
|
wd := pipe_config.Storage
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
diskinfo, err := disk.Usage(wd)
|
diskinfo, err := disk.Usage(wd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, "", err
|
||||||
}
|
|
||||||
data, err := json.MarshalIndent(diskinfo, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
info := fmt.Sprintf("diskinfo:%s", string(data))
|
|
||||||
journal.Print(journal.PriInfo, info)
|
|
||||||
}
|
}
|
||||||
usage := int64(math.Floor(diskinfo.UsedPercent + 0.5))
|
usage := int64(math.Floor(diskinfo.UsedPercent + 0.5))
|
||||||
info := fmt.Sprintf("usage:%d,limited:%d", usage, percent)
|
info := fmt.Sprintf("usage:%d,limited:%d", usage, percent)
|
||||||
journal.Print(journal.PriInfo, info)
|
|
||||||
if usage >= percent {
|
if usage >= percent {
|
||||||
return false, nil
|
return false, info, nil
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// create dir to storage coredump file and coredump info
|
// create dir to storage coredump file and coredump info
|
||||||
@@ -175,8 +162,7 @@ func writeCoreDumpToFile(config types.Coredump_config, pipe_config types.Pipecon
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
buf := make([]byte, 1024*1024)
|
buf := make([]byte, 10*1024*1024)
|
||||||
nums := 0
|
|
||||||
for {
|
for {
|
||||||
n, err := os.Stdin.Read(buf)
|
n, err := os.Stdin.Read(buf)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
@@ -189,9 +175,7 @@ func writeCoreDumpToFile(config types.Coredump_config, pipe_config types.Pipecon
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nums += 1
|
flag, _, err := isDiskSufficient(pipe_config)
|
||||||
if nums >= 10 {
|
|
||||||
flag, err := isDiskSufficient(pipe_config)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, "Can't judge disk's space is sufficient or not. "+err.Error())
|
journal.Print(journal.PriErr, "Can't judge disk's space is sufficient or not. "+err.Error())
|
||||||
return err
|
return err
|
||||||
@@ -199,15 +183,15 @@ func writeCoreDumpToFile(config types.Coredump_config, pipe_config types.Pipecon
|
|||||||
if !flag {
|
if !flag {
|
||||||
return errors.New("Disk space exceeds limit when writing coredump!")
|
return errors.New("Disk space exceeds limit when writing coredump!")
|
||||||
}
|
}
|
||||||
nums = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleCrash(pid int, procfsDir string, mdFilename string) bool {
|
func HandleCrash(pid int, procfsDir string, mdFilename string) bool {
|
||||||
journal.Print(journal.PriInfo, "start convert to minidump")
|
journal.Print(journal.PriInfo, "start convert to minidump")
|
||||||
return bool(C.HandleCrash(C.pid_t(pid), C.CString(procfsDir), C.CString(mdFilename)))
|
return bool(C.HandleCrash(C.pid_t(pid), C.CString(procfsDir), C.CString(mdFilename)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeMiniDumpToFile(config types.Coredump_config) error {
|
func writeMiniDumpToFile(config types.Coredump_config) error {
|
||||||
filename := fmt.Sprintf("%s/%s_%s_%d.minidump", config.Storage, config.Initial_ns_pid, config.Process_ns_pid, config.Timestamp)
|
filename := fmt.Sprintf("%s/%s_%s_%d.minidump", config.Storage, config.Initial_ns_pid, config.Process_ns_pid, config.Timestamp)
|
||||||
pid, err := strconv.Atoi(config.Initial_ns_pid)
|
pid, err := strconv.Atoi(config.Initial_ns_pid)
|
||||||
@@ -219,15 +203,9 @@ func writeMiniDumpToFile(config types.Coredump_config) error {
|
|||||||
return errors.New("can not convert to minidump")
|
return errors.New("can not convert to minidump")
|
||||||
}
|
}
|
||||||
journal.Print(journal.PriInfo, "end convert to minidump")
|
journal.Print(journal.PriInfo, "end convert to minidump")
|
||||||
// cmd := exec.Command("/opt/tsg/coredump/bin/core_handler", config.Initial_ns_pid, filename)
|
|
||||||
// cmd.Stdin = os.Stdin
|
|
||||||
// output, err := cmd.Output()
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// fmt.Println(string(output))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func compress(config types.Coredump_config) error {
|
func compress(config types.Coredump_config) error {
|
||||||
// Create a new zip archive.
|
// Create a new zip archive.
|
||||||
filename := fmt.Sprintf("%s_%s_%d.coredump", config.Initial_ns_pid, config.Process_ns_pid, config.Timestamp)
|
filename := fmt.Sprintf("%s_%s_%d.coredump", config.Initial_ns_pid, config.Process_ns_pid, config.Timestamp)
|
||||||
@@ -274,9 +252,8 @@ func compress(config types.Coredump_config) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func main() {
|
|
||||||
info := fmt.Sprintf("start handle coredump")
|
func init() {
|
||||||
journal.Print(journal.PriInfo, info)
|
|
||||||
flag.StringVar(&coredump_config.Initial_ns_pid, "P", "", "initial ns pid")
|
flag.StringVar(&coredump_config.Initial_ns_pid, "P", "", "initial ns pid")
|
||||||
flag.StringVar(&coredump_config.Process_ns_pid, "p", "", "process ns pid")
|
flag.StringVar(&coredump_config.Process_ns_pid, "p", "", "process ns pid")
|
||||||
flag.StringVar(&coredump_config.Process_exe_path, "E", "", "pathname of executable process")
|
flag.StringVar(&coredump_config.Process_exe_path, "E", "", "pathname of executable process")
|
||||||
@@ -285,13 +262,15 @@ func main() {
|
|||||||
flag.StringVar(&coredump_config.GID, "g", "", "Numeric real GID of dumped process.")
|
flag.StringVar(&coredump_config.GID, "g", "", "Numeric real GID of dumped process.")
|
||||||
flag.IntVar(&coredump_config.Signal, "s", -1, "Number of signal causing dump")
|
flag.IntVar(&coredump_config.Signal, "s", -1, "Number of signal causing dump")
|
||||||
flag.StringVar(&coredump_config.UID, "u", "", "Numeric real UID of dumped process.")
|
flag.StringVar(&coredump_config.UID, "u", "", "Numeric real UID of dumped process.")
|
||||||
flag.Parse()
|
}
|
||||||
|
|
||||||
|
func start() {
|
||||||
var err error
|
var err error
|
||||||
coredump_config.Hostname, err = os.Hostname()
|
coredump_config.Hostname, err = os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, err.Error())
|
journal.Print(journal.PriErr, err.Error())
|
||||||
}
|
}
|
||||||
info = fmt.Sprintf("initialize command line parameters. -P=%s -p=%s -E=%s -C=%s -t=%d -g=%s -h=%s -s=%d -u=%s", coredump_config.Initial_ns_pid, coredump_config.Process_ns_pid, coredump_config.Process_exe_path, coredump_config.Corepipe_config_path, coredump_config.Timestamp, coredump_config.GID, coredump_config.Hostname, coredump_config.Signal, coredump_config.UID)
|
info := fmt.Sprintf("initialize command line parameters. -P=%s -p=%s -E=%s -C=%s -t=%d -g=%s -h=%s -s=%d -u=%s", coredump_config.Initial_ns_pid, coredump_config.Process_ns_pid, coredump_config.Process_exe_path, coredump_config.Corepipe_config_path, coredump_config.Timestamp, coredump_config.GID, coredump_config.Hostname, coredump_config.Signal, coredump_config.UID)
|
||||||
journal.Print(journal.PriInfo, info)
|
journal.Print(journal.PriInfo, info)
|
||||||
coredump_config.Process_exe_path = strings.Replace(coredump_config.Process_exe_path, "!", "/", -1)
|
coredump_config.Process_exe_path = strings.Replace(coredump_config.Process_exe_path, "!", "/", -1)
|
||||||
//Judge agrs is correct or not.
|
//Judge agrs is correct or not.
|
||||||
@@ -316,12 +295,20 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//judge disk usage
|
percent, err = strconv.ParseInt(pipe_config.Total_file_mem_limit[:len(pipe_config.Total_file_mem_limit)-1], 10, 32)
|
||||||
flag, err := isDiskSufficient(pipe_config)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, err.Error())
|
journal.Print(journal.PriErr, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//judge disk usage
|
||||||
|
flag, info, err := isDiskSufficient(pipe_config)
|
||||||
|
if err != nil {
|
||||||
|
journal.Print(journal.PriErr, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if info != "" {
|
||||||
|
journal.Print(journal.PriInfo, info)
|
||||||
|
}
|
||||||
if !flag {
|
if !flag {
|
||||||
journal.Print(journal.PriErr, "Disk space exceeds limit")
|
journal.Print(journal.PriErr, "Disk space exceeds limit")
|
||||||
return
|
return
|
||||||
@@ -385,11 +372,14 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, err.Error())
|
journal.Print(journal.PriErr, err.Error())
|
||||||
}
|
}
|
||||||
flag, err = isDiskSufficient(pipe_config)
|
flag, info, err = isDiskSufficient(pipe_config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, "Can't judge disk's space is sufficient or not. "+err.Error())
|
journal.Print(journal.PriErr, "Can't judge disk's space is sufficient or not. "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if info != "" {
|
||||||
|
journal.Print(journal.PriInfo, info)
|
||||||
|
}
|
||||||
if !flag {
|
if !flag {
|
||||||
journal.Print(journal.PriErr, "Disk space exceeds limit after write coredump!")
|
journal.Print(journal.PriErr, "Disk space exceeds limit after write coredump!")
|
||||||
err := os.RemoveAll(pipe_config.Storage)
|
err := os.RemoveAll(pipe_config.Storage)
|
||||||
@@ -401,3 +391,11 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
info := fmt.Sprintf("start handle coredump")
|
||||||
|
journal.Print(journal.PriInfo, info)
|
||||||
|
flag.Parse()
|
||||||
|
start()
|
||||||
|
journal.Print(journal.PriInfo, "finish to write coredump")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user