forked from worstcase/gumshoe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mbeans for socketIO and unclosed sockets
- Loading branch information
Showing
7 changed files
with
274 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
gumshoe-probes/src/main/java/com/dell/gumshoe/socket/io/SocketIOMBeanImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.dell.gumshoe.socket.io; | ||
|
||
import com.dell.gumshoe.Probe; | ||
import com.dell.gumshoe.socket.IO.IOStats; | ||
import com.dell.gumshoe.stack.Stack; | ||
import com.dell.gumshoe.stats.ValueReporter; | ||
import com.dell.gumshoe.stats.ValueReporter.StreamReporter; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.util.Map; | ||
|
||
public class SocketIOMBeanImpl implements SocketIOMBean { | ||
private final Probe probe; | ||
|
||
public SocketIOMBeanImpl(Probe probe) { | ||
this.probe = probe; | ||
} | ||
|
||
@Override | ||
public void setEnabled(boolean enabled) { | ||
probe.getIOMonitor().setEnabled(enabled); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return probe.getIOMonitor().isEnabled(); | ||
} | ||
|
||
@Override | ||
public String getReport() { | ||
final ByteArrayOutputStream rawOut = new ByteArrayOutputStream(); | ||
final PrintStream out = new PrintStream(rawOut); | ||
final ValueReporter<SocketIODetailAdder>.StreamReporter streamer = probe.getIOReporter().new StreamReporter(out); | ||
final Map<Stack,SocketIODetailAdder> values = probe.getIOAccumulator().getStats(); | ||
streamer.statsReported(values); | ||
return rawOut.toString(); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
probe.getIOAccumulator().reset(); | ||
} | ||
|
||
@Override | ||
public void setReportingFrequency(long millis) { | ||
probe.getIOReporter().scheduleReportTimer(probe.getTimer(), millis); | ||
} | ||
|
||
@Override | ||
public long getReportingFrequency() { | ||
return probe.getIOReporter().getReportTimerFrequency(); | ||
} | ||
|
||
@Override | ||
public void setShutdownReportEnabled(boolean enabled) { | ||
if(enabled) { | ||
probe.addShutdownHook(probe.getIOReporter().getShutdownHook()); | ||
} else { | ||
probe.removeShutdownHook(probe.getIOReporter().getShutdownHook()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isShutdownReportEnabled() { | ||
return probe.isShutdownHookEnabled(probe.getIOReporter().getShutdownHook()); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
gumshoe-probes/src/main/java/com/dell/gumshoe/socket/unclosed/SocketCloseMBeanImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.dell.gumshoe.socket.unclosed; | ||
|
||
import com.dell.gumshoe.Probe; | ||
import com.dell.gumshoe.stack.Stack; | ||
import com.dell.gumshoe.stats.ValueReporter; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.util.Map; | ||
|
||
public class SocketCloseMBeanImpl implements SocketCloseMonitorMBean { | ||
private final Probe probe; | ||
|
||
public SocketCloseMBeanImpl(Probe probe) { | ||
this.probe = probe; | ||
} | ||
|
||
@Override public boolean isEnabled() { return probe.getUnclosedMonitor().isEnabled(); } | ||
@Override public void setEnabled(boolean enabled) { probe.getUnclosedMonitor().setEnabled(enabled); } | ||
|
||
@Override | ||
public String getReport(long age) { | ||
final ByteArrayOutputStream rawOut = new ByteArrayOutputStream(); | ||
final PrintStream out = new PrintStream(rawOut); | ||
final ValueReporter<UnclosedStats>.StreamReporter streamer = probe.getUnclosedReporter().new StreamReporter(out); | ||
final Map<Stack,UnclosedStats> values = probe.getUnclosedMonitor().getStats(age); | ||
streamer.statsReported(values); | ||
return rawOut.toString(); | ||
} | ||
|
||
@Override | ||
public void setReportingFrequency(long millis) { | ||
probe.getUnclosedReporter().scheduleReportTimer(probe.getTimer(), millis); | ||
} | ||
|
||
@Override | ||
public long getReportingFrequency() { | ||
return probe.getUnclosedReporter().getReportTimerFrequency(); | ||
} | ||
|
||
@Override | ||
public void setClearClosedSocketsInterval(int numberOfSockets) { | ||
probe.getUnclosedMonitor().setClearClosedSocketsInterval(numberOfSockets); | ||
} | ||
|
||
@Override | ||
public int getClearClosedSocketsInterval() { | ||
return probe.getUnclosedMonitor().getClearClosedSocketsInterval(); | ||
} | ||
|
||
@Override | ||
public void setShutdownReportEnabled(boolean enabled) { | ||
if(enabled) { | ||
probe.addShutdownHook(probe.getUnclosedReporter().getShutdownHook()); | ||
} else { | ||
probe.removeShutdownHook(probe.getUnclosedReporter().getShutdownHook()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isShutdownReportEnabled() { | ||
return probe.isShutdownHookEnabled(probe.getUnclosedReporter().getShutdownHook()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.