-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add MonitorBytesHandler, MonitorQpsHandler, JVMGCMetrics, Update Metr…
…icsCollector
- Loading branch information
1 parent
5580762
commit fc5f491
Showing
16 changed files
with
262 additions
and
22 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
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
63 changes: 63 additions & 0 deletions
63
piccolo-core/src/main/java/io/github/ukuz/piccolo/core/handler/MonitorBytesHandler.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,63 @@ | ||
/* | ||
* Copyright 2019 ukuz90 | ||
* | ||
* 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 io.github.ukuz.piccolo.core.handler; | ||
|
||
import io.github.ukuz.piccolo.monitor.MetricsMonitor; | ||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelDuplexHandler; | ||
import io.netty.channel.ChannelHandler; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelPromise; | ||
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; | ||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; | ||
|
||
/** | ||
* @author ukuz90 | ||
*/ | ||
@ChannelHandler.Sharable | ||
public class MonitorBytesHandler extends ChannelDuplexHandler { | ||
|
||
private final String serverName; | ||
|
||
public MonitorBytesHandler(String serverName) { | ||
this.serverName = serverName; | ||
} | ||
|
||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { | ||
if (msg instanceof ByteBuf) { | ||
MetricsMonitor.getQuestBytes(serverName).increment(((ByteBuf) msg).readableBytes()); | ||
} else if (msg instanceof BinaryWebSocketFrame) { | ||
MetricsMonitor.getQuestBytes(serverName).increment(((BinaryWebSocketFrame)msg).content().readableBytes()); | ||
} else if (msg instanceof TextWebSocketFrame) { | ||
MetricsMonitor.getQuestBytes(serverName).increment(((TextWebSocketFrame)msg).content().readableBytes()); | ||
} | ||
super.channelRead(ctx, msg); | ||
} | ||
|
||
@Override | ||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { | ||
if (msg instanceof ByteBuf) { | ||
MetricsMonitor.getResponseBytes(serverName).increment(((ByteBuf) msg).readableBytes()); | ||
} else if (msg instanceof BinaryWebSocketFrame) { | ||
MetricsMonitor.getResponseBytes(serverName).increment(((BinaryWebSocketFrame)msg).content().readableBytes()); | ||
} else if (msg instanceof TextWebSocketFrame) { | ||
MetricsMonitor.getResponseBytes(serverName).increment(((TextWebSocketFrame)msg).content().readableBytes()); | ||
} | ||
super.write(ctx, msg, promise); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
piccolo-core/src/main/java/io/github/ukuz/piccolo/core/handler/MonitorQpsHandler.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,47 @@ | ||
/* | ||
* Copyright 2019 ukuz90 | ||
* | ||
* 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 io.github.ukuz.piccolo.core.handler; | ||
|
||
import io.github.ukuz.piccolo.monitor.MetricsMonitor; | ||
import io.netty.channel.ChannelDuplexHandler; | ||
import io.netty.channel.ChannelHandler; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelPromise; | ||
|
||
/** | ||
* @author ukuz90 | ||
*/ | ||
@ChannelHandler.Sharable | ||
public class MonitorQpsHandler extends ChannelDuplexHandler { | ||
|
||
private final String serverName; | ||
|
||
public MonitorQpsHandler(String serverName) { | ||
this.serverName = serverName; | ||
} | ||
|
||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { | ||
MetricsMonitor.getQuestCount(serverName).increment(); | ||
super.channelRead(ctx, msg); | ||
} | ||
|
||
@Override | ||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { | ||
MetricsMonitor.getResponseCount(serverName).increment(); | ||
super.write(ctx, msg, promise); | ||
} | ||
} |
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
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
63 changes: 63 additions & 0 deletions
63
piccolo-monitor/src/main/java/io/github/ukuz/piccolo/monitor/JVMGCMetrics.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,63 @@ | ||
/* | ||
* Copyright 2019 ukuz90 | ||
* | ||
* 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 io.github.ukuz.piccolo.monitor; | ||
|
||
import io.github.ukuz.piccolo.monitor.quota.GCQuota; | ||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
|
||
/** | ||
* @author ukuz90 | ||
*/ | ||
public class JVMGCMetrics implements MeterBinder { | ||
|
||
private final GCQuota gcQuota; | ||
|
||
private static final String COUNT = "count"; | ||
private static final String TIME = "time"; | ||
|
||
public JVMGCMetrics(GCQuota gcQuota) { | ||
this.gcQuota = gcQuota; | ||
} | ||
|
||
@Override | ||
public void bindTo(MeterRegistry registry) { | ||
Gauge.builder("jvm.gc.collection.count", gcQuota, GCQuota::youngGcCollectionCount) | ||
.description("") | ||
.baseUnit(COUNT) | ||
.tag("name", "young gc") | ||
.register(registry); | ||
|
||
Gauge.builder("jvm.gc.collection.count", gcQuota, GCQuota::fullGcCollectionCount) | ||
.description("") | ||
.baseUnit(COUNT) | ||
.tag("name", "full gc") | ||
.register(registry); | ||
|
||
Gauge.builder("jvm.gc.collection.time", gcQuota, GCQuota::youngGcCollectionTime) | ||
.description("") | ||
.baseUnit(TIME) | ||
.tag("name", "young gc") | ||
.register(registry); | ||
|
||
Gauge.builder("jvm.gc.collection.time", gcQuota, GCQuota::fullGcCollectionTime) | ||
.description("") | ||
.baseUnit(TIME) | ||
.tag("name", "full gc") | ||
.register(registry); | ||
} | ||
} |
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.