Skip to content

Commit a09e242

Browse files
committed
Merge pull request #167 from scouter-project/master
Merge for release
2 parents b194d1e + 28f2146 commit a09e242

File tree

39 files changed

+668
-119
lines changed

39 files changed

+668
-119
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ Scouter has three modules:
7373

7474
## How to contribute
7575
- **Notice** : Pull request to **dev branch** only allowed.
76-
- Please check the development guide below
76+
- Refer to the development guide below.
7777
- [Scouter developer guide](./scouter.document/tech/Developer-Guide.md)
78-
78+
- Please note that you will have to complete a [CLA](http://goo.gl/forms/xSmYs8qM9J) for your first pull-request.
7979

8080

8181
## Q&A

README_kr.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ APM은 Application performance montoring 또는 application performance manageme
7070
- **Pull request**는 반드시 **dev branch**로 요청하여야 합니다.
7171
- 상세한 내용은 개발자 가이드를 참조하시기 바랍니다.
7272
- [Scouter 개발자 가이드](./scouter.document/tech/Developer-Guide_kr.md)
73+
- 최초 Pull-Request시 다음 [CLA](http://goo.gl/forms/xSmYs8qM9J)(Contributor License Agreement)에 서명하여 제출하여야 합니다.
7374

7475
## Q&A
7576
- [Google Groups](https://groups.google.com/forum/#!forum/scouter-project)

scouter.agent.host/src/scouter/agent/Configure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public final static synchronized Configure getInstance() {
9292
public int cpu_fatal_history = 3;
9393

9494
//Memory
95-
public boolean mem_alert_enabled = true;
95+
public boolean mem_alert_enabled = false;
9696
public long mem_alert_interval_ms = 30000;
9797
public int mem_warning_pct = 80;
9898
public int mem_fatal_pct = 90;
@@ -216,7 +216,7 @@ private void apply() {
216216
this.cpu_warning_history = getInt("cpu_warning_history", 3);
217217
this.cpu_fatal_history = getInt("cpu_fatal_history", 3);
218218

219-
this.mem_alert_enabled = getBoolean("mem_alert_enabled", true);
219+
this.mem_alert_enabled = getBoolean("mem_alert_enabled", false);
220220
this.mem_alert_interval_ms = getLong("mem_alert_interval_ms", 30000);
221221
this.mem_warning_pct = getInt("mem_warning_pct", 80);
222222
this.mem_fatal_pct = getInt("mem_fatal_pct", 90);
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package scouter.agent.counter.task;
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
* original from - https://svn.apache.org/repos/asf/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/sigar/SigarRunner.java
20+
*
21+
*/
22+
/**
23+
* Net Usage, Disk Usage
24+
25+
*/
26+
27+
28+
import org.hyperic.sigar.*;
29+
import scouter.agent.Logger;
30+
import scouter.agent.counter.CounterBasket;
31+
import scouter.agent.counter.anotation.Counter;
32+
import scouter.lang.counters.CounterConstants;
33+
34+
import java.util.HashMap;
35+
import java.util.Map;
36+
37+
public class HostNetDiskPerf {
38+
static int SLEEP_TIME = 2000;
39+
static Sigar sigarImpl = new Sigar();
40+
static SigarProxy sigar = SigarProxyCache.newInstance(sigarImpl, SLEEP_TIME);
41+
42+
private static String[] netIf = null;
43+
private static FileSystem[] fs = null;
44+
45+
private static HashMap<String, Map<String, Long>> previousNetworkStats = new HashMap<String, Map<String, Long>>();
46+
private static HashMap<String, Map<String, Long>> previousDiskStats = new HashMap<String, Map<String, Long>>();
47+
private static final String RX_DELTA = "rxD";
48+
private static final String TX_DELTA = "txD";
49+
private static final String READ_DELTA = "rdD";
50+
private static final String WRITE_DELTA = "wrD";
51+
private static volatile long rxTotalBytesPerSec = 0L;
52+
private static volatile long txTotalBytesPerSec = 0L;
53+
private static volatile long readTotalBytesPerSec = 0L;
54+
private static volatile long writeTotalBytesPerSec = 0L;
55+
56+
public static long getRxTotalBytesPerSec() {
57+
return HostNetDiskPerf.rxTotalBytesPerSec;
58+
}
59+
60+
public static long getTxTotalBytesPerSec() {
61+
return HostNetDiskPerf.txTotalBytesPerSec;
62+
}
63+
64+
public static long getReadTotalBytesPerSec() {
65+
return HostNetDiskPerf.readTotalBytesPerSec;
66+
}
67+
68+
public static long getWriteTotalBytesPerSec() {
69+
return HostNetDiskPerf.writeTotalBytesPerSec;
70+
}
71+
72+
@Counter(interval = 10000)
73+
public void process(CounterBasket pw) {
74+
try {
75+
netUsage(10);
76+
diskIO(10);
77+
SigarProxyCache.clear(sigar);
78+
} catch (Exception e) {
79+
Logger.println("A141", 10, "HostPerfProcess10s", e);
80+
}
81+
}
82+
83+
private void netUsage(int checkIntervalSec) {
84+
try {
85+
if (netIf == null) {
86+
netIf = sigar.getNetInterfaceList();
87+
}
88+
long tmpRxTotal = 0L;
89+
long tmpTxTotal = 0L;
90+
91+
for (int i = 0; i < netIf.length; i++) {
92+
NetInterfaceStat net = null;
93+
try {
94+
net = sigar.getNetInterfaceStat(netIf[i]);
95+
} catch (SigarException e) {
96+
// Ignore the exception when trying to stat network interface
97+
Logger.println("A143", 300, "SigarException trying to stat network device " + netIf[i], e);
98+
continue;
99+
}
100+
Map<String, Long> netMap = new HashMap<String, Long>();
101+
long rxBytes = net.getRxBytes();
102+
long txBytes = net.getTxBytes();
103+
104+
netMap.put(CounterConstants.HOST_NET_RX_BYTES, rxBytes);
105+
netMap.put(CounterConstants.HOST_NET_TX_BYTES, txBytes);
106+
107+
Map<String, Long> preMap = previousNetworkStats.get(netIf[i]);
108+
109+
if (preMap != null) {
110+
long rxDelta = (rxBytes - preMap.get(CounterConstants.HOST_NET_RX_BYTES)) / checkIntervalSec; // per sec delta
111+
long txDelta = (txBytes - preMap.get(CounterConstants.HOST_NET_TX_BYTES)) / checkIntervalSec; // per sec delta
112+
113+
netMap.put(this.RX_DELTA, rxDelta);
114+
netMap.put(this.TX_DELTA, txDelta);
115+
116+
tmpRxTotal += rxDelta;
117+
tmpTxTotal += txDelta;
118+
}
119+
previousNetworkStats.put(netIf[i], netMap);
120+
}
121+
122+
HostNetDiskPerf.rxTotalBytesPerSec = tmpRxTotal;
123+
HostNetDiskPerf.txTotalBytesPerSec = tmpTxTotal;
124+
125+
} catch (SigarException se) {
126+
Logger.println("A144", 60, "SigarException on net usage", se);
127+
HostNetDiskPerf.rxTotalBytesPerSec = 0;
128+
HostNetDiskPerf.txTotalBytesPerSec = 0;
129+
}
130+
}
131+
132+
private void diskIO(int checkIntervalSec) {
133+
try {
134+
if (fs == null) {
135+
fs = sigar.getFileSystemList();
136+
}
137+
long tmpReadTotal = 0L;
138+
long tmpWriteTotal = 0L;
139+
140+
for (int i = 0; i < fs.length; i++) {
141+
FileSystemUsage usage = null;
142+
try {
143+
usage = sigar.getFileSystemUsage(fs[i].getDirName());
144+
} catch (SigarException e) {
145+
// Ignore the exception when trying to stat file interface
146+
Logger.println("A145", 300, "SigarException trying to stat file system device " + fs[i], e);
147+
continue;
148+
}
149+
Map<String, Long> fsMap = new HashMap<String, Long>();
150+
long readBytes = usage.getDiskReadBytes();
151+
long writeBytes = usage.getDiskWriteBytes();
152+
153+
fsMap.put(CounterConstants.HOST_DISK_READ_BYTES, readBytes);
154+
fsMap.put(CounterConstants.HOST_DISK_WRITE_BYTES, writeBytes);
155+
156+
Map<String, Long> preMap = previousDiskStats.get(fs[i].getDevName());
157+
158+
if (preMap != null) {
159+
long readDelta = (readBytes - preMap.get(CounterConstants.HOST_DISK_READ_BYTES)) / checkIntervalSec; // per sec delta
160+
long writeDelta = (writeBytes - preMap.get(CounterConstants.HOST_DISK_WRITE_BYTES)) / checkIntervalSec; // per sec delta
161+
162+
fsMap.put(this.READ_DELTA, readDelta);
163+
fsMap.put(this.WRITE_DELTA, writeDelta);
164+
165+
tmpReadTotal += readDelta;
166+
tmpWriteTotal += writeDelta;
167+
}
168+
previousDiskStats.put(fs[i].getDevName(), fsMap);
169+
}
170+
171+
HostNetDiskPerf.readTotalBytesPerSec = tmpReadTotal;
172+
HostNetDiskPerf.writeTotalBytesPerSec = tmpWriteTotal;
173+
174+
} catch (SigarException se) {
175+
Logger.println("A144", 60, "SigarException on net usage", se);
176+
HostNetDiskPerf.rxTotalBytesPerSec = 0;
177+
HostNetDiskPerf.txTotalBytesPerSec = 0;
178+
}
179+
}
180+
181+
}

scouter.agent.host/src/scouter/agent/counter/task/HostPerf.java

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
package scouter.agent.counter.task;
21

3-
import org.hyperic.sigar.CpuPerc;
4-
import org.hyperic.sigar.FileSystem;
5-
import org.hyperic.sigar.FileSystemUsage;
6-
import org.hyperic.sigar.Mem;
7-
import org.hyperic.sigar.NetStat;
8-
import org.hyperic.sigar.NfsFileSystem;
9-
import org.hyperic.sigar.Sigar;
10-
import org.hyperic.sigar.SigarException;
11-
import org.hyperic.sigar.SigarProxy;
12-
import org.hyperic.sigar.SigarProxyCache;
13-
import org.hyperic.sigar.Swap;
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*
20+
*/
21+
22+
package scouter.agent.counter.task;
1423

24+
import org.hyperic.sigar.*;
1525
import scouter.agent.Configure;
1626
import scouter.agent.Logger;
1727
import scouter.agent.counter.CounterBasket;
@@ -36,7 +46,7 @@ public class HostPerf {
3646
MeterResource cpuMeter = new MeterResource();
3747
MeterResource sysCpuMeter = new MeterResource();
3848
MeterResource userCpuMeter = new MeterResource();
39-
49+
4050
@Counter
4151
public void process(CounterBasket pw) {
4252
try {
@@ -101,6 +111,17 @@ void domain(CounterBasket pw) throws SigarException {
101111
p.put(CounterConstants.HOST_TCPSTAT_TIM, new DecimalValue(tcpstat_time));
102112
p.put(CounterConstants.HOST_TCPSTAT_EST, new DecimalValue(tcpstat_est));
103113

114+
p.put(CounterConstants.HOST_NET_RX_BYTES, new DecimalValue(HostNetDiskPerf.getRxTotalBytesPerSec()));
115+
p.put(CounterConstants.HOST_NET_TX_BYTES, new DecimalValue(HostNetDiskPerf.getTxTotalBytesPerSec()));
116+
117+
p.put(CounterConstants.HOST_DISK_READ_BYTES, new DecimalValue(HostNetDiskPerf.getReadTotalBytesPerSec()));
118+
p.put(CounterConstants.HOST_DISK_WRITE_BYTES, new DecimalValue(HostNetDiskPerf.getWriteTotalBytesPerSec()));
119+
120+
// System.out.println("rx:" + HostNetDiskPerf.getRxTotalBytesPerSec());
121+
// System.out.println("tx:" + HostNetDiskPerf.getTxTotalBytesPerSec());
122+
// System.out.println("read:" + HostNetDiskPerf.getReadTotalBytesPerSec());
123+
// System.out.println("write:" + HostNetDiskPerf.getWriteTotalBytesPerSec());
124+
104125
p = pw.getPack(conf.getObjName(), TimeTypeEnum.FIVE_MIN);
105126
p.put(CounterConstants.HOST_CPU, new FloatValue(cpu));
106127
p.put(CounterConstants.HOST_SYSCPU, new FloatValue(sysCpu));
@@ -120,6 +141,7 @@ void domain(CounterBasket pw) throws SigarException {
120141
p.put(CounterConstants.HOST_TCPSTAT_FIN, new DecimalValue(tcpstat_fin1 + tcpstat_fin2));
121142
p.put(CounterConstants.HOST_TCPSTAT_TIM, new DecimalValue(tcpstat_time));
122143
p.put(CounterConstants.HOST_TCPSTAT_EST, new DecimalValue(tcpstat_est));
144+
123145
SigarProxyCache.clear(sigar);
124146
}
125147

0 commit comments

Comments
 (0)