Beats:运用 Filebeat 来对微服务 API 进行分析

文章转载自:https://elasticstack.blog.csdn.net/article/details/118145104

需要学习的是httpjson请求的写法

使用 Filebeat 的 HTTP JSON input 来对微服务的数据进行采集。我们知道 Beats 的架构是属于一种轻量级的部署。可以直接运用于客户端,或者需要采集的服务器中。

创建 Filebeat 配置文件

filebeat.yml

filebeat.inputs:
# Fetch your public IP every minute.
- type: httpjson
  config_version: 2
  interval: 5s
  request.url: http://api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=7dbe7341764f682c2242e744c4f167b0&units=metric
  processors:
    - decode_json_fields:
        fields: ["message"]
        target: "json"
 
output.elasticsearch:
    hosts: ["localhost:9200"]

使用 httpjson input 来读取一个 HTTP 的 JSON 负载,并使用 decode_json_fields 来对它进行解析。在上面我们使用了一个微服务的 API 接口:http://api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=7dbe7341764f682c2242e744c4f167b0&units=metric。它可以得到一个城市的天气情况。

启动filebeat后,可以看到 Filebeat 每5秒会发送一个请求到微服务中得到天气的数据。

posted @ 2021-06-29 10:43  哈喽哈喽111111  阅读(393)  评论(0编辑  收藏  举报