forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
136 lines (118 loc) · 3.75 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"flag"
"fmt"
"os"
_ "github.com/influxdata/influxdb/tsdb/engine"
)
func usage() {
println(`Usage: influx_inspect <command> [options]
Displays detailed information about InfluxDB data files.
`)
println(`Commands:
dumptsm - dumps low-level details about tsm1 files.
export - exports a tsm file to line protocol
report - displays a shard level report`)
println()
}
func main() {
flag.Usage = usage
flag.Parse()
if len(flag.Args()) == 0 {
flag.Usage()
os.Exit(0)
}
switch flag.Args()[0] {
case "report":
opts := &reportOpts{}
fs := flag.NewFlagSet("report", flag.ExitOnError)
fs.StringVar(&opts.pattern, "pattern", "", "Include only files matching a pattern")
fs.BoolVar(&opts.detailed, "detailed", false, "Report detailed cardinality estimates")
fs.Usage = func() {
println("Usage: influx_inspect report [options]\n\n Displays shard level report")
println()
println("Options:")
fs.PrintDefaults()
}
if err := fs.Parse(flag.Args()[1:]); err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
opts.dir = fs.Arg(0)
cmdReport(opts)
case "dumptsmdev":
fmt.Fprintf(os.Stderr, "warning: dumptsmdev is deprecated, use dumptsm instead.\n")
fallthrough
case "dumptsm":
var dumpAll bool
opts := &tsdmDumpOpts{}
fs := flag.NewFlagSet("file", flag.ExitOnError)
fs.BoolVar(&opts.dumpIndex, "index", false, "Dump raw index data")
fs.BoolVar(&opts.dumpBlocks, "blocks", false, "Dump raw block data")
fs.BoolVar(&dumpAll, "all", false, "Dump all data. Caution: This may print a lot of information")
fs.StringVar(&opts.filterKey, "filter-key", "", "Only display index and block data match this key substring")
fs.Usage = func() {
println("Usage: influx_inspect dumptsm [options] <path>\n\n Dumps low-level details about tsm1 files.")
println()
println("Options:")
fs.PrintDefaults()
os.Exit(0)
}
if err := fs.Parse(flag.Args()[1:]); err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
if len(fs.Args()) == 0 || fs.Args()[0] == "" {
fmt.Printf("TSM file not specified\n\n")
fs.Usage()
fs.PrintDefaults()
os.Exit(1)
}
opts.path = fs.Args()[0]
opts.dumpBlocks = opts.dumpBlocks || dumpAll || opts.filterKey != ""
opts.dumpIndex = opts.dumpIndex || dumpAll || opts.filterKey != ""
cmdDumpTsm1(opts)
case "verify":
var path string
fs := flag.NewFlagSet("verify", flag.ExitOnError)
fs.StringVar(&path, "dir", os.Getenv("HOME")+"/.influxdb", "Root storage path. [$HOME/.influxdb]")
fs.Usage = func() {
println("Usage: influx_inspect verify [options]\n\n verifies the the checksum of shards")
println()
println("Options:")
fs.PrintDefaults()
}
if err := fs.Parse(flag.Args()[1:]); err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
cmdVerify(path)
case "export":
var path, out, db, rp string
var compress bool
fs := flag.NewFlagSet("export", flag.ExitOnError)
fs.StringVar(&path, "dir", os.Getenv("HOME")+"/.influxdb", "Root storage path. [$HOME/.influxdb]")
fs.StringVar(&out, "out", os.Getenv("HOME")+"/.influxdb/export", "Destination file to export to")
fs.StringVar(&db, "db", "", "Optional: the database to export")
fs.StringVar(&rp, "rp", "", "Optional: the retention policy to export (requires db parameter to be specified)")
fs.BoolVar(&compress, "compress", false, "Compress the output")
fs.Usage = func() {
println("Usage: influx_inspect export [options]\n\n exports TSM files into InfluxDB line protocol format")
println()
println("Options:")
fs.PrintDefaults()
}
if err := fs.Parse(flag.Args()[1:]); err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
c := newCmdExport(path, out, db, rp, compress)
if err := c.run(); err != nil {
fmt.Println(err)
os.Exit(1)
}
default:
flag.Usage()
os.Exit(1)
}
}