Python读取寄存器

2024-06-01 03:43:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图按照MySQL仪表板的these指令进行操作,但是当我试图运行mysql.py脚本时,会出现以下错误:

  File "mysql.py", line 565, in <module>
    collectd.register_read(read_callback)
AttributeError: 'module' object has no attribute 'register_read'

我在internet上找不到有关此错误的任何信息,因此我请求您的帮助:)


Tags: inpy脚本registerread错误line指令
2条回答

据我所知,你不能在collectd之外运行collectd插件,也就是说,作为一个独立的脚本,因为collectd通过嵌入式Python解释器运行它们,如here 您必须执行以下操作:

  1. 创建插件配置:

    
    $ vi /etc/collectd.d/myplugin.conf # your path may vary
    
    LoadPlugin Python
    <Plugin python>
     ModulePath "/etc/collectd/python"
     LogTraces true
     Interactive false
     <Module myplugin>
       arg1 value1
     </Module> 
    </Plugin>
    

    上面的章节说-

    • 我有一个插件叫做我的插件.py存在于/etc/collectd/python目录中。
      • 它是一个非交互式插件
      • 我把它输入为-arg1=value1

  2. 将插件转储到/etc/collectd/python中,与Module同名,但使用.py
  3. 重新启动collectd并通过启用上面提到的logfile插件来监视日志。在

查看一些插件示例,看看插件中的内容-iostatredis

试试这个

python -m collectd mysql.py

如果您在使用collectd时遇到问题,请将mysql.py文件放入python include path中。要检查它,请使用

^{pr2}$

要确保插件正常工作,请检查collectd日志。您可以通过多种方式实现:

  1. 检查sudo service collectd status
  2. 检查collectd日志文件

在这两种情况下,你应该看到这样的情况

[date] mysql plugin: Sending value: ...

注1:sudo service collectd status的输出是有限的,可以显示其他内容。如果是这样,请使用日志文件 注2:获取输出enable plugin logfile并配置日志文件的路径,例如

<Plugin logfile>
    LogLevel "info"
    File "/var/log/collectd.log"
    Timestamp true
    PrintSeverity false
</Plugin>

LogLevel info is the highest log level for most installations. Only debug is higher but it's available only if collectd was compiled with debugging support.

相关问题 更多 >