无法从 Kapacitor 流获得对本地 Express 应用程序的响应 http Post

Unable to get response http Post to local express app from Kapacitor stream

我关注 SE Thread 是为了在 express 节点上获得对 HTTP POST 的一些响应。但是无法得到kapacitor的任何回应。

环境

我正在通过 PowerShell 使用 Windows 10。 我连接到 kapacitor.conf 中提到的 InfluxDB 内部服务器,并有一个 TICKscript 通过它流式传输数据。

kapacitor.conf

hostname = "134.102.97.81"
data_dir = "C:\Users\des\.kapacitor"
skip-config-overrides = true
default-retention-policy = ""

[alert]
  persist-topics = true

[http]
  bind-address = ":9092"
  auth-enabled = false
  log-enabled = true
  write-tracing = false
  pprof-enabled = false
  https-enabled = false
  https-certificate = "/etc/ssl/kapacitor.pem"
  https-private-key = ""
  shutdown-timeout = "10s"
  shared-secret = ""

[replay]
  dir = "C:\Users\des\.kapacitor\replay"

[storage]
  boltdb = "C:\Users\des\.kapacitor\kapacitor.db"

[task]
  dir = "C:\Users\des\.kapacitor\tasks"
  snapshot-interval = "1m0s"

[load]
  enabled = false
  dir = "C:\Users\des\.kapacitor\load"

[[influxdb]]
  enabled = true
  name = "DB5Server"
  default = true
  urls = ["https://influxdb.internal.server.address:8086"]
  username = "user"
  password = "password"
  ssl-ca = ""
  ssl-cert = ""
  ssl-key = ""
  insecure-skip-verify = true
  timeout = "0s"
  disable-subscriptions = true
  subscription-protocol = "https"
  subscription-mode = "cluster"
  kapacitor-hostname = ""
  http-port = 0
  udp-bind = ""
  udp-buffer = 1000
  udp-read-buffer = 0
  startup-timeout = "5m0s"
  subscriptions-sync-interval = "1m0s"
  [influxdb.excluded-subscriptions]
    _kapacitor = ["autogen"]

[logging]
  file = "STDERR"
  level = "DEBUG"

[config-override]
  enabled = true

[[httppost]]
  endpoint = "kapacitor"
  url = "http://localhost:1440"
  headers = { Content-Type = "application/json;charset=UTF-8"}
  alert-template = "{\"id\": {{.ID}}}"

守护进程运行没有任何问题。

test2.tick

dbrp "DBTEST"."autogen"

stream
    |from()
        .measurement('humid')
    |alert()
        .info(lambda: TRUE)
        .post()
        .endpoint('kapacitor')
  1. 已经定义了任务.\kapacitor.exe define bc_1 -tick test2.tick
  2. 启用它 .\kapacitor.exe enable bc_1

状态没有显示:

.\kapacitor.exe show bc_1



ID: bc_1
Error:
Template:
Type: stream
Status: enabled
Executing: true
Created: 13 Mar 19 15:33 CET
Modified: 13 Mar 19 16:23 CET
LastEnabled: 13 Mar 19 16:23 CET
Databases Retention Policies: ["NIMBLE"."autogen"]
TICKscript:
dbrp "TESTDB"."autogen"

stream
    |from()
        .measurement('humid')
    |alert()
        .info(lambda: TRUE)
        .post()
        .endpoint('kapacitor')

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

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

from1 [avg_exec_time_ns="0s" errors="0" working_cardinality="0" ];
from1 -> alert2 [processed="0"];

alert2 [alerts_inhibited="0" alerts_triggered="0" avg_exec_time_ns="0s" crits_triggered="0" errors="0" infos_triggered="0" oks_triggered="0" warns_triggered="0" working_cardinality="0" ];
}

守护进程日志为任务提供了这个

ts=2019-03-13T16:25:23.640+01:00 lvl=debug msg="starting enabled task on startup" service=task_store task=bc_1
ts=2019-03-13T16:25:23.677+01:00 lvl=debug msg="starting task" service=kapacitor task_master=main task=bc_1
ts=2019-03-13T16:25:23.678+01:00 lvl=info msg="started task" service=kapacitor task_master=main task=bc_1
ts=2019-03-13T16:25:23.679+01:00 lvl=debug msg="listing dot" service=kapacitor task_master=main dot="digraph bc_1 {\nstream0 -> from1;\nfrom1 -> alert2;\n}"
ts=2019-03-13T16:25:23.679+01:00 lvl=debug msg="started task during startup" service=task_store task=bc_1
ts=2019-03-13T16:25:23.680+01:00 lvl=debug msg="opened service" source=srv service=*task_store.Service
ts=2019-03-13T16:25:23.680+01:00 lvl=debug msg="opening service" source=srv service=*replay.Service
ts=2019-03-13T16:25:23.681+01:00 lvl=debug msg="skipping recording, metadata is already correct" service=replay recording_id=353d8417-285d-4fd9-b32f-15a82600f804
ts=2019-03-13T16:25:23.682+01:00 lvl=debug msg="skipping recording, metadata is already correct" service=replay recording_id=a8bb5c69-9f20-4f4d-8f84-109170b6f583

但是我在 Express Node 端什么也得不到。代码与上述SE线程中的代码完全相同。

关于如何在 HTTP 上从 Kapacitor 捕获流的任何帮助 Post?我已经有一个正在将信息推送到专用数据库的实时系统

我能够在上述查询中将焦点从 stream 转移到 batch。我已经记录了完整的过程 on medium.com.

一些文件:

kapacitor.gen.conf

hostname = "my-windows-10"
data_dir = "C:\Users\<user>\.kapacitor"
skip-config-overrides = true
default-retention-policy = ""

[alert]
  persist-topics = true

[http]
  bind-address = ":9092"
  auth-enabled = false
  log-enabled = true
  write-tracing = false
  pprof-enabled = false
  https-enabled = false
  https-certificate = "/etc/ssl/kapacitor.pem"
  https-private-key = ""
  shutdown-timeout = "10s"
  shared-secret = ""

[replay]
  dir = "C:\Users\des\.kapacitor\replay"

[storage]
  boltdb = "C:\Users\des\.kapacitor\kapacitor.db"

[task]
  dir = "C:\Users\des\.kapacitor\tasks"
  snapshot-interval = "1m0s"

[load]
  enabled = false
  dir = "C:\Users\des\.kapacitor\load"

[[influxdb]]
  enabled = true
  name = "default"
  default = true
  urls = ["http://127.0.0.1:8086"]
  username = ""
  password = ""
  ssl-ca = ""
  ssl-cert = ""
  ssl-key = ""
  insecure-skip-verify = true
  timeout = "0s"
  disable-subscriptions = true
  subscription-protocol = "http"
  subscription-mode = "cluster"
  kapacitor-hostname = ""
  http-port = 0
  udp-bind = ""
  udp-buffer = 1000
  udp-read-buffer = 0
  startup-timeout = "5m0s"
  subscriptions-sync-interval = "1m0s"
  [influxdb.excluded-subscriptions]
    _kapacitor = ["autogen"]

[logging]
  file = "STDERR"
  level = "DEBUG"

[config-override]
  enabled = true

# Subsequent Section describes what this conf does

[[httppost]]
  endpoint = "kap"
  url = "http://127.0.0.1:30001/kapacitor"
  headers = { "Content-Type" = "application/json"}

TICKScript

var data =  batch
     | query('SELECT "v" FROM "telegraf_test"."autogen"."humid"')
       .period(5s)
       .every(10s)

data
      |httpPost()
       .endpoint('kap')

定义任务

.\kapacitor.exe define batch_test -tick .\batch_test.tick -dbrp DBTEST.autogen

我怀疑 hostname 之前设置为 localhost 的地方是恶作剧,但我将其设置为我机器的主机名,而是使用 IP 地址 127.0.0.1 localhost被提及