Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ Scouter has three modules:

## How to contribute
- **Notice** : Pull request to **dev branch** only allowed.
- Please check the development guide below
- Refer to the development guide below.
- [Scouter developer guide](./scouter.document/tech/Developer-Guide.md)

- Please note that you will have to complete a [CLA](http://goo.gl/forms/xSmYs8qM9J) for your first pull-request.


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

## Q&A
- [Google Groups](https://groups.google.com/forum/#!forum/scouter-project)
Expand Down
4 changes: 2 additions & 2 deletions scouter.agent.host/src/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public final static synchronized Configure getInstance() {
public int cpu_fatal_history = 3;

//Memory
public boolean mem_alert_enabled = true;
public boolean mem_alert_enabled = false;
public long mem_alert_interval_ms = 30000;
public int mem_warning_pct = 80;
public int mem_fatal_pct = 90;
Expand Down Expand Up @@ -216,7 +216,7 @@ private void apply() {
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_enabled = getBoolean("mem_alert_enabled", false);
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
181 changes: 181 additions & 0 deletions scouter.agent.host/src/scouter/agent/counter/task/HostNetDiskPerf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package scouter.agent.counter.task;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*
* original from - https://svn.apache.org/repos/asf/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/sigar/SigarRunner.java
*
*/
/**
* Net Usage, Disk Usage
* author: gunlee01@gmail.com
*/


import org.hyperic.sigar.*;
import scouter.agent.Logger;
import scouter.agent.counter.CounterBasket;
import scouter.agent.counter.anotation.Counter;
import scouter.lang.counters.CounterConstants;

import java.util.HashMap;
import java.util.Map;

public class HostNetDiskPerf {
static int SLEEP_TIME = 2000;
static Sigar sigarImpl = new Sigar();
static SigarProxy sigar = SigarProxyCache.newInstance(sigarImpl, SLEEP_TIME);

private static String[] netIf = null;
private static FileSystem[] fs = null;

private static HashMap<String, Map<String, Long>> previousNetworkStats = new HashMap<String, Map<String, Long>>();
private static HashMap<String, Map<String, Long>> previousDiskStats = new HashMap<String, Map<String, Long>>();
private static final String RX_DELTA = "rxD";
private static final String TX_DELTA = "txD";
private static final String READ_DELTA = "rdD";
private static final String WRITE_DELTA = "wrD";
private static volatile long rxTotalBytesPerSec = 0L;
private static volatile long txTotalBytesPerSec = 0L;
private static volatile long readTotalBytesPerSec = 0L;
private static volatile long writeTotalBytesPerSec = 0L;

public static long getRxTotalBytesPerSec() {
return HostNetDiskPerf.rxTotalBytesPerSec;
}

public static long getTxTotalBytesPerSec() {
return HostNetDiskPerf.txTotalBytesPerSec;
}

public static long getReadTotalBytesPerSec() {
return HostNetDiskPerf.readTotalBytesPerSec;
}

public static long getWriteTotalBytesPerSec() {
return HostNetDiskPerf.writeTotalBytesPerSec;
}

@Counter(interval = 10000)
public void process(CounterBasket pw) {
try {
netUsage(10);
diskIO(10);
SigarProxyCache.clear(sigar);
} catch (Exception e) {
Logger.println("A141", 10, "HostPerfProcess10s", e);
}
}

private void netUsage(int checkIntervalSec) {
try {
if (netIf == null) {
netIf = sigar.getNetInterfaceList();
}
long tmpRxTotal = 0L;
long tmpTxTotal = 0L;

for (int i = 0; i < netIf.length; i++) {
NetInterfaceStat net = null;
try {
net = sigar.getNetInterfaceStat(netIf[i]);
} catch (SigarException e) {
// Ignore the exception when trying to stat network interface
Logger.println("A143", 300, "SigarException trying to stat network device " + netIf[i], e);
continue;
}
Map<String, Long> netMap = new HashMap<String, Long>();
long rxBytes = net.getRxBytes();
long txBytes = net.getTxBytes();

netMap.put(CounterConstants.HOST_NET_RX_BYTES, rxBytes);
netMap.put(CounterConstants.HOST_NET_TX_BYTES, txBytes);

Map<String, Long> preMap = previousNetworkStats.get(netIf[i]);

if (preMap != null) {
long rxDelta = (rxBytes - preMap.get(CounterConstants.HOST_NET_RX_BYTES)) / checkIntervalSec; // per sec delta
long txDelta = (txBytes - preMap.get(CounterConstants.HOST_NET_TX_BYTES)) / checkIntervalSec; // per sec delta

netMap.put(this.RX_DELTA, rxDelta);
netMap.put(this.TX_DELTA, txDelta);

tmpRxTotal += rxDelta;
tmpTxTotal += txDelta;
}
previousNetworkStats.put(netIf[i], netMap);
}

HostNetDiskPerf.rxTotalBytesPerSec = tmpRxTotal;
HostNetDiskPerf.txTotalBytesPerSec = tmpTxTotal;

} catch (SigarException se) {
Logger.println("A144", 60, "SigarException on net usage", se);
HostNetDiskPerf.rxTotalBytesPerSec = 0;
HostNetDiskPerf.txTotalBytesPerSec = 0;
}
}

private void diskIO(int checkIntervalSec) {
try {
if (fs == null) {
fs = sigar.getFileSystemList();
}
long tmpReadTotal = 0L;
long tmpWriteTotal = 0L;

for (int i = 0; i < fs.length; i++) {
FileSystemUsage usage = null;
try {
usage = sigar.getFileSystemUsage(fs[i].getDirName());
} catch (SigarException e) {
// Ignore the exception when trying to stat file interface
Logger.println("A145", 300, "SigarException trying to stat file system device " + fs[i], e);
continue;
}
Map<String, Long> fsMap = new HashMap<String, Long>();
long readBytes = usage.getDiskReadBytes();
long writeBytes = usage.getDiskWriteBytes();

fsMap.put(CounterConstants.HOST_DISK_READ_BYTES, readBytes);
fsMap.put(CounterConstants.HOST_DISK_WRITE_BYTES, writeBytes);

Map<String, Long> preMap = previousDiskStats.get(fs[i].getDevName());

if (preMap != null) {
long readDelta = (readBytes - preMap.get(CounterConstants.HOST_DISK_READ_BYTES)) / checkIntervalSec; // per sec delta
long writeDelta = (writeBytes - preMap.get(CounterConstants.HOST_DISK_WRITE_BYTES)) / checkIntervalSec; // per sec delta

fsMap.put(this.READ_DELTA, readDelta);
fsMap.put(this.WRITE_DELTA, writeDelta);

tmpReadTotal += readDelta;
tmpWriteTotal += writeDelta;
}
previousDiskStats.put(fs[i].getDevName(), fsMap);
}

HostNetDiskPerf.readTotalBytesPerSec = tmpReadTotal;
HostNetDiskPerf.writeTotalBytesPerSec = tmpWriteTotal;

} catch (SigarException se) {
Logger.println("A144", 60, "SigarException on net usage", se);
HostNetDiskPerf.rxTotalBytesPerSec = 0;
HostNetDiskPerf.txTotalBytesPerSec = 0;
}
}

}
48 changes: 35 additions & 13 deletions scouter.agent.host/src/scouter/agent/counter/task/HostPerf.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package scouter.agent.counter.task;

import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.NetStat;
import org.hyperic.sigar.NfsFileSystem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.SigarProxy;
import org.hyperic.sigar.SigarProxyCache;
import org.hyperic.sigar.Swap;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.counter.task;

import org.hyperic.sigar.*;
import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.counter.CounterBasket;
Expand All @@ -36,7 +46,7 @@ public class HostPerf {
MeterResource cpuMeter = new MeterResource();
MeterResource sysCpuMeter = new MeterResource();
MeterResource userCpuMeter = new MeterResource();

@Counter
public void process(CounterBasket pw) {
try {
Expand Down Expand Up @@ -101,6 +111,17 @@ void domain(CounterBasket pw) throws SigarException {
p.put(CounterConstants.HOST_TCPSTAT_TIM, new DecimalValue(tcpstat_time));
p.put(CounterConstants.HOST_TCPSTAT_EST, new DecimalValue(tcpstat_est));

p.put(CounterConstants.HOST_NET_RX_BYTES, new DecimalValue(HostNetDiskPerf.getRxTotalBytesPerSec()));
p.put(CounterConstants.HOST_NET_TX_BYTES, new DecimalValue(HostNetDiskPerf.getTxTotalBytesPerSec()));

p.put(CounterConstants.HOST_DISK_READ_BYTES, new DecimalValue(HostNetDiskPerf.getReadTotalBytesPerSec()));
p.put(CounterConstants.HOST_DISK_WRITE_BYTES, new DecimalValue(HostNetDiskPerf.getWriteTotalBytesPerSec()));

// System.out.println("rx:" + HostNetDiskPerf.getRxTotalBytesPerSec());
// System.out.println("tx:" + HostNetDiskPerf.getTxTotalBytesPerSec());
// System.out.println("read:" + HostNetDiskPerf.getReadTotalBytesPerSec());
// System.out.println("write:" + HostNetDiskPerf.getWriteTotalBytesPerSec());

p = pw.getPack(conf.getObjName(), TimeTypeEnum.FIVE_MIN);
p.put(CounterConstants.HOST_CPU, new FloatValue(cpu));
p.put(CounterConstants.HOST_SYSCPU, new FloatValue(sysCpu));
Expand All @@ -120,6 +141,7 @@ void domain(CounterBasket pw) throws SigarException {
p.put(CounterConstants.HOST_TCPSTAT_FIN, new DecimalValue(tcpstat_fin1 + tcpstat_fin2));
p.put(CounterConstants.HOST_TCPSTAT_TIM, new DecimalValue(tcpstat_time));
p.put(CounterConstants.HOST_TCPSTAT_EST, new DecimalValue(tcpstat_est));

SigarProxyCache.clear(sigar);
}

Expand Down
Loading