使用沙发和沙发应用程序的分析计数器
Couch 有一个 REST 接口。 这意味着数据更新是 PUT 调用所独有的。
我正在检查实现简单的分析计数器的方法,并遇到了 couchdb、sofa 和 couchapp 的功能 - 考虑到我强烈的 JavaScript 倾向,这些功能有点酷。
然而,大多数网络分析服务最终都会使用请求某些资源(通常在 IMG 或 SCRIPT 标记中)来进行计数更新调用。
- 有什么方法可以使用 couchApp 来 使用 GET 请求来执行我的计数?
- 这是否属于滥用 建筑学?我的意思是,并不是沙发上的所有东西都是 REST - i,g - 管理部分不是。
我很高兴听到专家们的意见 :)
** 编辑*
我刚刚注意到 CouchDB 和 Sofa 附带了 Mochiweb Web 服务器! 也许有什么办法我可以抓住它?
Couch has a REST interface.
This means that data-updates are exclusive to PUT calls.
I'm inspecting ways to implement a humble analyics counters, and came accross the features of couchdb, sofa and couchapp - which are kin'da cool, having in mind my strong JavaScript orientation.
However, most web-analytics servcies end with making count update calls using requesting some resource, usually in an IMG or SCRIPT tag.
- Is there a way I can use couchApp to
use GET request to perform my counts? - Would that be abuse of the
architecture? I mean, not everything in couch is REST - i,g, - the administration parts are not.
I'd be very happy to hear what the experts have to say :)
** Editted *
I just noted that CouchDB and Sofa are shipped with a Mochiweb web-server!
Maybe there's a way I could hook on that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分叉或插件的想法
如果您是一名 Erlang 程序员(或者您正在寻找一个新项目来学习 Erlang),那么您绝对可以编写任何您想要的内容作为 CouchDB 的插件/扩展。我所知道的最小的例子是 Die CouchDB,这是我的概念验证,它添加了一个可以简单地停止服务器的查询。
https://github.com/iriscouch/die_couchdb
原则上你可以编写一个 CouchDB 的插件或分支来处理 GET 请求并用它们做任何事情。
关于 REST 架构的注意事项
我对分析实现不太熟悉,但 REST 和 HTTP 的要点是
GET
查询没有副作用和/或幂等(运行 50 个查询与运行一)。结果是,代理可以并且将会以标准和非标准方式缓存许多 GET 响应。这似乎与用户跟踪和数据收集技术不兼容;然而,也许分析工具仍然认为收益大于成本。
对于大多数人来说,使用外部工具可能更容易。
日志想法
一个技巧是从 Couch 获取任何内容,然后检查来自 couch 的日志条目。您可以通过以管理员身份查询
/_log
来获取沙发日志。日志将显示用户的 IP 地址、请求路径和任何查询参数。例如
,接下来您可以自己处理该日志条目并重新插入到实际的分析数据库中。
包装器的想法
最终的解决方案是运行一个简单的反向代理,它将您的 GET 请求转换为您需要的任何内容。 NodeJS 在此类任务中越来越流行,但您可以使用您喜欢的任何 Web 平台:PHP、ASP、JSP,无论您已经知道什么。
您只需响应 GET 请求并在服务器端执行您需要的任何操作,例如将相关信息插入到分析数据库中。
祝你好运!
Fork or plugin idea
If you are an Erlang programmer (or you're looking for a new project to learn Erlang), then you definitely can write anything you want as a plugin/extension to CouchDB. The smallest example I know of is Die CouchDB, my proof-of-concept which adds one query that will simply stop the server.
https://github.com/iriscouch/die_couchdb
You could in principle write a plugin or fork of CouchDB to handle GET requests and do anything with them.
Note about REST architecture
I am not super familiar with analytics implementations, but the point of REST and HTTP is that
GET
queries have no side-effects and/or are idempotent (running 50 queries is no different from running one).The upshot is, proxies can and will cache many GET responses, in both standard and nonstandard ways. That seems incompatible with user tracking and data gathering techniques; however maybe analytics tools still think the benefits outweigh the costs.
For most people, it's probably easier to use external tools.
Log idea
One trick is to GET anything from Couch, and then check the log entry from couch. You can get the couch log by querying
/_log
as the admin. The log will show users' IP address, request path, and any query parameters.For example
Next you can process that log entry and re-insert into your actual analytics database yourself.
Wrapper idea
A final solution is to run a simple reverse-proxy which converts your GET requests into whatever you need. NodeJS is getting popular for tasks like that, but you can use any web platform you prefer: PHP, ASP, JSP, whatever you know already.
You simply respond to the GET request and do whatever you need on the server side, such as inserting the relavant information into your analytics db.
Good luck!