本文为博主原创,转载请注明出处:

  Telegraf 是一个灵活的服务器代理,用于收集和报告指标。它支持插件驱动,这意味着你可以根据需要添加或修改功能。

1.使用telegraf --help 查看telegraf提供的相关命令和参数

  使用telegraf --help 可以查看telegraf提供的相关命令和参数,具体如下:

telegraf --help
Telegraf, The plugin-driven server agent for collecting and reporting metrics. Usage: telegraf [commands|flags] The commands & flags are: config print out full sample configuration to stdout
version print the version to stdout --aggregator-filter <filter> filter the aggregators to enable, separator is :
--config <file> configuration file to load
--config-directory <directory> directory containing additional *.conf files
--plugin-directory directory containing *.so files, this directory will be
searched recursively. Any Plugin found will be loaded
and namespaced.
--debug turn on debug logging
--input-filter <filter> filter the inputs to enable, separator is :
--input-list print available input plugins.
--output-filter <filter> filter the outputs to enable, separator is :
--output-list print available output plugins.
--pidfile <file> file to write our pid to
--pprof-addr <address> pprof address to listen on, don't activate pprof if empty
--processor-filter <filter> filter the processors to enable, separator is :
--quiet run in quiet mode
--section-filter filter config sections to output, separator is :
Valid values are 'agent', 'global_tags', 'outputs',
'processors', 'aggregators' and 'inputs'
--sample-config print out full sample configuration
--test gather metrics, print them out, and exit;
processors, aggregators, and outputs are not run
--test-wait wait up to this many seconds for service
inputs to complete in test mode
--usage <plugin> print usage for a plugin, ie, 'telegraf --usage mysql'
--version display the version and exit Examples: # generate a telegraf config file:
telegraf config > telegraf.conf # generate config with only cpu input & influxdb output plugins defined
telegraf --input-filter cpu --output-filter influxdb config # run a single telegraf collection, outputing metrics to stdout
telegraf --config telegraf.conf --test # run telegraf with all plugins defined in config file
telegraf --config telegraf.conf # run telegraf, enabling the cpu & memory input, and influxdb output plugins
telegraf --config telegraf.conf --input-filter cpu:mem --output-filter influxdb # run telegraf with pprof
telegraf --config telegraf.conf --pprof-addr localhost:6060

基本命令

  • telegraf config: 打印完整的样本配置到标准输出。

  • telegraf version: 打印版本信息。

配置相关

  • --config <file>: 指定要加载的配置文件。

  • --config-directory <directory>: 指定包含额外 *.conf 文件的目录。

  • --plugin-directory: 指定包含 *.so 文件的目录,Telegraf 将递归搜索此目录并加载任何找到的插件。

  • --debug: 启用调试日志。

  • --input-filter <filter>: 过滤要启用的输入插件,分隔符为冒号。

  • --output-filter <filter>: 过滤要启用的输出插件,分隔符为冒号。

  • --pidfile <file>: 指定写入进程ID的文件。

  • --pprof-addr <address>: 指定监听 pprof 的地址。如果为空,则不激活 pprof。

  • --processor-filter <filter>: 过滤要启用的处理器,分隔符为冒号。

  • --quiet: 以静默模式运行。

  • --section-filter: 过滤要输出的配置部分,有效值包括 'agent', 'global_tags', 'outputs', 'processors', 'aggregators' 和 'inputs'。

  • --sample-config: 打印完整的样本配置。

  • --test: 收集指标、打印它们并退出;在测试模式下,不会运行处理器、聚合器和输出。

  • --test-wait: 在测试模式下等待多长时间以完成服务输入。

  • --usage <plugin>: 打印特定插件的使用信息,例如 'telegraf --usage mysql'。

示例

  • 生成 Telegraf 配置文件telegraf config > telegraf.conf

  • 仅定义 CPU 输入和 InfluxDB 输出插件的配置telegraf --input-filter cpu --output-filter influxdb config

  • 单次 Telegraf 收集,输出指标到 stdouttelegraf --config telegraf.conf --test

  • 按配置文件中定义的所有插件运行 Telegraftelegraf --config telegraf.conf

  • 启用 CPU 和内存输入,以及 InfluxDB 输出插件的 Telegraftelegraf --config telegraf.conf --input-filter cpu:mem --output-filter influxdb

  • 带有 pprof 的 Telegraf 运行telegraf --config telegraf.conf --pprof-addr localhost:6060

2.telegraf --debug 调试运行

  运行实例如下:

root@533b2a4c7c7d:/# telegraf --debug
2024-07-26T08:29:49Z I! Starting Telegraf 1.14.3
2024-07-26T08:29:49Z I! Using config file: /etc/telegraf/telegraf.conf
2024-07-26T08:29:49Z I! Loaded inputs: procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat procstat ping disk kernel mem system net cpu processes swap
2024-07-26T08:29:49Z I! Loaded aggregators:
2024-07-26T08:29:49Z I! Loaded processors:
2024-07-26T08:29:49Z I! Loaded outputs: influxdb
2024-07-26T08:29:49Z I! Tags enabled: host=controller1 nodetype=controller
2024-07-26T08:29:49Z I! [agent] Config: Interval:30s, Quiet:false, Hostname:"controller1", Flush Interval:10s
2024-07-26T08:29:49Z D! [agent] Initializing plugins
2024-07-26T08:29:49Z D! [agent] Connecting outputs
2024-07-26T08:29:49Z D! [agent] Attempting connection to [outputs.influxdb]
2024-07-26T08:29:49Z W! [outputs.influxdb] When writing to [http://192.168.118.142:8097]: database "monitor" creation failed: 404 Not Found
2024-07-26T08:29:49Z D! [agent] Successfully connected to outputs.influxdb
2024-07-26T08:29:49Z D! [agent] Starting service inputs
2024-07-26T08:30:00Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:10Z D! [outputs.influxdb] Wrote batch of 81 metrics in 8.753274ms
2024-07-26T08:30:10Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:20Z D! [outputs.influxdb] Wrote batch of 4 metrics in 1.620578ms
2024-07-26T08:30:20Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:30Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:40Z D! [outputs.influxdb] Wrote batch of 83 metrics in 11.697527ms
2024-07-26T08:30:40Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
2024-07-26T08:30:50Z D! [outputs.influxdb] Wrote batch of 4 metrics in 1.38142ms

  关注后面几行日志:

  • Buffer fullness: 这些消息显示了Telegraf内部缓冲区的状态,即在任何给定时间点,等待被发送到InfluxDB的指标数量。例如,“Buffer fullness: 0 / 10000 metrics”意味着当前没有指标在缓冲区中等待发送,而“Buffer fullness: 3 / 10000 metrics”表示有3个指标在缓冲区等待发送。这个数字显示了缓冲区的当前占用情况,与缓冲区的总容量(在这种情况下是10000个指标)相比。

  • Wrote batch of X metrics in Y ms: 这些消息表示Telegraf成功地将一批指标发送到InfluxDB,并给出了处理这批指标所花费的时间。例如,“Wrote batch of 80 metrics in 8.915386ms”意味着Telegraf成功地将80个指标作为一批发送到InfluxDB,这个过程花费了大约8.92毫秒。

3.通过修改配置文件开启debug模式:

  修改 telegraf.conf 配置文件中得 debug 为 true

telegraf 常用命令总结的更多相关文章

  1. Linux 常用命令(持续补充)

    常用命令: command &:将进程放在后台执行 ctrl + z:暂停当前进程 并放入后台 jobs:查看当前后台任务 bg( %id):将任务转为后台执行 fg( %id):将任务调回前 ...

  2. LVM基本介绍与常用命令

    一.LVM介绍LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制LVM - 优点:LVM通常用于装备大量磁盘的系统,但它同样适 ...

  3. Linux学习笔记(一):常用命令

    经过统计Linux中能够识别的命令超过3000种,当然常用的命令就远远没有这么多了,按照我的习惯,我把已经学过的Linux常用命令做了以下几个方面的分割: 1.文件处理命令 2.文件搜索命令 3.帮助 ...

  4. git常用命令(持续更新中)

    git常用命令(持续更新中) 本地仓库操作git int                                 初始化本地仓库git add .                       ...

  5. 【原】npm 常用命令详解

    今年上半年在学习gulp的使用,对npm的掌握是必不可少的,经常到npm官网查询文档让我感到不爽,还不如整理了一些常用的命令到自己博客上,于是根据自己的理解简单翻译过来,终于有点输出,想学习npm这块 ...

  6. npm常用命令

    npm常用命令 环境:win7 npm 是什么 NPM(node package manager),通常称为node包管理器.顾名思义,它的主要功能就是管理node包,包括:安装.卸载.更新.查看.搜 ...

  7. Git 常用命令

    一.初始環境配置 git config --global user.name "John Doe"git config --global user.email johndoe@ex ...

  8. linux iptables常用命令之配置生产环境iptables及优化

    在了解iptables的详细原理之前,我们先来看下如何使用iptables,以终为始,有可能会让你对iptables了解更深 所以接下来我们以配置一个生产环境下的iptables为例来讲讲它的常用命令 ...

  9. Linux常用命令(一)

    Linux常用命令 1. pwd查看当前路径(Print Working Directory)    [root@CentOS ~]# pwd/root 2. cd .. 返回上一级 .. 表示上一级 ...

  10. 版本控制-svn服务器搭建和常用命令(centos 6.3)

    Svn是比较优秀的版本控制工具,虽然功能和性能上无法和Git媲美,但由于其容易搭建和使用的特性,所以在各个小公司还是很受欢迎的.使用Git可参考<版本控制-Git服务器搭建和常用命令使用> ...

随机推荐

  1. XML Web 服务技术解析:WSDL 与 SOAP 原理、应用案例一览

    XML Web服务是一种用于在网络上发布.发现和使用应用程序组件的技术.它基于一系列标准和协议,如WSDL.SOAP.RDF和RSS.下面是一些相关的内容: WSDL(Web服务描述语言):用于描述W ...

  2. 很多人讲不明白HTTPS,但是我能

    很多人讲不明白HTTPS,但是我能 今天我们用问答的形式,来彻底弄明白HTTPS的过程 下面的问题都是 小明和小丽两个人通信为例 可以把小明想象成服务端,小丽想象成客户端 1. https是做什么用的 ...

  3. tab切换中嵌套swiper轮播

    今天在做官网的时候需要用到swiper多图轮播的功能,但是得嵌套在tab切换中,就在我把砖都搬完后,发现了个问题,就是我在进行tab切换后,发现原本设置的swiper的自动轮播竟然失效了,而且样式也是 ...

  4. vue组件间传值 父组件向子组件传值

    ² 父组件以属性的形式绑定值到子组件身上 ² 子组件通过使用属性props接收(props是单向绑定的(只读属性):当父组件的属性变化时,将传导给子组件,但是反过来不会) 第1步,父组件以动态属性的方 ...

  5. 一文搞懂 ARM 64 系列: 一文搞懂 ARM 64 系列: 函数调用传参与返回值

    函数调用涉及到传参与返回值,下面就来看下ARM 64中,参数与返回值的传递机制. 1 整数型参数传递 这里的整数型并不单指int类型,或者NSInteger类型,而是指任何能够使用整数表示的数据类型, ...

  6. leetcode_2-两数相加_javascript

    题目 2.两数相加 给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新 ...

  7. linux elasticsearch-8.2.0安装

    1.下载,解压缩,命令行前不要留空格 官网下载地址: https://www.elastic.co/cn/downloads/elasticsearch https://artifacts.elast ...

  8. mklink命令使得OneDrive同步任意一个文件夹

      本文介绍利用mklink命令,使得OneDrive自动同步电脑中任意指定文件夹的方法.   OneDrive是由微软提供的云存储和文件同步服务.它提供了大量的云存储空间,允许用户将文件和数据存储在 ...

  9. C++类与对象详解

    什么是类和对象 类和对象的概念 类是对象的抽象,对象是对客观事物的抽象. 用通俗的话来说: 类是类别的意思,是数据类型. 对象是类别下的具体事物. 也就是说: 类是数据类型,对象是变量. 比如: 水果 ...

  10. 解读MySQL 8.0数据字典的初始化与启动

    本文分享自华为云社区<MySQL全文索引源码剖析之Insert语句执行过程>,作者:GaussDB 数据库. 本文主要介绍MySQL 8.0数据字典的基本概念和数据字典的初始化与启动加载的 ...