您没有提到一种方法:您可以修改 memcached 或您的客户端来记录您需要的统计信息。这可能是最简单和最干净的方法。
在代理和 libpcap 方法之间,有几个权衡:
- If you do the packet capture approach, you have to reassemble the TCP
streams into something usable yourself. OTOH, if your monitor program
gets bogged down, it'll just lose some packets, it won't break the cache.
Same if it crashes. You also don't have to reconfigure anything; packet
capture is transparent.
- If you do the proxy approach, the kernel handles all the TCP work for
you. You'll never lose requests. But if your monitor bogs down, it'll bog
down the app. And if your monitor crashes, it'll break caching. You
probably will have to reconfigure your app and/or memcached servers so
that the connections go through the proxy.
简而言之,代理可能更容易编码,但实现它可能会很痛苦,最好是完美的,否则它会取消你的缓存。更改应用程序或 memcached 对我来说似乎是最明智的方法。
BTW:你看过 memcached 的内置统计报告吗?我认为它的粒度不足以满足您的需求,但是如果您还没有看到它,请在进行实际工作之前先看看 :-D