拓冰建站拓冰建站
首页 / 资讯中心 / 正文

Telegraf SLURM 输入插件:基于 slurmrestd REST API 的集群作业调度监控指南

Telegraf SLURM 输入插件基于 slurmrestd REST API 的集群作业调度监控指南【免费下载链接】telegrafAgent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.项目地址: https://gitcode.com/GitHub_Trending/te/telegraf本文基于 Telegraf 仓库中inputs.slurm插件的官方文档与源码实现系统讲解该插件如何通过 SLURM 的slurmrestdREST APIv0.0.38采集集群诊断、作业、节点、分区和预留reservation五类指标覆盖完整配置参数、指标清单、示例输出以及源码级实现与测试验证细节帮助你在 HPC 环境中快速搭建 SLURM 资源用量监控。插件概述与前提条件该插件是 Telegraf 于 v1.32.0 引入的输入插件见 CHANGELOG.md 中 “inputs.slurmSLURM workload manager” 条目标记为 server 端插件支持所有平台。它通过 SLURM 官方提供的slurmrestd守护进程的 REST API 采集集群数据因此使用前提为目标 SLURM 实例已启用slurmrestd守护进程默认监听127.0.0.1:6820可配置其他地址与端口slurmrestd启用的 REST API 版本必须为v0.0.38插件在 plugins/inputs/slurm/README.md 中明确声明了这一版本依赖若集群开启了基于 JWT 的认证需要准备username/token凭据。从源码结构看插件通过第三方客户端库github.com/pcolladosoto/goslurmgo.mod 中引入封装对/slurm/v0.0.38/...路径下各端点的 HTTP 调用而不是自行拼接请求路径。完整配置参考插件的完整示例配置见 sample.conf该文件通过//go:embed内嵌进二进制供telegraf --test等命令打印。以下为文档给出的全量配置项# Gather SLURM metrics [[inputs.slurm]] ## Slurmrestd URL. Both http and https can be used as schemas. url http://127.0.0.1:6820 ## Credentials for JWT-based authentication. # username foo # token topSecret ## Enabled endpoints ## List of endpoints a user can acquire data from. ## Available values are: diag, jobs, nodes, partitions, reservations. # enabled_endpoints [diag, jobs, nodes, partitions, reservations] ## Maximum time to receive a response. If set to 0s, the ## request will not time out. # response_timeout 5s ## Optional TLS Config. Note these options will only ## be taken into account when the scheme specified on ## the URL parameter is https. They will be silently ## ignored otherwise. ## Set to true/false to enforce TLS being enabled/disabled. If not set, ## enable TLS only if any of the other options are specified. # tls_enable ## Trusted root certificates for server # tls_ca /path/to/cafile ## Used for TLS client certificate authentication # tls_cert /path/to/certfile ## Used for TLS client certificate authentication # tls_key /path/to/keyfile ## Password for the key file if it is encrypted # tls_key_pwd ## Send the specified TLS server name via SNI # tls_server_name kubernetes.example.com ## Minimal TLS version to accept by the client # tls_min_version TLS12 ## List of ciphers to accept, by default all secure ciphers will be accepted ## Use all, secure and insecure to add all support ciphers, secure ## suites or insecure suites respectively. # tls_cipher_suites [secure] ## Renegotiation method, never, once or freely # tls_renegotiation_method never ## Use TLS but skip chain host verification # insecure_skip_verify false关键参数说明参数类型默认值说明urlstring无必填slurmrestd地址支持http/https两种 schemeusername/tokenstring空JWT 认证凭据未开启认证时可省略enabled_endpoints[]string全部 5 个端点可选值为diag、jobs、nodes、partitions、reservationsresponse_timeoutduration5s单次请求最长等待时间设为0s表示不超时tls_*/insecure_skip_verify-按 TLS 默认通用 TLS 选项仅在 URL scheme 为https时生效此外插件还支持 Telegraf 的全局插件配置能力别名、标签与字段过滤、插件顺序等详见 docs/CONFIGURATION.md。插件初始化URL 与端点校验逻辑实现位于 plugins/inputs/slurm/slurm.go。Init()方法在插件加载阶段完成一系列前置校验任何一项不通过都会让 Telegraf 启动时报错而非静默运行具体规则如下端点校验若未配置enabled_endpoints默认为全部五个端点配置中出现的值会被统一转小写后与diag、jobs、nodes、partitions、reservations比对出现空字符串或拼写错误如diagg会直接返回unknown endpoint错误。注意Init()中若EnabledEndpoints为空切片也会被赋为默认值因此配置里写enabled_endpoints []等价于启用全部端点仓库测试用例 testcases/panic/telegraf.conf 正是利用这一点URL 校验url不能为空、必须能解析出 hostname、scheme 只能是http或httpsTLS 处理若 URL 是http但配置了 TLS 参数插件仅记录一条警告并忽略 TLS 配置不会导致启动失败。初始化完成后插件构造goslurm客户端UserAgent使用 Telegraf 的产品标识http.Client的Timeout绑定到response_timeoutTLS 配置注入底层http.Transport。上述校验规则均有对应的单元测试覆盖TestGoodURLs/TestWrongURLs验证合法与非法 URL含httpp://这类错误 scheme、空 hostnameTestWrongEndpoints验证端点拼写错误时的报错行为均见 slurm_test.go。采集流程一次 Gather 内的五个端点Gather()方法在每个采集周期内按endpointMap依次调用五个 API 端点对应源码中的调用链SlurmV0038Diag→ 生成slurm_diag指标SlurmV0038GetJobs→ 生成slurm_jobs指标SlurmV0038GetNodes→ 生成slurm_nodes指标SlurmV0038GetPartitions→ 生成slurm_partitions指标SlurmV0038GetReservations→ 生成slurm_reservations指标。认证凭据以 API key 的形式通过context传递给 goslurm 客户端goslurm.ContextAPIKeyskey 分别为user与token。任一启用端点请求失败都会使整个Gather返回包装后的错误如error getting diag: ...便于在 Telegraf 日志中定位是哪个端点出了问题。指标清单与字段说明文档强调由于 SLURM API 暴露的字段非常多插件在“信息量”与“噪音”之间做了取舍只保留运维上有价值的字段。所有指标都带一个source标签其值为url中的 hostname用于区分同一实例下多组配置或跨集群场景。slurm_diag集群诊断标签source。字段均来自slurmrestd的/slurm/v0.0.38/diag返回的statistics段server_thread_count— slurmctld 服务线程数jobs_canceled/jobs_submitted/jobs_started/jobs_completed/jobs_failed/jobs_pending/jobs_running— 作业生命周期各阶段计数schedule_cycle_last/schedule_cycle_mean— 调度循环最近一次耗时与平均耗时bf_queue_len/bf_queue_len_mean— 后台填充backfill队列长度及均值bf_active— backfill 调度器是否处于活跃状态真实的 diag 响应样例含rpcs_by_message_type、rpcs_by_user等未采集字段可参考 testcases/gather/responses/diag.json其中statistics段还包含schedule_cycle_max、bf_cycle_mean等插件未映射的字段印证了文档中“有取舍”的描述。slurm_jobs作业级指标标签source、name作业名、job_id。每个作业一条指标字段包括状态类state、state_reason资源类partition、nodes、node_count、cpus、tasks、time_limit、nice属性类priority、group_id路径类command、standard_output、standard_error、standard_input、current_working_directory源码中对这些路径字段做了反斜杠清洗strings.ReplaceAll(*strPtr, \\, )时间类submit_time、start_timeUnix 时间戳TRES 类tres_cpu、tres_mem、tres_node、tres_billing等由作业请求的 TRES 字符串动态展开slurm_nodes节点级指标标签source、name节点名。每个节点一条指标字段包括state— 节点状态idle、allocated、down等硬件类cores、cpus、cpu_load、real_memory分配类alloc_cpu、alloc_memory、free_memoryTRES 类tres_cpu、tres_mem、tres_billing及已用量tres_used_cpu、tres_used_mem其他weight节点调度权重、slurmd_version、architectureslurm_partitions分区级指标标签source、name。每个分区一条指标字段state、total_cpu、total_nodes、nodes节点名列表字符串、tres_cpu、tres_mem、tres_node、tres_billing。slurm_reservations预留资源指标标签source、name。每个 reservation 一条指标字段core_count、core_spec_count、groups、users、start_time、partition、accounts、node_count、node_list。TRES 字符串的动态解析TRESTracked Resource Specification在 SLURM API 中以cpu1,mem2000M这类逗号分隔的keyvalue字符串返回。插件用parseTres()函数将其展开为tres_前缀的独立字段普通数值直接转为浮点数mem字段支持K/M/G/T/P单位后缀并统一换算为以 MB 为基准的数值K除以 1024G乘 1024依此类见无法解析为数值的内容如tres_node中的节点列表保持原始字符串。这正是示例输出中出现tres_cpu1、tres_mem2000数值型与tres_node1计数混合呈现的原因。示例输出以下是 README 中给出的真实运行样例InfluxDB line protocol 格式展示了各指标的时间戳与字段组合slurm_diag,hosthoth,sourceslurm_primary.example.net bf_activefalse,bf_queue_len1i,bf_queue_len_mean1i,jobs_canceled0i,jobs_completed137i,jobs_failed0i,jobs_pending0i,jobs_running100i,jobs_started137i,jobs_submitted137i,schedule_cycle_last27i,schedule_cycle_mean86i,server_thread_count3i 1723466497000000000 slurm_jobs,hosthoth,job_id23160,namegridjob,sourceslurm_primary.example.net command/tmp/SLURM_job_script.11BCgQ,cpus2i,current_working_directory/home/sessiondir/7CQODmQ3uw5nKG01gq4B3BRpm7wtQmABFKDmbnHPDmG9JKDmILUkln,group_id2005i,nice50i,node_count1i,nodesnaboo225,partitionatlas,priority4294878569i,standard_error...comment,standard_input/dev/null,standard_output...comment,start_time1723354525i,stateRUNNING,state_reasonNone,submit_time1723354525i,tasks1i,time_limit3600i,tres_billing1,tres_cpu1,tres_mem2000,tres_node1 1723466497000000000 slurm_nodes,hosthoth,namenaboo147,sourceslurm_primary.example.net alloc_cpu36i,alloc_memory45000i,architecturex86_64,cores18i,cpu_load3826i,cpus36i,free_memory1607i,real_memory94793i,slurmd_version22.05.9,stateallocated,tres_billing36,tres_cpu36,tres_mem94793,tres_used_cpu36,tres_used_mem45000,weight1i 1723466497000000000 slurm_partitions,hosthoth,nameatlas,sourceslurm_primary.example.net nodesnaboo145,...,naboo243,stateUP,total_cpu632i,total_nodes21i,tres_billing632,tres_cpu632,tres_mem1415207,tres_node21 1723466497000000000从样例可见state、nodes、command等可变长字段以字符串形式输出计数与容量类字段为整型i后缀TRES 展开字段为浮点数无后缀这与 slurm.go 中各gather*Metrics函数的类型映射一一对应。测试体系用模拟 slurmrestd 校验指标一致性插件的集成测试采用“目录驱动”方式TestCases遍历 testcases 下的每个子目录用httptest在本地启动一个模拟slurmrestd的 HTTP 服务按请求路径/slurm/v0.0.38/{diag,jobs,nodes,partitions,reservations}分发目录下responses/*.json中的预置响应然后加载该目录的telegraf.conf实例化插件、执行Gather并将实际指标与期望值比对时间戳忽略、按序排序。仓库当前包含两组用例testcases/gather配置了username/token凭据、未设置enabled_endpoints即默认采集全部端点验证完整采集链路testcases/panicenabled_endpoints []验证空端点列表不会导致采集异常源码中会回落到默认值。每个端点的模拟响应 JSON如 jobs.json、nodes.json均来自 SLURM 22.05.9 的真实 API 返回可作为对接自己集群时的字段对照参考。注册与适用场景小结插件通过 plugins/inputs/all/slurm.go 的空白导入注册进标准构建build tag 为!custom || inputs || inputs.slurm。典型适用场景包括监控 SLURM 集群的作业提交/完成/失败速率基于slurm_diag的jobs_*字段做趋势与告警跟踪节点利用率结合slurm_nodes的alloc_cpu、free_memory、tres_used_mem等字段评估资源水位审计分区容量slurm_partitions与预留资源占用slurm_reservations。需要注意的限制插件仅支持 REST API v0.0.38采集粒度为每个interval的全量快照非增量jobs端点在大集群下返回的指标数量与作业数成正比可通过enabled_endpoints裁剪高基数端点来控制数据量。【免费下载链接】telegrafAgent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.项目地址: https://gitcode.com/GitHub_Trending/te/telegraf创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门