CnOps 智能运维与可观测社区
首页开源项目实践文章视频课程常见问答开发者工具STAROps 专题
导航菜单
首页开源项目实践文章视频课程常见问答开发者工具STAROps 专题

CnOps 智能运维与可观测社区

愿景

CnOps 智能运维与可观测社区是一个以"智能运维与可观测"为核心的开放、包容、分享的技术社区,旨在聚集运维专家、开发者和爱好者,共同探讨、学习和分享可观测最佳实践与最新技术,与众多技术社区合作互动,共同探讨交叉领域的技术挑战,推动可观测领域的创新与进步。

内容社区

  • 实践文章
  • 视频课程
  • 开源项目
  • 常见问答
  • 开发者工具

友情链接

  • Prometheus
  • Grafana Lab
  • OpenTelemetry
  • LoongCollector

关注我们

阿里云云原生公众号阿里云云原生
阿里云可观测公众号阿里云可观测

Copyright © 2026 CnOps 社区. All rights reserved.

首页/开源项目/LoongCollector/脚本执行数据
文档目录
概览版本管理
什么是输入插件
脚本执行数据【Debug】文本日志【示例】MetricInput主机Meta数据【Debug】Mock数据-Metric主机监控数据MySQL Binlog容器标准输出GO ProfileGPU数据HTTP数据【示例】ServiceInputJournal数据KafkaKubernetes元信息采集【Debug】Mock数据-ServiceSqlServer 查询数据OTLP数据PostgreSQL 查询数据收集 SNMP 协议机器信息Syslog数据

LoongCollector

脚本执行数据

inputcommand插件可以通过配置脚本内容,在agent机器上生成可执行的脚本,并通过指定的cmdpath 执行该脚本,插件会从脚本执行后stdout获得内容进行解析,从而获取脚本内容执行后的信息。 注意:如需使用该插件,LoongCollector 进程需以 root 用户运行。配置的脚本内容请自行评估风险。 Alpha 推荐版本:iLogtail v1.7.1 及以上 | 参数 ...

input_command 插件

简介

input_command插件可以通过配置脚本内容,在agent机器上生成可执行的脚本,并通过指定的cmdpath 执行该脚本,插件会从脚本执行后stdout获得内容进行解析,从而获取脚本内容执行后的信息。

注意:如需使用该插件,LoongCollector 进程需以 root 用户运行。配置的脚本内容请自行评估风险。

版本

Alpha

版本说明

  • 推荐版本:iLogtail v1.7.1 及以上

配置参数

基础参数

参数 类型 是否必选 说明
Type string 是 插件类型,指定为input_command
ScriptType string 是 指定脚本内容的类型,目前支持:bash、shell、python2、python3
User string 是 运行命令使用的用户名,只支持非Root用户(建议配置最小权限,只给需要关注的目录/文件rwx权限)
ScriptContent string 是 脚本内容, 支持PlainText和base64加密的内容, 跟ContentEncoding的字段对应, ScriptContent长度不能超过512*1024
ContentEncoding string 否 脚本内容的文本格式
支持PlainText(纯文本,不编码)|Base64编码 默认:PlainText
LineSplitSep string 否 脚本输出内容的分隔符,为空时不进行分割,全部作为一条数据返回
CmdPath string 否 执行脚本命令的路径,如果为空,则使用默认路径。bash、shell、python2、python3对应的默认路径如下:
- bash: /usr/bin/bash
- shell: /usr/bin/sh
- python2: /usr/bin/python2
- python3: /usr/bin/python3
TimeoutMilliSeconds int 否 执行脚本的超时时间,单位为毫秒,默认为3000ms
IntervalMs int 否 采集触发频率,也是脚本执行的频率,单位为毫秒,默认为5000ms
Environments []string 否 环境变量,默认为os.Environ()的值,如果设置了Environments,则在os.Environ()的基础上追加设置的环境变量
IgnoreError Bool 否 插件执行出错时是否输出Error日志。如果未添加该参数,则默认使用false,表示不忽略

生成参数

参数 类型 说明
content string 表示脚本的输出内容
script_md5 string 用于表示 ScriptContent(脚本内容)的 MD5,有助于确定生成日志的脚本内容来源
  • 采集配置1
enable: true
inputs:
  - Type: input_command
    User: test
    ScriptType: shell
    ScriptContent:
      echo -e "test metric commond"
    Environments:
      - "DEBUG=true"
flushers:
  - Type: flusher_stdout
    OnlyStdout: true
  • 输出
{
  "content":"test metric commond",
  "script_md5":"b3ebc535c2e6cead6e2e13b383907245",
  "__time__":"1689677617"
}
  • 采集配置2
enable: true
inputs:
  - Type: input_command
    User: test
    ScriptType: python2
    ScriptContent: |
      print("test input_command 0")
      print("test input_command 1")
      print("test input_command 2")
      print("test input_command 3")
      print("test input_command 4")
      print("test input_command 5")
      print("test input_command 6")
      print("test input_command 7")
      print("test input_command 8")
      print("test input_command 9")
    CmdPath: /usr/bin/python
    Environments:
      - "DEBUG=true"
    TimeoutMilliseconds: 1005
flushers:
  - Type: flusher_stdout
    OnlyStdout: true
  • 输出
{
  "content":"test input_command 0\ntest input_command 1\ntest input_command 2\ntest input_command 3\ntest input_command 4\ntest input_command 5\ntest input_command 6\ntest input_command 7\ntest input_command 8\ntest input_command 9",
  "script_md5":"5d049f5b2943d2d5e5737dddb065c39c",
  "__time__":"1689677656"
}
  • 采集配置3
enable: true
inputs:
  - Type: input_command
    User: test
    ScriptType: python2
    ScriptContent: |
      import os
      print os.environ
    CmdPath: /usr/bin/python
    Environments:
      - "DEBUG=true"
    TimeoutMilliseconds: 1005
flushers:
  - Type: flusher_stdout
    OnlyStdout: true
  • 输出
{
  "content":"{'GOPATH': '/opt/go', 'GOROOT': '/usr/local/go',  'DEBUG': 'true', xxxxx(省略后面内容)}",
  "script_md5":"1444286e16118f7d1bb778738a828273",
  "__time__":"1689677681"
}

文章大纲