如何通过python脚本向piwik发送硬编码事件

2024-09-28 15:28:04 发布

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

我正在使用piwik作为vm使用情况的跟踪程序。这个计划是,每次VM启动或关闭时,都会向piwik服务器发送一个自定义请求,并报告UUID和一些其他变量。 我下载了https://github.com/piwik/piwik-python-api项目,该项目本应允许创建python脚本,但在那之后我就被卡住了。在

所有vm都有一个ip(例如,在我的本地主机中是10.0.5.15),我必须使用这个访问来发送请求。在

有人能提供一个链接到一个简单的例子如何发送任何东西到piwik?在


Tags: 项目https程序github脚本comapiuuid
1条回答
网友
1楼 · 发布于 2024-09-28 15:28:04

这个piwik库用于pythonweb服务器,比如Django。除非你计划在你的虚拟机上运行一个web服务器,否则它是没有用的。这就是说,运行一个网络服务器来向piwik发送曲目似乎有些过头了。在

Piwik只是在向服务器发送数据时调用URL。它不使用POST,只使用GET。因此,使用一个将调用URL:https://docs.python.org/2/howto/urllib2.html的脚本在Python中复制调用是非常简单的

实际的piwik url可以简单到:

http://piwik.example.org/piwik.php?idsite={$IDSITE}amp;rec=1

这将在piwik数据库中启动一个会话。ID Site是您正在跟踪的网站的piwik ID。在

Source

可以使用此会话跟踪器传递其他变量。在

我建议在uid参数中传递用户id,如果需要其他自定义变量,也可以在\u cvar中传递。在

uid — defines the User ID for this request. User ID is any non empty unique string identifying the user (such as an email address or a username). To access this value, users must be logged-in in your system so you can fetch this user ID from your system, and pass it to Piwik. The User ID appears in the visitor log, the Visitor profile, and you can Segment reports for one or several User ID (userId segment). When specified, the User ID will be "enforced". This means that if there is no recent visit with this User ID, a new one will be created. If a visit is found in the last 30 minutes with your specified User ID, then the new action will be recorded to this existing visit.

Source

希望这有帮助。在

相关问题 更多 >