Skip to content

Commit

Permalink
update docs and tickdoc to use config
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Mar 25, 2016
1 parent 4338bfd commit 1b5ac4d
Show file tree
Hide file tree
Showing 27 changed files with 467 additions and 319 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ A simple TICKscript that alerts on high cpu usage looks like this:

```javascript
stream
.from().measurement('cpu_usage_idle')
.groupBy('host')
.window()
|from()
.measurement('cpu_usage_idle')
.groupBy('host')
|window()
.period(1m)
.every(1m)
.mean('value')
.eval(lambda: 100.0 - "mean")
|mean('value')
|eval(lambda: 100.0 - "mean")
.as('used')
.alert()
|alert()
.message('{{ .Level}}: {{ .Name }}/{{ index .Tags "host" }} has high cpu usage: {{ index .Fields "used" }}')
.warn(lambda: "used" > 70.0)
.crit(lambda: "used" > 85.0)
Expand All @@ -63,7 +64,6 @@ stream

// PagerDuty
.pagerDuty()

```

Place the above script into a file `cpu_alert.tick` then run these commands to start the task:
Expand Down
157 changes: 84 additions & 73 deletions cmd/kapacitord/run/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func TestServer_DefineTask(t *testing.T) {
RetentionPolicy: "default",
},
}
tick := "stream.from().measurement('test')"
tick := `stream
|from()
.measurement('test')
`
r, err := s.DefineTask(name, ttype, tick, dbrps)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -123,7 +126,10 @@ func TestServer_EnableTask(t *testing.T) {
RetentionPolicy: "default",
},
}
tick := "stream.from().measurement('test')"
tick := `stream
|from()
.measurement('test')
`
r, err := s.DefineTask(name, ttype, tick, dbrps)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -192,7 +198,10 @@ func TestServer_DisableTask(t *testing.T) {
RetentionPolicy: "default",
},
}
tick := "stream.from().measurement('test')"
tick := `stream
|from()
.measurement('test')
`
r, err := s.DefineTask(name, ttype, tick, dbrps)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -262,7 +271,10 @@ func TestServer_DeleteTask(t *testing.T) {
RetentionPolicy: "default",
},
}
tick := "stream.from().measurement('test')"
tick := `stream
|from()
.measurement('test')
`
r, err := s.DefineTask(name, ttype, tick, dbrps)
if err != nil {
t.Fatal(err)
Expand All @@ -288,7 +300,10 @@ func TestServer_ListTasks(t *testing.T) {
count := 10

ttype := "stream"
tick := "stream.from().measurement('test')"
tick := `stream
|from()
.measurement('test')
`
dbrps := []kapacitor.DBRP{
{
Database: "mydb",
Expand Down Expand Up @@ -356,14 +371,14 @@ func TestServer_StreamTask(t *testing.T) {
Database: "mydb",
RetentionPolicy: "myrp",
}}
tick := `
stream
.from().measurement('test')
.window()
.period(10s)
.every(10s)
.count('value')
.httpOut('count')
tick := `stream
|from()
.measurement('test')
|window()
.period(10s)
.every(10s)
|count('value')
|httpOut('count')
`

r, err := s.DefineTask(name, ttype, tick, dbrps)
Expand Down Expand Up @@ -458,13 +473,12 @@ func TestServer_BatchTask(t *testing.T) {
Database: "mydb",
RetentionPolicy: "myrp",
}}
tick := `
batch
.query(' SELECT value from mydb.myrp.cpu ')
.period(5ms)
.every(5ms)
.count('value')
.httpOut('count')
tick := `batch
|query(' SELECT value from mydb.myrp.cpu ')
.period(5ms)
.every(5ms)
|count('value')
|httpOut('count')
`

r, err := s.DefineTask(name, ttype, tick, dbrps)
Expand Down Expand Up @@ -519,13 +533,12 @@ func TestServer_InvalidBatchTask(t *testing.T) {
Database: "mydb",
RetentionPolicy: "myrp",
}}
tick := `
batch
.query(' SELECT value from unknowndb.unknownrp.cpu ')
.period(5ms)
.every(5ms)
.count('value')
.httpOut('count')
tick := `batch
|query(' SELECT value from unknowndb.unknownrp.cpu ')
.period(5ms)
.every(5ms)
|count('value')
|httpOut('count')
`

r, err := s.DefineTask(name, ttype, tick, dbrps)
Expand Down Expand Up @@ -564,18 +577,18 @@ func TestServer_RecordReplayStream(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)
tick := `
stream
.from().measurement('test')
.window()
.period(10s)
.every(10s)
.count('value')
.alert()
.id('test-count')
.message('{{ .ID }} got: {{ index .Fields "count" }}')
.crit(lambda: TRUE)
.log('` + tmpDir + `/alert.log')
tick := `stream
|from()
.measurement('test')
|window()
.period(10s)
.every(10s)
|count('value')
|alert()
.id('test-count')
.message('{{ .ID }} got: {{ index .Fields "count" }}')
.crit(lambda: TRUE)
.log('` + tmpDir + `/alert.log')
`

r, err := s.DefineTask(name, ttype, tick, dbrps)
Expand Down Expand Up @@ -710,16 +723,15 @@ func TestServer_RecordReplayBatch(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)
tick := `
batch
.query('SELECT value from mydb.myrp.cpu')
.period(2s)
.every(2s)
.alert()
.id('test-batch')
.message('{{ .ID }} got: {{ index .Fields "value" }}')
.crit(lambda: "value" > 2.0)
.log('` + tmpDir + `/alert.log')
tick := `batch
|query('SELECT value from mydb.myrp.cpu')
.period(2s)
.every(2s)
|alert()
.id('test-batch')
.message('{{ .ID }} got: {{ index .Fields "value" }}')
.crit(lambda: "value" > 2.0)
.log('` + tmpDir + `/alert.log')
`

r, err := s.DefineTask(name, ttype, tick, dbrps)
Expand Down Expand Up @@ -902,19 +914,19 @@ func testStreamAgent(t *testing.T, c *run.Config) {
Database: "mydb",
RetentionPolicy: "myrp",
}}
tick := `
stream
.from().measurement('test')
.groupBy('group')
.movingAvg()
.field('value')
.size(10)
.as('mean')
.window()
.period(11s)
.every(11s)
.last('mean').as('mean')
.httpOut('moving_avg')
tick := `stream
|from()
.measurement('test')
.groupBy('group')
|movingAvg()
.field('value')
.size(10)
.as('mean')
|window()
.period(11s)
.every(11s)
|last('mean').as('mean')
|httpOut('moving_avg')
`

r, err := s.DefineTask(name, ttype, tick, dbrps)
Expand Down Expand Up @@ -1124,17 +1136,16 @@ func testBatchAgent(t *testing.T, c *run.Config) {
Database: "mydb",
RetentionPolicy: "myrp",
}}
tick := `
batch
.query(' SELECT value from mydb.myrp.cpu ')
.period(5ms)
.every(5ms)
.groupBy('count')
.outliers()
.field('value')
.scale(1.5)
.count('value')
.httpOut('count')
tick := `batch
|query(' SELECT value from mydb.myrp.cpu ')
.period(5ms)
.every(5ms)
.groupBy('count')
|outliers()
.field('value')
.scale(1.5)
|count('value')
|httpOut('count')
`

r, err := s.DefineTask(name, ttype, tick, dbrps)
Expand Down
Loading

0 comments on commit 1b5ac4d

Please sign in to comment.