0

我想做什么?

我正在尝试在我的 Kubernetes 集群中部署 Telegraf,以便我可以使用 Telegraf 的Prometheus输入插件从特定 URL 读取数据(指标),并使用 Telegraf 的输出文件插件将指标写入文件中。

我做了什么?

我使用 telegraf helm chart在 kubernetes 上部署 telegraf。我更改了以下配置更改。 原始电报 yaml 文件:

config:
  agent:
    interval: "10s"
    round_interval: true
    metric_batch_size: 1000
    metric_buffer_limit: 10000
    collection_jitter: "0s"
    flush_interval: "10s"
    flush_jitter: "0s"
    precision: ""
    debug: false
    quiet: false
    logfile: ""
    hostname: "$HOSTNAME"
    omit_hostname: false
  processors:
    - enum:
        mapping:
          field: "status"
          dest: "status_code"
          value_mappings:
            healthy: 1
            problem: 2
            critical: 3
  outputs:
    - influxdb:
        urls:
          - "http://influxdb.monitoring.svc:8086"
        database: "telegraf"
  inputs:
    - statsd:
        service_address: ":8125"
        percentiles:
          - 50
          - 95
          - 99
        metric_separator: "_"
        allowed_pending_messages: 10000
        percentile_limit: 1000

我对其所做的更改:

config:
  outputs:
    - file:
        files:
          - "stdout"
          - "metrics.out" 
        data_format: influx  
  inputs:
    - prometheus:
        - urls:
            url: "http://ipaddr:80/metrics"

当我应用 helm chart 以及所做的更改时,我得到了 Error: Service "telegraf" is invalid: spec.ports: Required value and my deployment failed。

chandhana@Azure:~/clouddrive/PromExpose$ helm install telegraf influxdata/telegraf -f telegraf-values.yaml
Error: Service "telegraf" is invalid: spec.ports: Required value

如果我在更改后的 YAML 配置上犯了任何错误,请帮助我,因为我没有找到 Telegraf 输入和输出插件的 yaml 格式的任何资源。附加参考链接: telegraf .conf 文件

4

1 回答 1

0

您忘记在values.yaml中启用指标,默认情况下禁用。正确的部分是

metrics:
  health:
    enabled: true
  collect_memstats: false

改变你telegraf-values.yaml

config:
  agent:
    interval: "10s"
    round_interval: true
    metric_batch_size: 1000
    metric_buffer_limit: 10000
    collection_jitter: "0s"
    flush_interval: "10s"
    flush_jitter: "0s"
    precision: ""
    debug: false
    quiet: false
    logfile: ""
    hostname: "$HOSTNAME"
    omit_hostname: false
  processors:
    - enum:
        mapping:
          field: "status"
          dest: "status_code"
          value_mappings:
            healthy: 1
            problem: 2
            critical: 3
  outputs:
    - file:
        files:
          - "stdout"
          - "metrics.out" 
        data_format: influx 
  inputs:
    - prometheus:
        - urls:
            url: "http://ipaddr:80/metrics"

metrics:
  health:
    enabled: true
  collect_memstats: false

结果:

helm install telegraf influxdata/telegraf -f values.yaml
NAME: telegraf
LAST DEPLOYED: Fri Jun 25 10:35:05 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
To open a shell session in the container running Telegraf run the following:

  kubectl exec -i -t --namespace default $(kubectl get pods --namespace default -l app.kubernetes.io/name=telegraf -o jsonpath='{.items[0].metadata.name}') /bin/sh

To view the logs for a Telegraf pod, run the following:

  kubectl logs -f --namespace default $(kubectl get pods --namespace default -l app.kubernetes.io/name=telegraf -o jsonpath='{ .items[0].metadata.name }')
于 2021-06-25T10:40:01.480 回答