匿名使用统计信息收集器
usagestats的Python项目详细描述
此包旨在方便地从 程序。
将收集统计信息,但在用户选择加入之前不会上载。一个 将在stderr上打印消息,要求用户显式选择加入或选择 出去。
用法
通过将usagetts添加到 项目的需求和使用库。下面是一个示例:
import usagestats import sys optin_prompt = usagestats.Prompt(enable='cool_program --enable-stats', disable='cool_program --disable-stats') # Location where to store stats # Also allocates a unique ID for the user # The version is important, since the information you log (or the format) # might change in later versions of your program stats = usagestats.Stats('~/.myprog/usage_stats', optin_prompt, 'https://usagestats.example.org/', unique_user_id=True, version='0.1') def main(): if len(sys.argv) < 2: pass elif sys.argv.get(1) == '--enable-stats': stats.enable_reporting() sys.exit(0) elif sys.argv.get(1) == '--disable-stats': stats.disable_reporting() sys.exit(0) if sys.version_info < (3,): # Stores some info, will be reported when submit() is called stats.note({'mode': 'compatibility'}) # Report things stats.submit( # Dictionary containing the info {'what': 'Ran the program'}, # Flags making usagestats insert more details usagestats.OPERATING_SYSTEM, # Operating system/distribution usagestats.PYTHON_VERSION, # Python version info usagestats.SESSION_TIME, # Time since Stats object was created ) if __name__ == '__main__': main()
submit()默认情况下将信息存储在指定的目录中。没有什么 将被报告,直到用户选择进入;消息将被简单地打印到 标准差:
Uploading usage statistics is currently DISABLED Please help us by providing anonymous usage statistics; you can enable this by running: cool_program --enable-stats If you do not want to see this message again, you can run: cool_program --disable-stats Nothing will be uploaded before you opt in.
服务器
要收集报告,任何服务器都可以;报告通过post上传 作为key:value对的lf分隔列表。mod_wsgi的一个简单脚本是 包含;它将每个报告写入一个单独的文件。自己写 使用您自己的后端选择的语言(php、java)实现 应该相当直截了当。