Skip to content

Commit

Permalink
Merge pull request #304 from scouter-project/master
Browse files Browse the repository at this point in the history
Merge for release
  • Loading branch information
bill23-kim authored Mar 27, 2017
2 parents 0261b3f + e3f6209 commit 578f066
Show file tree
Hide file tree
Showing 550 changed files with 167,794 additions and 763 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![scouter](./scouter.document/img/main/scouter-logo-w200.png)

![Englsh](https://img.shields.io/badge/language-English-red.svg) [![Korean](https://img.shields.io/badge/language-Korean-blue.svg)](README_kr.md)
![Englsh](https://img.shields.io/badge/language-English-orange.svg) [![Korean](https://img.shields.io/badge/language-Korean-blue.svg)](README_kr.md)

## Application Performance Monitoring for Open Source S/Ws.

Expand Down Expand Up @@ -29,8 +29,6 @@ SCOUTER can help you.
## At a glance(Click to watch the video)
[![Demo gif](https://j.gifs.com/yDqbAa.gif)](https://youtu.be/iuArTzsD7Ws)

<iframe width="560" height="315" src="https://www.youtube.com/embed/iuArTzsD7Ws" frameborder="0" allowfullscreen></iframe>

## Documents
- [Document Home](./scouter.document/index.md)
- [Quick Start Guide (Quick Installation and Demo)](./scouter.document/main/Quick-Start.md)
Expand Down
4 changes: 1 addition & 3 deletions README_kr.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![scouter](./scouter.document/img/main/scouter-logo-w200.png)

[![Englsh](https://img.shields.io/badge/language-English-red.svg)](README.md) ![Korean](https://img.shields.io/badge/language-Korean-blue.svg)
[![Englsh](https://img.shields.io/badge/language-English-orange.svg)](README.md) ![Korean](https://img.shields.io/badge/language-Korean-blue.svg)

## 오픈소스 S/W 어플리케이션 성능 모니터링

Expand Down Expand Up @@ -30,8 +30,6 @@ SCOUTER는 오픈소스 APM 도구로서 Java, WAS에 대한 모니터링 모니
## 소개 동영상(클릭)
[![Demo gif](https://j.gifs.com/yDqbAa.gif)](https://youtu.be/iuArTzsD7Ws)

<iframe width="560" height="315" src="https://www.youtube.com/embed/iuArTzsD7Ws" frameborder="0" allowfullscreen></iframe>

## Documents
- [Document Home](./scouter.document/index_kr.md)
- [Quick Start(Scouter Demo 설치)](./scouter.document/main/Quick-Start_kr.md)
Expand Down
1 change: 1 addition & 0 deletions scouter.agent.batch/src/scouter/agent/batch/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public void reload() {
apply();

Logger.println(CONFIG_SCOUTER_ENABLED + "=" + this.scouter_enabled);
Logger.println("scouter_standalone=" + this.scouter_standalone);
Logger.println("sql_enabled=" + this.sql_enabled);
Logger.println("sfa_dump_enabled=" + this.sql_enabled);
if(sfa_dump_enabled){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,24 @@ static public boolean sendMTU(InetAddress IPAddress, int port, byte[] data, int
if (IPAddress == null)
return false;
long pkid = KeyGen.next();
int total = data.length / packetSize;
int remainder = data.length % packetSize;
if (remainder > 0)
total++;

int availPacketSize = packetSize - 23; // Packet header size is 23
int totalPacketCnt;
int total = data.length / availPacketSize;
int remainder = data.length % availPacketSize;
int num = 0;
boolean isSuccess = true;
for (num = 0; (isSuccess && num < (data.length / packetSize)); num++) {
isSuccess = SendMTU(IPAddress, port, pkid, total, num, packetSize, DataInputX.get(data, num * packetSize, packetSize));

totalPacketCnt = total;
if(remainder > 0){
totalPacketCnt++;
}

for (num = 0; (isSuccess && num < total); num++) {
isSuccess = SendMTU(IPAddress, port, pkid, totalPacketCnt, num, availPacketSize, DataInputX.get(data, num * availPacketSize, availPacketSize));
}
if (isSuccess && remainder > 0) {
SendMTU(IPAddress, port, pkid, total, num, remainder, DataInputX.get(data, data.length - remainder, remainder));
isSuccess = SendMTU(IPAddress, port, pkid, totalPacketCnt, num, remainder, DataInputX.get(data, data.length - remainder, remainder));
}
return isSuccess;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import scouter.agent.batch.Configure;
import scouter.agent.batch.Main;
import scouter.agent.batch.netio.mtu.MultiPacketProcessor;
import scouter.io.DataInputX;
import scouter.lang.pack.MapPack;
import scouter.net.NetCafe;

public class UdpLocalServer extends Thread{
private static UdpLocalServer instance;
Expand All @@ -44,31 +47,21 @@ public static synchronized UdpLocalServer getInstance() {

public void run(){
Configure conf = Configure.getInstance();
byte[] receiveData = new byte[300000];
byte[] receiveData = new byte[conf.net_udp_packet_max_bytes];
DatagramSocket serverSocket = null;
int flag;

try {
int flag;
int size;
serverSocket = new DatagramSocket(conf.net_local_udp_port);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
while(true){
serverSocket.receive(receivePacket);
size = receivePacket.getLength() - 4;
byte [] data = new byte[size];
System.arraycopy(receivePacket.getData(), 4, data, 0, size);

flag = DataInputX.toInt(receiveData, 0);
switch(flag){
case BatchNetFlag.BATCH_END_DUMPFILE_INFO:
TcpAgentReqMgr.getInstance().addJob(data);
break;
case BatchNetFlag.BATCH_RUNNING_INFO:
processRunningInfo(data);
break;
case BatchNetFlag.BATCH_END_INFO:
processEndInfo(data);
break;
}
flag = DataInputX.toInt(receiveData, 0);
if(flag == NetCafe.UDP_CAFE_MTU){
processMTU(receiveData, receivePacket.getAddress());
}else{
process(flag, receiveData);
}
}
}catch(Exception ex){
ex.printStackTrace();
Expand All @@ -79,6 +72,40 @@ public void run(){
}
}

private void processMTU(byte[] receiveData, InetAddress addr) throws Exception{
DataInputX in = new DataInputX(receiveData);
in.readInt();
int objHash = in.readInt();
long pkid = in.readLong();
short total = in.readShort();
short num = in.readShort();
byte [] data = in.readBlob();

data = MultiPacketProcessor.getInstance().add(pkid, total, num, data, objHash, addr);
if (data != null) {
int flag = DataInputX.toInt(data, 0);
process(flag, data);
}
}

private void process(int flag, byte[] receiveData) throws Exception{
int size = receiveData.length - 4;
byte [] data = new byte[size];
System.arraycopy(receiveData, 4, data, 0, size);

switch(flag){
case BatchNetFlag.BATCH_END_DUMPFILE_INFO:
TcpAgentReqMgr.getInstance().addJob(data);
break;
case BatchNetFlag.BATCH_RUNNING_INFO:
processRunningInfo(data);
break;
case BatchNetFlag.BATCH_END_INFO:
processEndInfo(data);
break;
}
}

public int getStartBatchs(){
return startBatchs;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2015 the original author or authors.
* @https://github.com/scouter-project/scouter
*
* 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 scouter.agent.batch.netio.mtu;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;

public class MultiPacket{
private int added = 0;
private ArrayList<byte []> data;
private long openTime = System.currentTimeMillis();

private int total;
private int objHash;
private InetAddress addr;

public MultiPacket(int total, int objHash, InetAddress addr){
this.total = total;
this.objHash = objHash;
this.addr = addr;
this.data = new ArrayList<byte[]>(total);

for(int i=0; i < total; i++){
data.add(null);
}
}

public void set(int n, byte [] data){
if (n < total) {
if (this.data.get(n) == null)
added += 1;
this.data.add(n, data);
}
}

public boolean isExpired(){
return ((System.currentTimeMillis() - this.openTime) >= 1000);
}

public boolean isDone() {
return total == added;
}

public byte[] toBytes() throws IOException{
ByteArrayOutputStream out = new ByteArrayOutputStream();
for (int i = 0; i < total; i++) {
out.write(this.data.get(i));
}
return out.toByteArray();
}

public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("MultiPacket total=").append(total);
sb.append(" recv=").append(added);
sb.append(" object=(").append(objHash).append(")").append(objHash);
sb.append(" ").append(addr);
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package scouter.agent.batch.netio.mtu;

import java.io.IOException;
import java.net.InetAddress;

import scouter.agent.batch.Configure;
import scouter.agent.batch.Logger;
import scouter.util.LongEnumer;
import scouter.util.LongKeyLinkedMap;
import scouter.util.ThreadUtil;

public class MultiPacketProcessor extends Thread{
private static MultiPacketProcessor instance = null;

static final int MAX_COUNT = 1000;
private LongKeyLinkedMap<MultiPacket> buffer = new LongKeyLinkedMap<MultiPacket>();

static public MultiPacketProcessor getInstance(){
if(instance == null){
instance = new MultiPacketProcessor();
instance.setDaemon(true);
instance.setName(ThreadUtil.getName(instance));

instance.start();
}
return instance;
}

private MultiPacketProcessor(){
buffer.setMax(MAX_COUNT);
}

public void run() {
while (true) {
ThreadUtil.sleep(1000);
if (buffer.size() > 0) {
try {
checkExpired();
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
}

public byte[] add(long pkid, int total, int num, byte [] data, int objHash, InetAddress addr) throws IOException{
MultiPacket p;
synchronized(buffer){
p = buffer.get(pkid);
if (p == null) {
p = new MultiPacket(total, objHash, addr);
buffer.put(pkid, p);
}
}

p.set(num, data);
if (p.isDone()) {
buffer.remove(pkid);
return p.toBytes();
}
return null;
}

private void checkExpired() {
LongEnumer en = buffer.keys();
long key;
MultiPacket p;
while (en.hasMoreElements() == true) {
key = en.nextLong();
p = buffer.get(key);
if (p.isExpired()) {
buffer.remove(key);
// if (Configure.getInstance().log_expired_multipacket) {
// Logger.println("S150", p.toString());
// }
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public void run() {
config = Configure.getInstance();
TraceContext traceContext = TraceContext.getInstance();

UdpLocalAgent.sendUdpPackToServer(Main.getObjectPack());
if(!config.scouter_standalone){
UdpLocalAgent.sendUdpPackToServer(Main.getObjectPack());
}
if(config.sfa_dump_enabled){
stackFile = new File(traceContext.getLogFullFilename() + ".log");
if(stackFile.exists()){
Expand All @@ -74,18 +76,18 @@ public void run() {
currentTime = System.currentTimeMillis();
if(stackWriter != null){
if((currentTime - lastStackDumpTime) >= config.sfa_dump_interval_ms){
lastStackDumpTime = currentTime;
ThreadDumpHandler.processDump(stackFile, stackWriter, indexWriter, config.sfa_dump_filter, config.sfa_dump_header_exists);
UdpLocalAgent.sendRunningInfo(traceContext);
lastStackDumpTime = currentTime;
}
}
if((currentTime - lastCheckGCTime) >= 5000L){
traceContext.caculateResource();
lastCheckGCTime = currentTime;
traceContext.caculateResource();
}
if((currentTime - lastCheckThreadTime) >= config.thread_check_interval_ms){
traceContext.checkThread();
lastCheckThreadTime = currentTime;
traceContext.checkThread();
}
Thread.sleep(100L);
}
Expand Down
3 changes: 3 additions & 0 deletions scouter.agent.java/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
<classpathentry kind="lib" path="/scouter.deploy/lib/httpcore-4.3.3.jar" sourcepath="/Users/sjokim/.m2/repository/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3-sources.jar"/>
<classpathentry kind="lib" path="/scouter.deploy/lib/rxnetty-0.4.6.jar"/>
<classpathentry kind="lib" path="/scouter.deploy/lib/ribbon-loadbalancer-2.0.0.jar"/>
<classpathentry kind="lib" path="/scouter.deploy/lib/javax.servlet-api-3.1.0.jar"/>
<classpathentry kind="lib" path="/scouter.deploy/lib/spring-web-4.3.7.RELEASE.jar"/>
<classpathentry kind="lib" path="/scouter.deploy/lib/spring-core-4.3.7.RELEASE.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Loading

0 comments on commit 578f066

Please sign in to comment.