Skip to content
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

Alert data outputs to children nodes #465

Merged
merged 1 commit into from
Apr 15, 2016
Merged

Alert data outputs to children nodes #465

merged 1 commit into from
Apr 15, 2016

Conversation

nathanielc
Copy link
Contributor

@nathanielc nathanielc commented Apr 14, 2016

Fixes #93

Alert data can now be consumed directly from within TICKscripts.
For example, let's say we want to store all data that triggered an alert in InfluxDB with a tag level containing the level string value (i.e CRITICAL).

...
    |alert()
        .warn(...)
        .crit(...)
        .levelTag('level')
         // Or use a field
        .levelField('level')
    |influxDBOut()
        .database('alerts')
        ...

@nathanielc nathanielc merged commit dd5ddf9 into master Apr 15, 2016
@nathanielc nathanielc deleted the nc-issue#93 branch April 15, 2016 16:01
@lpalm
Copy link

lpalm commented Jun 29, 2016

Does levelTag() work for deadman alerts? I tried this but the points being inserted contain only tags for each of the groupBy tags and the one value field for each point. No "level" tag is attached to the points inserted into InfluxDB.

Kapacitor 1.0.0~beta1 (git: master c6f7db5)

var b = stream
    |from()
        .database('X')
        .retentionPolicy('autogen')
        .measurement('X')
        .where(...)
        .groupBy('X', 'Y', 'Z')

b
    |deadman(1.0, 1m)
        .id('streamingDeadman {{ .Group }}')
        .message('{{ .ID }} is {{ .Level }}: {{ index .Fields "emitted" | printf "%.0f" }} points seen in last 1m')
        .levelTag('level')
        .stateChangesOnly()
        .log('X')
        .mode(644)
        .post('X')

b
    |influxDBOut()
        .database('X')
        .retentionPolicy('autogen')
        .measurement('streamingDeadman')

@nathanielc
Copy link
Contributor Author

It does but this script is not sending the deadman alert to InfluxDB but rather the original data selected from the stream

Did you mean this?

var b = stream
    |from()
        .database('X')
        .retentionPolicy('autogen')
        .measurement('X')
        .where(...)
        .groupBy('X', 'Y', 'Z')

b
    |deadman(1.0, 1m)
        .id('streamingDeadman {{ .Group }}')
        .message('{{ .ID }} is {{ .Level }}: {{ index .Fields "emitted" | printf "%.0f" }} points seen in last 1m')
        .levelTag('level')
        .stateChangesOnly()
        .log('X')
        .mode(644)
        .post('X')
    |influxDBOut()
        .database('X')
        .retentionPolicy('autogen')
        .measurement('streamingDeadman')

@lpalm
Copy link

lpalm commented Jun 29, 2016

That's exactly right, @nathanielc. Confirmed this works. Thanks and sorry to waste your time with that.

While we're here, what would be the easiest way to add a field to the inserted point that's equal to the alert's message?

@nathanielc
Copy link
Contributor Author

nathanielc commented Jun 29, 2016

@lpalm That is currently not possible without custom code like a UDF. But it is a good idea and would follow the work from this PR well. Feel free to create an issue to track the request. PRs are always welcome ;)

@manojgour
Copy link

Following below doc for writing stream or batch data back to Influx:
https://docs.influxdata.com/kapacitor/v1.1/examples/continuous_queries/

Doesn't seem to be working for me; Here's my TICK script:

kapacitor show CQ_engine
ID: CQ_engine
Error:
Template:
Type: batch
Status: enabled
Executing: true
Created: 23 Jan 17 13:50 EST
Modified: 23 Jan 17 13:53 EST
LastEnabled: 23 Jan 17 13:53 EST
Databases Retention Policies: ["kapacitor_example"."autogen"]
TICKscript:
batch
|query('SELECT mean(usage_idle) as usage_idle FROM "kapacitor_example"."autogen".cpu')
.period(5m)
.every(5m)
.groupBy(*)
|influxDBOut()
.database('kapacitor_example')
.retentionPolicy('autogen')
.measurement('mean_cpu_idle')
.precision('s')

DOT:
digraph CQ_engine {
graph [throughput="0.00 batches/s"];

query1 [avg_exec_time_ns="0s" batches_queried="0" connect_errors="0" points_queried="0" query_errors="0" ];
query1 -> influxdb_out2 [processed="0"];

influxdb_out2 [avg_exec_time_ns="0s" points_written="0" write_errors="0" ];
}

Also tried working with stream TICK script:

kapacitor show CQ_engine_stream
ID: CQ_engine_stream
Error:
Template:
Type: stream
Status: enabled
Executing: true
Created: 23 Jan 17 14:01 EST
Modified: 23 Jan 17 14:01 EST
LastEnabled: 23 Jan 17 14:01 EST
Databases Retention Policies: ["kapacitor_example"."autogen"]
TICKscript:
stream
|from()
.database('kapacitor_example')
.measurement('cpu')
.groupBy(*)
|window()
.period(5m)
.every(5m)
.align()
|mean('usage_idle')
.as('usage_idle')
|influxDBOut()
.database('kapacitor_example')
.retentionPolicy('autogen')
.measurement('mean_cpu_idle')
.precision('s')

DOT:
digraph CQ_engine_stream {
graph [throughput="0.00 points/s"];

stream0 [avg_exec_time_ns="0s" ];
stream0 -> from1 [processed="0"];

from1 [avg_exec_time_ns="0s" ];
from1 -> window2 [processed="0"];

window2 [avg_exec_time_ns="0s" ];
window2 -> mean3 [processed="0"];

mean3 [avg_exec_time_ns="0s" ];
mean3 -> influxdb_out4 [processed="0"];

influxdb_out4 [avg_exec_time_ns="0s" points_written="0" write_errors="0" ];
}

Appreicate your help here.

@nathanielc
Copy link
Contributor Author

@manojgour We try to reserve GitHub Issues for actionable bug reports or feature requests. Please send general questions to the [email protected] mailing list.

@jjbuchan jjbuchan mentioned this pull request May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants