-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
export: add command to export backup file to txt file #62
Conversation
1023280072
commented
Sep 11, 2023
- add tcpmon/export.go
- add tcpmon/print_metric.go
- add tools/codegen.go to generate tcpmon/print_metric_tsdb.go
- add tcpmon/export.go - add tcpmon/print_metric.go - add tools/codegen.go to generate tcpmon/print_metric_tsdb.go
cmd/export.go
Outdated
hostname := args[1] | ||
|
||
if net.ParseIP(hostname) == nil { | ||
log.Fatal().Msg("Invalid IP address") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hostname 不一定是个 ip
cmd/export.go
Outdated
log.Fatal().Msg("Invalid IP address") | ||
} | ||
|
||
var printer tcpmon.PrintMetric |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该叫 MetricPrinter
cmd/export.go
Outdated
var printer tcpmon.PrintMetric | ||
switch format { | ||
case "tsdb": | ||
printer = tcpmon.TSDBPrintMetric{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上。
cmd/export.go
Outdated
|
||
isEmpty, err := IsDirEmpty(dbDir) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("Check db directory failed, need an empty directory") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里写 need an empty directory
,但是 force = true
的情况又不需要一个空的目录。并且这里 err != nil
的情况下,也并不意味着 need an empty directory
的发生。
cmd/export.go
Outdated
} | ||
defer db.Close() | ||
|
||
if !isEmpty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好像可以直接 DropAll
?因为他肯定是 empty
,或者是有数据,反正不需要判断
cmd/export.go
Outdated
func init() { | ||
exportCmd.Flags().StringVarP(&format, "format", "f", "tsdb", "export backup to txt in this format") | ||
exportCmd.Flags().StringVarP(&dbDir, "db", "d", "/tmp/tcpmon/export/db", "db path to restore backup") | ||
exportCmd.Flags().BoolVarP(&force, "force", "e", false, "force restore, may overwrite files") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
force
一般是 -f
这里冲突的情况,format
通常是可以忽略的,不经常用,所以 format
可能不需要 P
tcpmon/print_metric.go
Outdated
@@ -0,0 +1,7 @@ | |||
package tcpmon | |||
|
|||
type PrintMetric interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上