文件名称:
多维时间序列记录库NetflixSpectator.zip
开发工具:
文件大小: 998kb
下载次数: 0
上传时间: 2019-07-19
详细说明: Spectator 是记录多维时间序列的简单插装代码库,要求 Java 7 及以上版本。代码示例:// The Spectator class provides a static lookup for the default registry Server s = new Server(Spectator.registry()); public class Server { private final ExtendedRegistry registry; private final Id requestCountId; private final Timer requestLatency; private final DistributionS ummary responseSizes; // We can pass in the registry to make unit testing easier. Outside of tests it should typically // be bound to Spectator.registry() to make sure data goes to the right place. public Server(ExtendedRegistry registry) { this.registry = registry; // Create a base id for the request count. The id will get refined with additional dimensions // when we receive a request. requestCountId = registry.createId("server.requestCount"); // Create a timer for tracking the latency. The reference can be held onto to avoid // additional lookup cost in critical paths. requestLatency = registry.timer("server.requestLatency"); // Create a distribution summary meter for tracking the response sizes. responseSizes = registry.distributionSummary("server.responseSizes"); // Gauge type that can be sampled. In this case it will invoke the specified method via // reflection to get the value. The registry will keep a weak reference to the object passed // in so that registration will not prevent garbage collection of the server object. registry.methodValue("server.numConnections", this, "getNumConnections"); } public Response handle(Request req) { final long s = System.nanoTime(); try { Response res = doSomething(req); // Update the counter id with dimensions based on the request. The counter will then // be looked up in the registry which should be fairly cheap, such as lookup of id object // in a ConcurrentHashMap. However, it is more expensive than having a local variable set // to the counter. final Id cntId = requestCountId .withTag("country", req.country()) .withTag("status", res.status()); registry.counter(cntId).increment(); responseSizes.record(res.body().size()); return res; } catch (Exception e) { final Id cntId = requestCountId .withTag("country", req.country()) .withTag("status", "exception") .withTag("error", e.getClass().getSimpleName()); registry.counter(cntId).increment(); throw e; } finally { // Update the latency timer. This should typically be done in a finally block. requestLatency.record(System.nanoTime() - s, TimeUnit.NANOSECONDS); } } public int getNumConnections() { // however we determine the current number of connections on the server } } 标签:Netflix
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
相关搜索: