Skip to content

Commit

Permalink
Merge pull request #69 from scouter-project/master
Browse files Browse the repository at this point in the history
merge for release
  • Loading branch information
bill23-kim committed Dec 13, 2015
2 parents 715f7ed + 8aa057e commit a7d8d99
Show file tree
Hide file tree
Showing 198 changed files with 4,370 additions and 2,416 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
scouter.agent.java/bin/*
scouter.client/bin/*
scouter.common/bin/*
scouter.common/bin-test/*
scouter.server/bin/*
scouter.server/bin-test/*
scouter.deploy/out
*/.cache
*/.svn
Expand Down Expand Up @@ -29,6 +31,8 @@ scouter.server/database/
scouter.client.product/plugin_customization.ini
scouter.client/plugin_customization.ini

*/*.scouter

### Vim template
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
Expand Down
6 changes: 2 additions & 4 deletions scouter.agent.host/scripts/host.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mkdir logs > /dev/null 2>&1
cp nohup.out ./logs/nohup.$(date '+%Y%m%d%H%M%S').out > /dev/null 2>&1
#!/usr/bin/env bash

nohup java -classpath ./scouter.host.jar scouter.boot.Boot ./lib > nohup.out &
echo "Scouter host agent launching..."
echo "See the nohup.out."
6 changes: 6 additions & 0 deletions scouter.agent.host/scripts/sample1.host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
mkdir logs > /dev/null 2>&1
cp nohup.out ./logs/nohup.$(date '+%Y%m%d%H%M%S').out > /dev/null 2>&1
nohup java -classpath ./scouter.host.jar scouter.boot.Boot ./lib > nohup.out &
echo "Scouter host agent launching..."
echo "See the nohup.out."
167 changes: 85 additions & 82 deletions scouter.agent.host/src/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@

package scouter.agent;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;

import scouter.Version;
import scouter.agent.netio.data.DataProxy;
import scouter.lang.conf.ConfObserver;
Expand All @@ -35,20 +25,16 @@
import scouter.lang.value.ListValue;
import scouter.lang.value.MapValue;
import scouter.net.NetConstants;
import scouter.util.DateUtil;
import scouter.util.FileUtil;
import scouter.util.HashUtil;
import scouter.util.StringEnumer;
import scouter.util.StringKeyLinkedMap;
import scouter.util.StringSet;
import scouter.util.StringUtil;
import scouter.util.SysJMX;
import scouter.util.SystemUtil;
import scouter.util.ThreadUtil;
import scouter.util.*;

import java.io.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;

public class Configure extends Thread {

public static boolean JDBC_REDEFINED = false;
private static Configure instance = null;
public final static String CONF_DIR = "./conf/";

Expand All @@ -62,53 +48,59 @@ public final static synchronized Configure getInstance() {
return instance;
}

public String local_udp_addr = null;
public int local_udp_port;

public String server_addr = "127.0.0.1";
public int server_udp_port = NetConstants.SERVER_UDP_PORT;
public int server_tcp_port = NetConstants.SERVER_TCP_PORT;
public int server_tcp_session_count = 1;
public int server_tcp_so_timeout = 60000;
public int server_tcp_connection_timeout = 3000;

public String scouter_type = "";
public String scouter_name = "";

public int objHash;
public String objName;

public int udp_packet_max = 60000;
public StringSet log_ignore = new StringSet();
public int max_concurrent_server_request = 10;

public boolean enable_counter_task = true;
public boolean debug_udp_object = false;

public boolean log_rotation = true;
public String logs_dir = "./logs";
public int log_keep_dates = 365;

public String object_registry = "/tmp/scouter";

//Network
public String net_local_udp_ip = null;
public int net_local_udp_port;
public String net_collector_ip = "127.0.0.1";
public int net_collector_udp_port = NetConstants.SERVER_UDP_PORT;
public int net_collector_tcp_port = NetConstants.SERVER_TCP_PORT;
public int net_collector_tcp_session_count = 1;
public int net_collector_tcp_so_timeout_ms = 60000;
public int net_collector_tcp_connection_timeout_ms = 3000;
public int net_udp_packet_max_bytes = 60000;

//Object
public String obj_type = "";
public String obj_name = "";

//Manager
public StringSet mgr_log_ignore_ids = new StringSet();

//Counter
public boolean counter_enabled = true;
public String counter_object_registry_path = "/tmp/scouter";

//Log
public boolean log_udp_object = false;
public boolean log_rotation_enalbed = true;
public String log_dir = "./logs";
public int log_keep_days = 365;

//Disk
public boolean disk_alert_enabled = true;
public int disk_warning_pct = 70;
public int disk_fatal_pct = 90;
public StringSet disk_ignore = new StringSet();
public StringSet disk_ignore_names = new StringSet();

//Cpu
public boolean cpu_alert_enabled = true;
public long cpu_check_period = 300000;
public long cpu_alert_interval = 30000;
public long cpu_check_period_ms = 300000;
public long cpu_alert_interval_ms = 30000;
public int cpu_warning_pct = 70;
public int cpu_fatal_pct = 90;
public int cpu_warning_history = 3;
public int cpu_fatal_history = 3;

//Memory
public boolean mem_alert_enabled = true;
public long mem_alert_interval = 30000;
public long mem_alert_interval_ms = 30000;
public int mem_warning_pct = 80;
public int mem_fatal_pct = 90;

//internal variables
private int objHash;
private String objName;

private Configure() {
Properties p = new Properties();
Map args = new HashMap();
Expand Down Expand Up @@ -189,44 +181,43 @@ public synchronized boolean reload(boolean force) {

private void apply() {

this.udp_packet_max = getInt("udp_packet_max", getInt("udp.packet.max", 60000));
this.log_ignore = getStringSet("log_ignore", ",");
this.net_udp_packet_max_bytes = getInt("net_udp_packet_max_bytes", getInt("udp.packet.max", 60000));
this.mgr_log_ignore_ids = getStringSet("mgr_log_ignore_ids", ",");

this.local_udp_addr = getValue("local_udp_addr");
this.local_udp_port = getInt("local_udp_port", 0);
this.net_local_udp_ip = getValue("net_local_udp_ip");
this.net_local_udp_port = getInt("net_local_udp_port", 0);

this.server_addr = getValue("server_addr", getValue("server.addr", "127.0.0.1"));
this.server_udp_port = getInt("server_udp_port", getInt("server.port", NetConstants.SERVER_UDP_PORT));
this.server_tcp_port = getInt("server_tcp_port", getInt("server.port", NetConstants.SERVER_TCP_PORT));
this.server_tcp_session_count = getInt("server_tcp_session_count", 1, 1);
this.server_tcp_connection_timeout = getInt("server_tcp_connection_timeout", 3000);
this.server_tcp_so_timeout = getInt("server_tcp_so_timeout", 60000);
this.net_collector_ip = getValue("net_collector_ip", getValue("server.addr", "127.0.0.1"));
this.net_collector_udp_port = getInt("net_collector_udp_port", getInt("server.port", NetConstants.SERVER_UDP_PORT));
this.net_collector_tcp_port = getInt("net_collector_tcp_port", getInt("server.port", NetConstants.SERVER_TCP_PORT));
this.net_collector_tcp_session_count = getInt("net_collector_tcp_session_count", 1, 1);
this.net_collector_tcp_connection_timeout_ms = getInt("net_collector_tcp_connection_timeout_ms", 3000);
this.net_collector_tcp_so_timeout_ms = getInt("net_collector_tcp_so_timeout_ms", 60000);

this.max_concurrent_server_request = getInt("max_concurrent_server_request", 10);
this.enable_counter_task = getBoolean("enable_counter_task", true);
this.debug_udp_object = getBoolean("debug_udp_object", false);
this.counter_enabled = getBoolean("counter_enabled", true);
this.log_udp_object = getBoolean("log_udp_object", false);

this.logs_dir = getValue("logs_dir", "./logs");
this.log_rotation = getBoolean("log_rotation", true);
this.log_keep_dates = getInt("log_keep_dates", 365);
this.log_dir = getValue("log_dir", "./logs");
this.log_rotation_enalbed = getBoolean("log_rotation_enalbed", true);
this.log_keep_days = getInt("log_keep_days", 365);

this.object_registry = getValue("object_registry", "/tmp/scouter");
this.counter_object_registry_path = getValue("counter_object_registry_path", "/tmp/scouter");

this.disk_alert_enabled = getBoolean("disk_alert_enablee", true);
this.disk_warning_pct = getInt("disk_warning_pct", 70);
this.disk_fatal_pct = getInt("disk_fatal_pct", 90);
this.disk_ignore = getStringSet("disk_ignore", ",");
this.disk_ignore_names = getStringSet("disk_ignore_names", ",");

this.cpu_alert_enabled = getBoolean("cpu_alert_enabled", true);
this.cpu_check_period = getLong("cpu_check_period", 300000);
this.cpu_alert_interval = getLong("cpu_alert_interval", 30000);
this.cpu_check_period_ms = getLong("cpu_check_period_ms", 300000);
this.cpu_alert_interval_ms = getLong("cpu_alert_interval_ms", 30000);
this.cpu_warning_pct = getInt("cpu_warning_pct", 70);
this.cpu_fatal_pct = getInt("cpu_fatal_pct", 90);
this.cpu_warning_history = getInt("cpu_warning_history", 3);
this.cpu_fatal_history = getInt("cpu_fatal_history", 3);

this.mem_alert_enabled = getBoolean("mem_alert_enabled", true);
this.mem_alert_interval = getLong("mem_alert_interval", 30000);
this.mem_alert_interval_ms = getLong("mem_alert_interval_ms", 30000);
this.mem_warning_pct = getInt("mem_warning_pct", 80);
this.mem_fatal_pct = getInt("mem_fatal_pct", 90);

Expand Down Expand Up @@ -261,10 +252,10 @@ public synchronized void resetObjInfo() {
} else if (SystemUtil.IS_HP_UX) {
detected = CounterConstants.HPUX;
}
this.scouter_type = getValue("scouter_type", detected);
this.scouter_name = getValue("scouter_name", SysJMX.getHostName());
this.obj_type = getValue("obj_type", detected);
this.obj_name = getValue("obj_name", SysJMX.getHostName());

this.objName = "/" + this.scouter_name;
this.objName = "/" + this.obj_name;
this.objHash = HashUtil.hash(objName);

}
Expand Down Expand Up @@ -318,6 +309,14 @@ public boolean getBoolean(String key, boolean def) {
return def;
}

public int getObjHash() {
return this.objHash;
}

public String getObjName() {
return this.objName;
}

public String loadText() {
File file = getPropertyFile();
InputStream fin = null;
Expand Down Expand Up @@ -354,9 +353,6 @@ public void printConfig() {

static {
ignoreSet.add("property");
ignoreSet.add("objHash");
ignoreSet.add("objName");
ignoreSet.add("objType");
}

public MapValue getKeyValueInfo() {
Expand All @@ -381,6 +377,13 @@ public MapValue getKeyValueInfo() {
}

public static void main(String[] args) {
System.out.println(Configure.getInstance().getKeyValueInfo().toString().replace(',', '\n'));
StringKeyLinkedMap<Object> defMap = ConfigValueUtil.getConfigDefault(new Configure(true));
StringEnumer enu = defMap.keys();
while (enu.hasMoreElements()) {
String key = enu.nextString();
if (ignoreSet.contains(key))
continue;
System.out.println(key + " : " + ConfigValueUtil.toValue(defMap.get(key)));
}
}
}
26 changes: 13 additions & 13 deletions scouter.agent.host/src/scouter/agent/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static String getCallStack(Throwable t) {
}

private static boolean checkOk(String id, int sec) {
if (Configure.getInstance().log_ignore.hasKey(id))
if (Configure.getInstance().mgr_log_ignore_ids.hasKey(id))
return false;
if (sec > 0) {
long last = lastLog.get(id);
Expand Down Expand Up @@ -138,10 +138,10 @@ public void run() {
static {
ConfObserver.add(Logger.class.getName(), new Runnable() {
public void run() {
if (CompareUtil.equals(lastDir, conf.logs_dir) == false || lastFileRotation != conf.log_rotation) {
if (CompareUtil.equals(lastDir, conf.log_dir) == false || lastFileRotation != conf.log_rotation_enalbed) {
pw = (PrintWriter) FileUtil.close(pw);
lastDir = conf.logs_dir;
lastFileRotation = conf.log_rotation;
lastDir = conf.log_dir;
lastFileRotation = conf.log_rotation_enalbed;
}
}
});
Expand All @@ -153,27 +153,27 @@ public void run() {
private static synchronized void openFile() throws IOException {
if (pw == null) {
lastDataUnit = DateUtil.getDateUnit();
lastDir = conf.logs_dir;
lastFileRotation = conf.log_rotation;
lastDir = conf.log_dir;
lastFileRotation = conf.log_rotation_enalbed;

new File(lastDir).mkdirs();
if (conf.log_rotation) {
FileWriter fw = new FileWriter(new File(conf.logs_dir, "agent-" + DateUtil.yyyymmdd() + ".log"), true);
if (conf.log_rotation_enalbed) {
FileWriter fw = new FileWriter(new File(conf.log_dir, "agent-" + DateUtil.yyyymmdd() + ".log"), true);
pw = new PrintWriter(fw);
} else {
pw = new PrintWriter(new File(conf.logs_dir, "agent.log"));
pw = new PrintWriter(new File(conf.log_dir, "agent.log"));
}
lastDataUnit = DateUtil.getDateUnit();
}
}

protected static void clearOldLog() {
if (conf.log_rotation == false)
if (conf.log_rotation_enalbed == false)
return;
if (conf.log_keep_dates <= 0)
if (conf.log_keep_days <= 0)
return;
long nowUnit = DateUtil.getDateUnit();
File dir = new File(conf.logs_dir);
File dir = new File(conf.log_dir);
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory())
Expand All @@ -191,7 +191,7 @@ protected static void clearOldLog() {
try {
long d = DateUtil.yyyymmdd(date);
long fileUnit = DateUtil.getDateUnit(d);
if (nowUnit - fileUnit > DateUtil.MILLIS_PER_DAY * conf.log_keep_dates) {
if (nowUnit - fileUnit > DateUtil.MILLIS_PER_DAY * conf.log_keep_days) {
files[i].delete();
}
} catch (Exception e) {
Expand Down
Loading

0 comments on commit a7d8d99

Please sign in to comment.