本文整理汇总了Java中com.neverwinterdp.yara.MetricRegistry类的典型用法代码示例。如果您正苦于以下问题:Java MetricRegistry类的具体用法?Java MetricRegistry怎么用?Java MetricRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MetricRegistry类属于com.neverwinterdp.yara包,在下文中一共展示了MetricRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPerformance
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
@Test
public void testPerformance() throws Exception {
clusterBuilder.install() ;
MetricRegistry mRegistry = new MetricRegistry("localhost") ;
int numOfMessages = 10000 ;
Map<String, String> kafkaProducerProps = new HashMap<String, String>() ;
kafkaProducerProps.put("request.required.acks", "1");
KafkaMessageProducer producer = new KafkaMessageProducer(kafkaProducerProps, mRegistry, "127.0.0.1:9092") ;
for(int i = 0 ; i < numOfMessages; i++) {
Message message = new Message("m" + i, new byte[1024], false) ;
producer.send(KafkaClusterBuilder.TOPIC, message) ;
}
producer.close();
Thread.sleep(2000) ;
clusterBuilder.getShell().execute("server metric");
clusterBuilder.uninstall();
}
示例2: testBasic
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
@Test
public void testBasic() throws Exception {
FileUtil.removeIfExist("build/ServerLogMetricPlugin", false);
YaraServiceImpl yaraService = new YaraServiceImpl() ;
server.getServiceRegistry().register(YaraService.newReflectiveBlockingService(yaraService));
MetricRegistry server1 = createMetricRegistry("server1") ;
MetricRegistry server2 = createMetricRegistry("server2") ;
Random rand = new Random() ;
for(int i = 0; i < 100000; i++) {
long timestamp = Clock.defaultClock().getTick() ;
server1.counter("counter").incr() ;
server1.timer("timer").update(timestamp, rand.nextInt(1000)) ;
server2.counter("counter").incr() ;
server2.timer("timer").update(timestamp, rand.nextInt(1000)) ;
}
Thread.sleep(6000);
new ClusterMetricPrinter().print(yaraService.getClusterMetricRegistry());
}
示例3: testBasic
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
@Test
public void testBasic() throws IOException {
MetricRegistry server1 = new MetricRegistry("server1") ;
MetricRegistry server2 = new MetricRegistry("server2") ;
Random rand = new Random() ;
for(int i = 0; i < 1000; i++) {
long duration = rand.nextInt(i + 1) ;
if(duration % 3 == 0) {
server1.getCounter("method call counter").incr() ;
server1.getTimer("method call timer").update(duration, TimeUnit.NANOSECONDS);
} else {
server2.getCounter("method call counter").incr() ;
server2.getTimer("method call timer").update(duration, TimeUnit.NANOSECONDS);
}
}
ClusterMetricRegistry registry = new ClusterMetricRegistry() ;
registry.update(server1);
registry.update(server2);
ClusterMetricPrinter printer = new ClusterMetricPrinter() ;
printer.print(registry);
}
示例4: testPerformance
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
@Test
public void testPerformance() throws Exception {
MetricRegistry mRegistry = new MetricRegistry() ;
WirePayload payload = createWirePayload() ;
System.out.println("ProtoBuf Size: " + payload.toByteArray().length);
System.out.println("Serializable Size: " + IOUtil.serialize(payload).length);
for(int i = 0; i < 1000000; i++) {
Timer.Context protoBufSerCtx = mRegistry.timer("protobuf", "serialize").time() ;
byte[] protobufData = payload.toByteArray() ;
protoBufSerCtx .close();
Timer.Context protobufDeserCtx = mRegistry.timer("protobuf", "deserialize").time() ;
WirePayload deserPayload = WirePayload.parseFrom(protobufData) ;
protobufDeserCtx.close();
Timer.Context javaSerCtx = mRegistry.timer("java", "serialize").time() ;
byte[] javaData = IOUtil.serialize(payload) ;
javaSerCtx .close();
Timer.Context javaDeserCtx = mRegistry.timer("java", "deserialize").time() ;
deserPayload = (WirePayload)IOUtil.deserialize(javaData) ;
javaDeserCtx.close();
}
new MetricPrinter().print(mRegistry) ;
}
示例5: testSegment
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
void testSegment(byte[] data, int numOfEntries, MetricRegistry mRegistry) throws Exception {
String segmentDir = "build/segment" ;
FileUtil.removeIfExist(segmentDir, false);
Timer.Context allCtx = mRegistry.timer("all", "segment").time() ;
Segment<String> segment = new Segment<String>(segmentDir, new JavaSerializer<String>(), 0, numOfEntries) ;
segment.open();
Timer.Context writeAllCtx = mRegistry.timer("segment", "writeAll").time() ;
for(int i = 0; i < numOfEntries; i++) {
Timer.Context writeCtx = mRegistry.timer("segment", "write").time() ;
segment.append(data);
writeCtx.close();
}
segment.close();
writeAllCtx.close();
segment.open();
while(segment.hasNext()) {
Timer.Context timeCtx = mRegistry.timer("segment", "next").time() ;
byte[] bytes = segment.next();
timeCtx.close();
}
segment.close();
allCtx.close();
}
示例6: testInitSegment
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
void testInitSegment(int numOfSegment, MetricRegistry mRegistry) throws Exception {
String segmentDir = "build/segment" ;
for(int i = 0; i < numOfSegment; i++) {
FileUtil.removeIfExist(segmentDir, false);
Timer.Context constructCtx = mRegistry.timer("segment", "init", "construct").time() ;
Segment<String> segment = new Segment<String>(segmentDir, new JavaSerializer<String>(), 0, 10000) ;
constructCtx.close();
Timer.Context openCtx = mRegistry.timer("segment", "init", "open").time() ;
segment.open();
openCtx.close();
Timer.Context closeCtx = mRegistry.timer("segment", "init", "close").time() ;
segment.close();
closeCtx.close();
}
}
示例7: configure
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
@Override
protected void configure() {
Names.bindProperties(binder(), properties) ;
HazelcastClusterService clusterService = new HazelcastClusterService() ;
ClusterMember member = clusterService.getMember();
properties.put("cluster.ip-address", member.getIpAddress()) ;
properties.put("cluster.listen-port", Integer.toString(member.getPort())) ;
String hostId = member.toString() ;
bind(ClusterService.class).toInstance(clusterService);
MetricRegistry metricRegistry = new MetricRegistry(properties.get("server.name")) ;
clusterService.setMetricRegistry(metricRegistry);
bind(MetricRegistry.class).toInstance(metricRegistry);
LoggerFactory loggerFactory = new LoggerFactory("[" + hostId + "][NeverwinterDP] ") ;
clusterService.setLoggerFactory(loggerFactory);
bind(LoggerFactory.class).toInstance(loggerFactory);
bind(ModuleContainer.class).asEagerSingleton();
bind(Server.class).asEagerSingleton();
}
示例8: main
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
static public void main(String[] args) throws Exception {
Options options = new Options() ;
JCommander jcommander = new JCommander(options, args) ;
jcommander.usage();
LoggerFactory lfactory = new LoggerFactory() ;
MetricRegistry mRegistry = new MetricRegistry() ;
HttpServer server = new HttpServer() ;
server.setLoggerFactory(lfactory) ;
server.setPort(options.httpListenPort) ;
MessageForwarder forwarder = null ;
if("kafka".equals(options.forwarder)) {
forwarder = new KafkaMessageForwarder(lfactory, mRegistry, options.kafkaParams) ;
} else {
forwarder = new NullDevMessageForwarder(options.sparknginParams) ;
}
Sparkngin sparkngin = new Sparkngin(mRegistry, forwarder, options.dataDir) ;
server.add("/message/json", new JSONMessageRouteHandler(sparkngin));
server.add("/message/jbinary", new JBinaryMessageRouteHandler(sparkngin));
server.add("/tracker/:trackerName/:site", new TrackingPixelRouteHandler(sparkngin, options.sparknginParams));
server.startAsDeamon() ;
Thread.currentThread().join();
}
示例9: setup
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
@Before
public void setup() throws Exception {
FileUtil.removeIfExist("build/queue", false) ;
forwarder = new AssertMessageForwarder() ;
MetricRegistry mRegistry = new MetricRegistry() ;
Sparkngin sparkngin = new Sparkngin(mRegistry, forwarder, "build/queue/data") ;
server = new HttpServer() ;
server.startAsDeamon() ;
Map<String, String> config = new HashMap<String, String>() ;
config.put("tracking.site.extract-headers", "Host.*,content.*") ;
server.add("/tracker/:trackerName/:site", new TrackingPixelRouteHandler(sparkngin, config)) ;
Thread.sleep(2000) ;
}
示例10: KafkaMessageProducer
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
public KafkaMessageProducer(Map<String, String> props, MetricRegistry metricRegistry, String kafkaBrokerUrls) {
this.metricRegistry = metricRegistry ;
Properties kafkaProps = new Properties() ;
kafkaProps.put("serializer.class", "kafka.serializer.StringEncoder");
kafkaProps.put("partitioner.class", SimplePartitioner.class.getName());
kafkaProps.put("request.required.acks", "1");
kafkaProps.put("metadata.broker.list", kafkaBrokerUrls);
if(props != null) {
kafkaProps.putAll(props);
}
this.kafkaProperties = kafkaProps ;
reconnect() ;
}
示例11: doTestSendMessage
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
void doTestSendMessage() throws Exception {
clusterBuilder.install() ;
MetricRegistry mRegistry = new MetricRegistry("localhost") ;
MetricsConsumerHandler handler = new MetricsConsumerHandler("Kafka", mRegistry) ;
KafkaMessageConsumerConnector consumer = new KafkaMessageConsumerConnector("consumer", "127.0.0.1:2181") ;
String[] topics = {"metrics.consumer", "metrics.tracker"};
consumer.consume(topics, handler, 1) ;
int numOfMessages = 10000 ;
Map<String, String> kafkaProducerProps = new HashMap<String, String>() ;
kafkaProducerProps.put("request.required.acks", "1");
KafkaMessageProducer producer = new KafkaMessageProducer(kafkaProducerProps, mRegistry, "127.0.0.1:9092") ;
for(int i = 0 ; i < numOfMessages; i++) {
//SampleEvent event = new SampleEvent("event-" + i, "event " + i) ;
Message message = new Message("m" + i, new byte[1024], false) ;
producer.send("metrics.consumer", message) ;
producer.send("metrics.tracker", message) ;
}
Thread.sleep(2000) ;
//Assert.assertEquals(numOfMessages, handler.messageCount()) ;
MetricPrinter mPrinter = new MetricPrinter() ;
mPrinter.print(mRegistry);
//TODO: problem with consumer shutdown it seems the process is hang for
//awhile and produce the exception, it seems the hang problem occurs on jdk1.8 MAC OS
consumer.close() ;
producer.close();
clusterBuilder.uninstall() ;
}
示例12: init
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
@Inject
public void init(LoggerFactory lfactory, MetricRegistry mRegistry, YaraConfig config) {
logger = lfactory.getLogger(YaraClientService.class) ;
logger.info("Start init(...)");
this.metricRegistry = mRegistry ;
this.config = config ;
logger.info("Finish init(...)");
}
示例13: createMetricRegistry
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
MetricRegistry createMetricRegistry(String server) throws Exception {
RPCLogRequestForwarder forwarder = new RPCLogRequestForwarder(client) ;
MetricRegistry registry = new MetricRegistry() ;
ServerLogMetricPlugin plugin = new ServerLogMetricPlugin(server, "build/ServerLogMetricPlugin/" + server, forwarder) ;
registry.getPluginManager().add(plugin);
return registry ;
}
示例14: write
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
synchronized public void write(byte[] data, MetricRegistry mRegistry) throws Exception {
Timer.Context timeCtx = mRegistry.timer("queue", "segment", "find").time() ;
Segment<T> segment = writtingSegment();
timeCtx.stop() ;
timeCtx = mRegistry.timer("queue", "segment", "write").time() ;
segment.append(data) ;
timeCtx.stop() ;
}
示例15: execute
import com.neverwinterdp.yara.MetricRegistry; //导入依赖的package包/类
public Object execute(ClusterClient clusterClient, Command command) throws Exception {
ServerCommand<MetricRegistry> serverCmd = new ServerCommands.GetMetricRegistry() ;
command.mapPartial(serverCmd);
ServerCommandResult<MetricRegistry>[] results = command.getMemberSelector().execute(clusterClient, serverCmd) ;
ClusterMetricRegistry registry = new ClusterMetricRegistry() ;
for(ServerCommandResult<MetricRegistry> result : results) {
registry.update(result.getResult());
}
return registry ;
}