-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11567 from 985492783/glcc
[ISSUE #10378]add lock query count and rt metrics
- Loading branch information
Showing
5 changed files
with
215 additions
and
2 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
59 changes: 59 additions & 0 deletions
59
lock/src/main/java/com/alibaba/nacos/lock/aspect/RequestLockAspect.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,59 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.lock.aspect; | ||
|
||
import com.alibaba.nacos.api.lock.remote.request.LockOperationRequest; | ||
import com.alibaba.nacos.api.lock.remote.response.LockOperationResponse; | ||
import com.alibaba.nacos.api.remote.request.RequestMeta; | ||
import com.alibaba.nacos.lock.monitor.LockMetricsMonitor; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* RequestLockAspect. | ||
* @author goumang.zh@alibaba-inc.com | ||
*/ | ||
@Aspect | ||
@Component | ||
public class RequestLockAspect { | ||
|
||
|
||
/** | ||
* count metrics and get handler time. | ||
*/ | ||
@SuppressWarnings("checkstyle:linelength") | ||
@Around(value = "execution(* com.alibaba.nacos.core.remote.RequestHandler.handleRequest(..)) && target(com.alibaba.nacos.lock.remote.rpc.handler.LockRequestHandler) && args(request, meta)", argNames = "pjp,request,meta") | ||
public Object lockMeterPoint(ProceedingJoinPoint pjp, LockOperationRequest request, RequestMeta meta) | ||
throws Throwable { | ||
long st = System.currentTimeMillis(); | ||
try { | ||
LockMetricsMonitor.getTotalMeter(request.getLockOperationEnum()).incrementAndGet(); | ||
LockOperationResponse result = (LockOperationResponse) pjp.proceed(); | ||
if (result.isSuccess()) { | ||
LockMetricsMonitor.getSuccessMeter(request.getLockOperationEnum()).incrementAndGet(); | ||
} | ||
return result; | ||
} finally { | ||
long rt = System.currentTimeMillis() - st; | ||
LockMetricsMonitor.getLockHandlerTimer().record(rt, TimeUnit.MILLISECONDS); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
lock/src/main/java/com/alibaba/nacos/lock/monitor/LockMemoryMonitor.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,40 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.lock.monitor; | ||
|
||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* memory monitor. | ||
* | ||
* @author goumang.zh@alibaba-inc.com | ||
*/ | ||
@Service | ||
public class LockMemoryMonitor { | ||
|
||
/** | ||
* auto clean metrics per-day. | ||
*/ | ||
@Scheduled(cron = "0 0 0 * * ?") | ||
public void clear() { | ||
LockMetricsMonitor.getGrpcLockTotal().set(0); | ||
LockMetricsMonitor.getGrpcLockSuccess().set(0); | ||
LockMetricsMonitor.getGrpcUnLockTotal().set(0); | ||
LockMetricsMonitor.getGrpcUnLockSuccess().set(0); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
lock/src/main/java/com/alibaba/nacos/lock/monitor/LockMetricsMonitor.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,111 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.lock.monitor; | ||
|
||
import com.alibaba.nacos.api.lock.remote.LockOperationEnum; | ||
import com.alibaba.nacos.core.monitor.NacosMeterRegistryCenter; | ||
import io.micrometer.core.instrument.ImmutableTag; | ||
import io.micrometer.core.instrument.Tag; | ||
import io.micrometer.core.instrument.Timer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* MetricsMonitor. | ||
* @author goumang.zh@alibaba-inc.com | ||
*/ | ||
public class LockMetricsMonitor { | ||
|
||
private static final String METER_REGISTRY = NacosMeterRegistryCenter.LOCK_STABLE_REGISTRY; | ||
|
||
private static AtomicInteger grpcLockSuccess = new AtomicInteger(); | ||
|
||
private static AtomicInteger grpcUnLockSuccess = new AtomicInteger(); | ||
|
||
private static AtomicInteger grpcLockTotal = new AtomicInteger(); | ||
|
||
private static AtomicInteger grpcUnLockTotal = new AtomicInteger(); | ||
|
||
private static AtomicInteger aliveLockCount = new AtomicInteger(); | ||
|
||
static { | ||
ImmutableTag immutableTag = new ImmutableTag("module", "lock"); | ||
List<Tag> tags = new ArrayList<>(); | ||
tags.add(immutableTag); | ||
tags.add(new ImmutableTag("name", "grpcLockTotal")); | ||
NacosMeterRegistryCenter.gauge(METER_REGISTRY, "nacos_monitor", tags, grpcLockTotal); | ||
|
||
tags = new ArrayList<>(); | ||
tags.add(immutableTag); | ||
tags.add(new ImmutableTag("name", "grpcLockSuccess")); | ||
NacosMeterRegistryCenter.gauge(METER_REGISTRY, "nacos_monitor", tags, grpcLockSuccess); | ||
|
||
tags = new ArrayList<>(); | ||
tags.add(immutableTag); | ||
tags.add(new ImmutableTag("name", "grpcUnLockTotal")); | ||
NacosMeterRegistryCenter.gauge(METER_REGISTRY, "nacos_monitor", tags, grpcUnLockTotal); | ||
|
||
tags = new ArrayList<>(); | ||
tags.add(immutableTag); | ||
tags.add(new ImmutableTag("name", "grpcUnLockSuccess")); | ||
NacosMeterRegistryCenter.gauge(METER_REGISTRY, "nacos_monitor", tags, grpcUnLockSuccess); | ||
|
||
tags = new ArrayList<>(); | ||
tags.add(immutableTag); | ||
tags.add(new ImmutableTag("name", "aliveLockCount")); | ||
NacosMeterRegistryCenter.gauge(METER_REGISTRY, "nacos_monitor", tags, aliveLockCount); | ||
} | ||
|
||
public static AtomicInteger getGrpcLockSuccess() { | ||
return grpcLockSuccess; | ||
} | ||
|
||
public static AtomicInteger getGrpcUnLockSuccess() { | ||
return grpcUnLockSuccess; | ||
} | ||
|
||
public static AtomicInteger getGrpcLockTotal() { | ||
return grpcLockTotal; | ||
} | ||
|
||
public static AtomicInteger getGrpcUnLockTotal() { | ||
return grpcUnLockTotal; | ||
} | ||
|
||
public static Timer getLockHandlerTimer() { | ||
return NacosMeterRegistryCenter | ||
.timer(METER_REGISTRY, "nacos_timer", "module", "lock", "name", "lockHandlerRt"); | ||
} | ||
|
||
public static AtomicInteger getSuccessMeter(LockOperationEnum lockOperationEnum) { | ||
if (lockOperationEnum == LockOperationEnum.ACQUIRE) { | ||
return grpcLockSuccess; | ||
} else { | ||
return grpcUnLockSuccess; | ||
} | ||
} | ||
|
||
public static AtomicInteger getTotalMeter(LockOperationEnum lockOperationEnum) { | ||
if (lockOperationEnum == LockOperationEnum.ACQUIRE) { | ||
return grpcLockTotal; | ||
} else { | ||
return grpcUnLockTotal; | ||
} | ||
} | ||
} |
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