Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

mt-index-cat: make NameWithTags() callable from template format #1157

Merged
merged 4 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions cmd/mt-index-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,20 @@ func main() {
fmt.Printf("cass config flags:\n\n")
cassFlags.PrintDefaults()
fmt.Println()
fmt.Printf("output: either presets like %v\n", strings.Join(outputs, "|"))
fmt.Printf("output: or custom templates like '{{.Id}} {{.OrgId}} {{.Name}} {{.Metric}} {{.Interval}} {{.Unit}} {{.Mtype}} {{.Tags}} {{.LastUpdate}} {{.Partition}}'\n\n\n")
fmt.Println("You may also use processing functions in templates:")
fmt.Println("pattern: transforms a graphite.style.metric.name into a pattern with wildcards inserted")
fmt.Println(" an operation is randomly selected between: replacing a node with a wildcard, replacing a character with a wildcard, and passthrough")
out.PatternCustomUsage()
fmt.Println("age: subtracts the passed integer (typically .LastUpdate) from the query time")
fmt.Println("roundDuration: formats an integer-seconds duration using aggressive rounding. for the purpose of getting an idea of overal metrics age")
fmt.Println("output:")
fmt.Println()
fmt.Printf(" * presets: %v\n", strings.Join(outputs, "|"))
fmt.Println(" * templates, which may contain:")
fmt.Println(" - fields, e.g. '{{.Id}} {{.OrgId}} {{.Name}} {{.Interval}} {{.Unit}} {{.Mtype}} {{.Tags}} {{.LastUpdate}} {{.Partition}}'")
fmt.Println(" - methods, e.g. '{{.NameWithTags}}' (works basically the same as a field)")
fmt.Println(" - processing functions:")
fmt.Println(" pattern: transforms a graphite.style.metric.name into a pattern with wildcards inserted")
fmt.Println(" an operation is randomly selected between: replacing a node with a wildcard, replacing a character with a wildcard, and passthrough")
out.PatternCustomUsage(" ")
fmt.Println(" age: subtracts the passed integer (typically .LastUpdate) from the query time")
fmt.Println(" roundDuration: formats an integer-seconds duration using aggressive rounding. for the purpose of getting an idea of overal metrics age")
fmt.Println()
fmt.Println()
fmt.Println("EXAMPLES:")
fmt.Println("mt-index-cat -from 60min cass -hosts cassandra:9042 list")
fmt.Println("mt-index-cat -from 60min cass -hosts cassandra:9042 'sumSeries({{.Name | pattern}})'")
Expand Down
2 changes: 1 addition & 1 deletion cmd/mt-index-cat/out/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Template(format string) func(d schema.MetricDefinition) {
tpl := template.Must(template.New("format").Funcs(funcs).Parse(format))

return func(d schema.MetricDefinition) {
err := tpl.Execute(os.Stdout, d)
err := tpl.Execute(os.Stdout, &d)
if err != nil {
panic(err)
}
Expand Down
20 changes: 10 additions & 10 deletions cmd/mt-index-cat/out/tpl_pattern_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ type bucket struct {
fn func(in string) string
}

func PatternCustomUsage() {
fmt.Println("patternCustom: transforms a graphite.style.metric.name into a pattern with wildcards inserted according to rules provided:")
fmt.Println(" patternCustom <chance> <operation>[ <chance> <operation>...]")
fmt.Println(" the chances need to add up to 100")
fmt.Println(" operation is one of:")
fmt.Println(" * pass (passthrough)")
fmt.Println(" * <digit>rcnw (replace a randomly chosen sequence of <digit (0-9)> consecutive nodes with wildcards")
fmt.Println(" * <digit>rccw (replace a randomly chosen sequence of <digit (0-9)> consecutive characters with wildcards")
fmt.Println(" example: {{.Name | patternCustom 15 \"pass\" 40 \"1rcnw\" 15 \"2rcnw\" 10 \"3rcnw\" 10 \"3rccw\" 10 \"2rccw\"}}\\n")
func PatternCustomUsage(indent string) {
fmt.Printf("%spatternCustom: transforms a graphite.style.metric.name into a pattern with wildcards inserted according to rules provided:\n", indent)
fmt.Printf("%s patternCustom <chance> <operation>[ <chance> <operation>...]\n", indent)
fmt.Printf("%s the chances need to add up to 100\n", indent)
fmt.Printf("%s operation is one of:\n", indent)
fmt.Printf("%s * pass (passthrough)\n", indent)
fmt.Printf("%s * <digit>rcnw (replace a randomly chosen sequence of <digit (0-9)> consecutive nodes with wildcards\n", indent)
fmt.Printf("%s * <digit>rccw (replace a randomly chosen sequence of <digit (0-9)> consecutive characters with wildcards\n", indent)
fmt.Printf("%s example: {{.Name | patternCustom 15 \"pass\" 40 \"1rcnw\" 15 \"2rcnw\" 10 \"3rcnw\" 10 \"3rccw\" 10 \"2rccw\"}}\\n\n", indent)
}

// percentage chance, and function
func patternCustom(in ...interface{}) string {
usage := func() {
PatternCustomUsage()
PatternCustomUsage("")
os.Exit(-1)
}

Expand Down
38 changes: 21 additions & 17 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,27 @@ cass config flags:
-write-queue-size int
Max number of metricDefs allowed to be unwritten to cassandra (default 100000)

output: either presets like dump|list|vegeta-render|vegeta-render-patterns
output: or custom templates like '{{.Id}} {{.OrgId}} {{.Name}} {{.Metric}} {{.Interval}} {{.Unit}} {{.Mtype}} {{.Tags}} {{.LastUpdate}} {{.Partition}}'


You may also use processing functions in templates:
pattern: transforms a graphite.style.metric.name into a pattern with wildcards inserted
an operation is randomly selected between: replacing a node with a wildcard, replacing a character with a wildcard, and passthrough
patternCustom: transforms a graphite.style.metric.name into a pattern with wildcards inserted according to rules provided:
patternCustom <chance> <operation>[ <chance> <operation>...]
the chances need to add up to 100
operation is one of:
* pass (passthrough)
* <digit>rcnw (replace a randomly chosen sequence of <digit (0-9)> consecutive nodes with wildcards
* <digit>rccw (replace a randomly chosen sequence of <digit (0-9)> consecutive characters with wildcards
example: {{.Name | patternCustom 15 "pass" 40 "1rcnw" 15 "2rcnw" 10 "3rcnw" 10 "3rccw" 10 "2rccw"}}\n
age: subtracts the passed integer (typically .LastUpdate) from the query time
roundDuration: formats an integer-seconds duration using aggressive rounding. for the purpose of getting an idea of overal metrics age
output:

* presets: dump|list|vegeta-render|vegeta-render-patterns
* templates, which may contain:
- fields, e.g. '{{.Id}} {{.OrgId}} {{.Name}} {{.Interval}} {{.Unit}} {{.Mtype}} {{.Tags}} {{.LastUpdate}} {{.Partition}}'
- methods, e.g. '{{.NameWithTags}}' (works basically the same as a field)
- processing functions:
pattern: transforms a graphite.style.metric.name into a pattern with wildcards inserted
an operation is randomly selected between: replacing a node with a wildcard, replacing a character with a wildcard, and passthrough
patternCustom: transforms a graphite.style.metric.name into a pattern with wildcards inserted according to rules provided:
patternCustom <chance> <operation>[ <chance> <operation>...]
the chances need to add up to 100
operation is one of:
* pass (passthrough)
* <digit>rcnw (replace a randomly chosen sequence of <digit (0-9)> consecutive nodes with wildcards
* <digit>rccw (replace a randomly chosen sequence of <digit (0-9)> consecutive characters with wildcards
example: {{.Name | patternCustom 15 "pass" 40 "1rcnw" 15 "2rcnw" 10 "3rcnw" 10 "3rccw" 10 "2rccw"}}\n
age: subtracts the passed integer (typically .LastUpdate) from the query time
roundDuration: formats an integer-seconds duration using aggressive rounding. for the purpose of getting an idea of overal metrics age


EXAMPLES:
mt-index-cat -from 60min cass -hosts cassandra:9042 list
mt-index-cat -from 60min cass -hosts cassandra:9042 'sumSeries({{.Name | pattern}})'
Expand Down