Skip to content

Commit

Permalink
基础功能全部跑通!
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbully committed Apr 27, 2013
1 parent 31c16d0 commit 23bfd54
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ target/
*.patch
*.tmp
.logs

logs/

Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,15 @@
* Time: 上午11:01
*/
public class Bootstrap {
private CollectorService collectorService;
private final String topic = "hydra_test";

public static void main(String[] strings){
try {
ApplicationContext context = new ClassPathXmlApplicationContext("hydra-collector-service.xml");
Bootstrap bootstrap = new Bootstrap();
bootstrap.collectorService = (CollectorService)context.getBean("collectorService");
bootstrap.start();
CollectorSerService collectorSerService = (CollectorSerService)context.getBean("collectorService");
collectorSerService.subscribe();
} catch (Exception e) {
e.printStackTrace();
}
}

public void start()throws Exception{
collectorService.subscribe(topic);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
* Date: 13-4-17
* Time: 下午5:03
*/
public class CollectorService {
private static final Logger log = LoggerFactory.getLogger(CollectorService.class);
public class CollectorSerService {
private static final Logger log = LoggerFactory.getLogger(CollectorSerService.class);
private String topic;
private MessageConsumer consumer;
private HbaseService hbaseService;
private ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
Expand All @@ -36,6 +37,10 @@ public void setHbaseService(HbaseService hbaseService) {
this.hbaseService = hbaseService;
}

public void setTopic(String topic) {
this.topic = topic;
}

class HbaseConsumer implements MessageListener{
@Override
public void recieveMessages(Message message) {
Expand All @@ -49,15 +54,14 @@ public Executor getExecutor() {
}


public void subscribe(String topic)throws Exception{
public void subscribe()throws Exception{
consumer.subscribe(topic,1024*1024,new HbaseConsumer()).completeSubscribe();
}

public void persistent(Message message){
List<Span> spanList = new ArrayList<Span>();
try{
spanList = (List)PB.parsePBBytes(message.getData());
log.info("成功接受message");
}catch (Exception e){
log.error(e.getMessage());
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
default-autowire="byName">

<bean id="hbaseService" class="com.jd.bdp.hydra.hbase.service.impl.HbaseServiceImpl"/>
<bean id="collectorService" class="com.jd.bdp.hydra.collector.service.CollectorService" />
<bean id="collectorSerService" class="com.jd.bdp.hydra.collector.service.CollectorSerService" >
<property name="topic" value="hydra_test"></property>
</bean>


<bean id="sessionFactory" class="com.taobao.metamorphosis.client.MetaMessageSessionFactory">
<constructor-arg>
Expand Down
2 changes: 1 addition & 1 deletion modules/hydra-collector/src/main/resources/metaq.prop
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metaq.zk=192.168.227.83:2181,192.168.227.86:2181,192.168.228.85:2181
metaq.zk=192.168.227.83:2181
metaq.topic=hydra_test
metaq.zk.root=/meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright jd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.jd.bdp.hydra.benchmark.startCollectorService;

import com.jd.bdp.hydra.agent.CollectorService;
import com.jd.bdp.hydra.collector.service.CollectorSerService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* User: xiangkui
* Date: 13-4-23
* Time: 下午6:19
*/
public class StartCollectorService {

public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{
"classpath*:hydra-collector-service.xml"
});
CollectorSerService collectorSerService = (CollectorSerService)context.getBean("collectorSerService");
collectorSerService.subscribe();
Thread.sleep(999999999);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void main(String[] args) {
context.start();
Trigger trigger=(Trigger)context.getBean("trigger");
// 每隔3s触发一次调用
trigger.startWorkWithSleep(5,500);
trigger.startWorkWithSleep(20,500);
Thread.sleep(999999999);
} catch (Exception e) {
e.printStackTrace();
Expand Down
5 changes: 5 additions & 0 deletions modules/hydra-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<groupId>com.jd.bdp</groupId>
<artifactId>hydra-collector</artifactId>
</dependency>
<!-- 测试hydra-collector-service -->
<dependency>
<groupId>com.jd.bdp</groupId>
<artifactId>hydra-collector-service</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,34 +144,43 @@ public void annotationIndex(Span span) {


public void durationIndex(Span span) {
List<Annotation> alist = span.getAnnotations();
Annotation cs = getCsAnnotation(alist);
Annotation cr = getCrAnnotation(alist);
if (cs != null) {
long duration = cs.getTimestamp() - cr.getTimestamp();
String rowkey = cs.getHost().getServiceName() + ":" + cs.getTimestamp();
Put put = new Put(rowkey.getBytes());
//rowkey:serviceId:csTime
//每列的timestamp为duration
//每列列名为traceId,值为1(用来区分1ms内的跟踪)
put.add(duration_index_family_column.getBytes(), long2ByteArray(span.getTraceId()), duration, "1".getBytes());
HTableInterface htable = null;
try {
htable = POOL.getTable(duration_index);
htable.put(put);
} catch (IOException e) {
e.printStackTrace();
}finally {
if(htable != null){
try {
htable.close();
} catch (IOException e) {
e.printStackTrace();
if (isRootSpan(span)) {
List<Annotation> alist = span.getAnnotations();
Annotation cs = getCsAnnotation(alist);
Annotation cr = getCrAnnotation(alist);
if (cs != null) {
long duration = cr.getTimestamp() - cs.getTimestamp();
String rowkey = cs.getHost().getServiceName() + ":" + cs.getTimestamp();
Put put = new Put(rowkey.getBytes());
//rowkey:serviceId:csTime
//每列的timestamp为duration
//每列列名为traceId,值为1(用来区分1ms内的跟踪)
put.add(duration_index_family_column.getBytes(), long2ByteArray(span.getTraceId()), duration, "1".getBytes());
HTableInterface htable = null;
try {
htable = POOL.getTable(duration_index);
System.out.println(1);
htable.put(put);
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}finally {
if(htable != null){
try {
htable.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}

private boolean isRootSpan(Span span) {
return span.getParentId() == null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void main(String[] args){
cs.setTimestamp(System.currentTimeMillis());
cs.setValue("cs");
Annotation cr = new Annotation();
cr.setTimestamp(System.currentTimeMillis()-(int)(Math.random() * 100));
cr.setTimestamp(System.currentTimeMillis()+(int)(Math.random() * 100));
cr.setValue("cr");
cr.setHost(endpoint);
span.setId(new Long(i));
Expand All @@ -68,10 +68,10 @@ public static void main(String[] args){
Annotation sr = new Annotation();
sr.setHost(endpoint);
sr.setTimestamp(System.currentTimeMillis());
sr.setValue("ss");
sr.setValue("sr");
Annotation ss = new Annotation();
ss.setTimestamp(System.currentTimeMillis()-(int)(Math.random() * 100));
ss.setValue("sr");
ss.setTimestamp(System.currentTimeMillis()+(int)(Math.random() * 100));
ss.setValue("ss");
ss.setHost(endpoint);
span.setParentId(new Long(i+1));
span.setId(new Long(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public class TraceController {
@ResponseBody
public JSONArray getTraces(@PathVariable String serviceId, @PathVariable long startTime, @PathVariable int durationMin, @PathVariable int durationMax, @PathVariable int sum) {
try {
serviceId = "22001";
startTime = 1366614281166L;
durationMin = 20;
durationMax = 80;
sum = 500;
return queryService.getTracesByDuration(serviceId, startTime, sum, durationMin, durationMax);
}catch (Exception e){
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ angular.module('hydra.services.sequence', [])
var spanIndex = {index: 0}
getMySpan(span, spanIndex);


function getMySpan(span, spanIndex) {
var anMap = {};
for (var i in span.annotations) {
Expand Down

0 comments on commit 23bfd54

Please sign in to comment.