开发者

Issue with configuring alert via API on Influx DB

I'm using InfluxDB to configure alert against data collected via node_exporter & prometheus. I use the attached query to validate the usage of CPU (refer image 1)

from(bucket: "prometheus")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_field"] == "node_cpu_seconds_total" and r["mode"] == "idle")
    |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
    |> derivative(timeColumn: "_time", columns: ["_value"])
    |> map(
        fn: (r) =>
            ({
                _time: r._time,
                node_cpu_seconds_total: r["_value"],
                _field: r.cpu,
                _value: 100.0 - r._value * 100.0,
            }),
    )
    |> yield()

The output is working as expected. But when i try to configure an alert against the same query via API. It's not working as expected. API Endpoint: https://ap-southeast-2-1.aws.cloud2.influxdata.com/api/v2/checks Method: POST Payload:

{
    "id": null,
    "type": "threshold",
    "status": "active",
    "activeStatus": "active",
    "name": "API Test",
    "query": {
        "name": "",
        "text": "from(bucket: \"prometheus\") |> range(start: -30m) |> filter(fn: (r) => r[\"_field\"] == 开发者_运维技巧\"node_cpu_seconds_total\" and r[\"mode\"] == \"idle\") |> aggregateWindow(every: 1m, fn: mean, createEmpty: false) |> derivative(timeColumn: \"_time\", columns: [\"_value\"]) |> map( fn: (r) => ({_time: r._time, _field: r.cpu,node_cpu_seconds_total: r[\"_value\"], job: r[\"job\"], _value: 100.0 - r._value * 100.0}), ) |> yield()",
        "editMode": "builder",
        "builderConfig": {
            "buckets": [
                "prometheus"
            ],
            "tags": [
                {
                    "key": "_measurement",
                    "values": [
                        "_all"
                    ],
                    "aggregateFunctionType": "filter"
                },
                {
                    "key": "_field",
                    "values": [
                        "_value"
                    ],
                    "aggregateFunctionType": "filter"
                }
            ],
            "functions": [
                {
                    "name": "mean"
                }
            ],
            "aggregateWindow": {
                "period": "30m",
                "fillValues": false
            }
        },
        "hidden": false
    },
    "orgID": "2f4c02f2aa443cb5",
    "labels": [],
    "description": "",
    "every": "1m",
    "offset": "0s",
    "statusMessageTemplate": "Check: ${ r._check_name } is: ${ r._level }",
    "tags": [],
    "thresholds": [
        {
            "type": "greater",
            "value": 3.0,
            "level": "INFO"
        }
    ]
}

Observations:

  • Alert is created on the console
  • The task created against the alert is not reflecting the query i mentioned. Attached the task code below.
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/schema"

data =
    from(bucket: "prometheus")
        |> range(start: -1m)
        |> filter(fn: (r) => r["_field"] == "node_cpu_seconds_total" and r["mode"] == "idle")
        |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
        |> derivative(timeColumn: "_time", columns: ["_value"])
        |> map(
            fn: (r) =>
                ({
                    _time: r._time,
                    _field: r.cpu,
                    node_cpu_seconds_total: r["_value"],
                    job: r["job"],
                    _value: 100.0 - r._value * 100.0,
                }),
        )

option task = {name: "API Test", every: 1m, offset: 0s}

check = {_check_id: "0a65e164fceff000", _check_name: "API Test", _type: "threshold", tags: {}}
info = (r) => r["node_cpu_seconds_total"] > 3.0
messageFn = (r) => "Check: ${ r._check_name } is: ${ r._level }"

data |> schema["fieldsAsCols"]() |> monitor["check"](data: check, messageFn: messageFn, info: info)

Output

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜