Datadog Agent检查找不到指定的路径

Datadog Agent check cannot find the path specified

我已经按照此页面上的说明在 Python 中编写了一个 Datadog 代理检查:https://docs.datadoghq.com/developers/agent_checks/

代理检查应该读取指定网络文件夹中的所有文件,然后将某些指标发送到 Datadog。

要读取的文件夹在yaml文件中是这样指定的:

init_config:
taskResultLocation: "Z:/TaskResults"

这是用来读取文件夹的代码,它是Python 2.7,因为Datadog需要

task_result_location = self.init_config.get('taskResultLocation')
# Loop through all the XML files in the specified folder
for file in os.listdir(task_result_location):

如果我 运行 我的 IDE 中的 Python 脚本一切正常。 当检查被添加到 IDE 所在的同一台机器上的 Datadog Agent Manager 并且检查是 运行 时,Datadog Agent Manager 日志中会抛出一个错误:

2018-08-14 14:33:26 EEST | ERROR | (runner.go:277 in work) | Error running check TaskResultErrorReader: [{"message": "[Error 3] The system cannot find the path specified: 'Z:/TaskResults/.'", "traceback": "Traceback (most recent call last):\n File \"C:\Program Files\Datadog\Datadog Agent\embedded\lib\site-packages\datadog_checks\checks\base.py\", line 294, in run\n self.check(copy.deepcopy(self.instances[0]))\n File \"c:\programdata\datadog\checks.d\TaskResultErrorReader.py\", line 42, in check\n for file in os.listdir(task_result_location):\nWindowsError: [Error 3] The system cannot find the path specified: 'Z:/TaskResults/.'\n"}]

我尝试过使用单引号和双引号、正斜杠和反斜杠以及双斜杠以多种方式指定文件夹位置,但仍会引发相同的错误。

有人知道这是 Yaml 语法错误还是 Datadog 或 Python 的某种问题?

即使 datadog 运行 来自同一台机器,它也会在您的机器上设置一个单独的服务器。因此,听起来 datadog 代理无法访问您的 z:/ 驱动程序。

尝试将 "TaskResults" 文件夹放在根目录中(当 运行ning 来自 datadog - mycheck.yaml 文件所在的位置)并相应地更改路径。

如果这可行并且您仍然希望有一个公共驱动器能够将文件从您的计算机共享到 datadog 的代理程序,则您必须找到一种方法将 drive\folder 挂载到代理程序。他们可能有办法在 documentation

中做到这一点

此问题的解决方案是在网络驱动器上创建文件共享并使用该路径而不是完整的网络驱动器路径。 对某些人来说可能是显而易见的,但我并没有立即想到,因为正常的 Python 代码在 Datadog 之外没有任何问题。

所以不是:

init_config:
taskResultLocation: "Z:/TaskResults"

使用

init_config:
taskResultLocation: '//FileShareName/d/TaskResults'