kapacitor的安裝及部分常用命令


Kapacitor 是一個開源框架,用來處理、監控和警告時間序列數據,它使用 TICKscript 腳本來定義任務。Kapacitor是InfluxData開源的數據處理引擎。它可以處理來自InfluxDB的流數據和批處理數據,可以周期性將InfluxDB中的數據匯總、處理后再輸出到InfluxDB當中,或者告警(支持Email、HTTP、TCP、 HipChat, OpsGenie, Alerta, Sensu, PagerDuty, Slack等多種方式)。

一.安裝

修改kapacitor.conf文件中的參數data_dir和[logging]的路徑,重啟報錯,錯誤如下:

[XXXXXXXX kapacitor]# systemctl status kapacitor
● kapacitor.service - Time series data processing engine.
   Loaded: loaded (/usr/lib/systemd/system/kapacitor.service; disabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Fri 2019-01-29 15:17:42 CST; 312ms ago
     Docs: https://github.com/influxdb/kapacitor
  Process: 28842 ExecStart=/usr/bin/kapacitord -config /etc/kapacitor/kapacitor.conf $KAPACITOR_OPTS (code=exited, status=1/FAILURE)
 Main PID: 28842 (code=exited, status=1/FAILURE)

Jan 29 15:17:42  systemd[1]: Unit kapacitor.service entered failed state.
Jan 29 15:17:42  systemd[1]: kapacitor.service failed.
Jan 29 15:17:42  systemd[1]: kapacitor.service holdoff time over, scheduling restart.
Jan 29 15:17:42  systemd[1]: Stopped Time series data processing engine..
Jan 29 15:17:42  systemd[1]: start request repeated too quickly for kapacitor.service
Jan 29 15:17:42  systemd[1]: Failed to start Time series data processing engine..
Jan 29 15:17:42  systemd[1]: Unit kapacitor.service entered failed state.
Jan 29 15:17:42  systemd[1]: kapacitor.service failed.
查看service 文件/usr/lib/systemd/system/kapacitor.service,發現啟動賬號為kapacitor。

 解決方案:對替換的文件授權即可

chown -R kapacitor:kapacitor data 

chown -R kapacitor:kapacitor logs

 2.調試報錯

調試命令如下:

kapacitor record stream -task cpu_alert -duration 60s

報錯信息:

failed to create recording file: open /var/lib/kapacitor/replay/119w1985-0101-120c-83b0-c9XXXXXXXXX.srpl: permission denied

查看報錯文件的權限

 解決方案:

chown -R kapacitor:kapacitor replay

3.log過多過大,調試log打印級別

上線運行一周發現kapacitor.log有4G,過多過大。

4.服務的開啟/關閉/查看

啟動服務

systemctl start kapacitor.service

關閉服務

systemctl stop kapacitor.service

查看服務狀態

systemctl status kapacitor.service

5.部分命令

查看已部署的task

kapacitor list tasks

如果需要調整代碼,在TICKscript文件中直接編輯。調整后,重新生成task

例如某id為cpu_alert的tick

kapacitor define cpu_alert -tick cpu_alert.tick

 6. bach類型的task 注意沒有-duration 參數

例如:

 kapacitor record batch -task XXXXX -duration 60s

報錯信息如下:

flag provided but not defined: -duration

解釋如下:

Usage: kapacitor record batch [options]

        Record the result of a InfluxDB query from a task.

        Prints the recording ID on exit.

        See 'kapacitor help replay' for how to replay a recording.

Examples:

        $ kapacitor record batch -task cpu_idle -start 2015-09-01T00:00:00Z -stop 2015-09-02T00:00:00Z

                This records the result of the query defined in task 'cpu_idle' and runs the query
                until the queries reaches the stop time, starting at time 'start' and incrementing
                by the schedule defined in the task.

        $ kapacitor record batch -task cpu_idle -past 10h

                This records the result of the query defined in task 'cpu_idle' and runs the query
                until the queries reaches the present time.
                The starting time for the queries is 'now - 10h' and increments by the schedule defined in the task.

Options:

  -no-wait
        Do not wait for the recording to finish.
  -past string
        Set start time via 'now - past'.
  -recording-id string
        The ID to give to this recording. If not set an random ID is chosen.
  -start string
        The start time for the set of queries.
  -stop string
        The stop time for the set of queries (default now).
  -task string
        The ID of a task. Uses the queries contained in the task.

參考資料

https://docs.influxdata.com/kapacitor/v1.5/introduction/getting-started/#test-the-task


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM