-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance(monitor): add druid monitor (#1088)
* add druid monitor * add druid monitor * format * add back connection cluster name * format * format * format * format * format * review * review * rename * review --------- Co-authored-by: ungreat <[email protected]>
- Loading branch information
Showing
12 changed files
with
943 additions
and
3 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
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
27 changes: 27 additions & 0 deletions
27
server/odc-service/src/main/java/com/oceanbase/odc/config/druid/DruidMonitor.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,27 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* 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.oceanbase.odc.config.druid; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.METHOD, ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface DruidMonitor { | ||
} |
53 changes: 53 additions & 0 deletions
53
server/odc-service/src/main/java/com/oceanbase/odc/config/druid/DruidMonitorAspect.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,53 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* 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.oceanbase.odc.config.druid; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.alibaba.druid.support.spring.stat.DruidStatInterceptor; | ||
|
||
@Aspect | ||
@Component | ||
public class DruidMonitorAspect { | ||
|
||
private final DruidStatInterceptor druidStatInterceptor; | ||
|
||
@Autowired | ||
public DruidMonitorAspect(DruidStatInterceptor druidStatInterceptor) { | ||
this.druidStatInterceptor = druidStatInterceptor; | ||
} | ||
|
||
@Pointcut("within(@org.springframework.stereotype.Controller *) || within(@org.springframework.web.bind.annotation.RestController *)") | ||
public void controllerMethods() {} | ||
|
||
@Around("@annotation(DruidMonitor)") | ||
public Object aroundDruidMonitor(ProceedingJoinPoint joinPoint) throws Throwable { | ||
return druidStatInterceptor.invoke(new JointPointMethodInvocationAdapter(joinPoint)); | ||
} | ||
|
||
@Around("controllerMethods()") | ||
public Object aroundDruidMonitorClass(ProceedingJoinPoint joinPoint) throws Throwable { | ||
return druidStatInterceptor.invoke(new JointPointMethodInvocationAdapter(joinPoint)); | ||
} | ||
|
||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...rvice/src/main/java/com/oceanbase/odc/config/druid/JointPointMethodInvocationAdapter.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,61 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* 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.oceanbase.odc.config.druid; | ||
|
||
import java.lang.reflect.AccessibleObject; | ||
import java.lang.reflect.Method; | ||
|
||
import org.aopalliance.intercept.MethodInvocation; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
|
||
class JointPointMethodInvocationAdapter implements MethodInvocation { | ||
private final ProceedingJoinPoint joinPoint; | ||
private final MethodSignature methodSignature; | ||
private final Method method; | ||
|
||
public JointPointMethodInvocationAdapter(ProceedingJoinPoint joinPoint) { | ||
this.joinPoint = joinPoint; | ||
this.methodSignature = (MethodSignature) joinPoint.getSignature(); | ||
this.method = methodSignature.getMethod(); | ||
} | ||
|
||
@Override | ||
public Object proceed() throws Throwable { | ||
return joinPoint.proceed(); | ||
} | ||
|
||
@Override | ||
public Object getThis() { | ||
return joinPoint.getThis(); | ||
} | ||
|
||
@Override | ||
public Object[] getArguments() { | ||
return joinPoint.getArgs(); | ||
} | ||
|
||
@Override | ||
public Method getMethod() { | ||
return method; | ||
} | ||
|
||
@Override | ||
public AccessibleObject getStaticPart() { | ||
return method; | ||
} | ||
} |
Oops, something went wrong.