Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2496] Add datasource metric collection
Apply dbcp2 plugin to collect datasource metrics
- Loading branch information
1 parent
7b2c380
commit 73af3b1
Showing
10 changed files
with
333 additions
and
25 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
39 changes: 39 additions & 0 deletions
39
...bcp2/src/main/java/com/navercorp/pinpoint/plugin/commons/dbcp2/CommonsDbcp2Constants.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,39 @@ | ||
/* | ||
* Copyright 2017 NAVER Corp. | ||
* | ||
* 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.navercorp.pinpoint.plugin.commons.dbcp2; | ||
|
||
import com.navercorp.pinpoint.common.trace.ServiceType; | ||
import com.navercorp.pinpoint.common.trace.ServiceTypeFactory; | ||
|
||
/** | ||
* @author Taejin Koo | ||
*/ | ||
public class CommonsDbcp2Constants { | ||
|
||
public static final String SCOPE = "DBCP2_SCOPE"; | ||
|
||
public static final ServiceType SERVICE_TYPE = ServiceTypeFactory.of(6052, "DBCP2"); | ||
|
||
public static final String ACCESSOR_DATASOURCE_MONITOR = "com.navercorp.pinpoint.plugin.commons.dbcp2.DataSourceMonitorAccessor"; | ||
|
||
public static final String INTERCEPTOR_CONSTRUCTOR = "com.navercorp.pinpoint.plugin.commons.dbcp2.interceptor.DataSourceConstructorInterceptor"; | ||
public static final String INTERCEPTOR_CLOSE = "com.navercorp.pinpoint.plugin.commons.dbcp2.interceptor.DataSourceCloseInterceptor"; | ||
|
||
public static final String INTERCEPTOR_GET_CONNECTION = "com.navercorp.pinpoint.plugin.commons.dbcp2.interceptor.DataSourceGetConnectionInterceptor"; | ||
public static final String INTERCEPTOR_CLOSE_CONNECTION = "com.navercorp.pinpoint.plugin.commons.dbcp2.interceptor.DataSourceCloseConnectionInterceptor"; | ||
|
||
} |
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
.../src/main/java/com/navercorp/pinpoint/plugin/commons/dbcp2/DataSourceMonitorAccessor.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 2017 NAVER Corp. | ||
* | ||
* 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.navercorp.pinpoint.plugin.commons.dbcp2; | ||
|
||
/** | ||
* @author Taejin Koo | ||
*/ | ||
public interface DataSourceMonitorAccessor { | ||
|
||
void _$PINPOINT$_setDataSourceMonitor(Dbcp2DataSourceMonitor dataSourceMonitor); | ||
Dbcp2DataSourceMonitor _$PINPOINT$_getDataSourceMonitor(); | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...cp2/src/main/java/com/navercorp/pinpoint/plugin/commons/dbcp2/Dbcp2DataSourceMonitor.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 @@ | ||
/* | ||
* Copyright 2017 NAVER Corp. | ||
* | ||
* 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.navercorp.pinpoint.plugin.commons.dbcp2; | ||
|
||
import com.navercorp.pinpoint.bootstrap.plugin.monitor.DataSourceMonitor; | ||
import com.navercorp.pinpoint.common.trace.ServiceType; | ||
import org.apache.commons.dbcp2.BasicDataSource; | ||
|
||
/** | ||
* @author Taejin Koo | ||
*/ | ||
public class Dbcp2DataSourceMonitor implements DataSourceMonitor { | ||
|
||
private final BasicDataSource dataSource; | ||
private volatile boolean closed = false; | ||
|
||
public Dbcp2DataSourceMonitor(BasicDataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@Override | ||
public ServiceType getServiceType() { | ||
return CommonsDbcp2Constants.SERVICE_TYPE; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUrl() { | ||
return dataSource.getUrl(); | ||
} | ||
|
||
@Override | ||
public int getActiveConnectionSize() { | ||
return dataSource.getNumActive(); | ||
} | ||
|
||
@Override | ||
public int getMaxConnectionSize() { | ||
return dataSource.getMaxTotal(); | ||
} | ||
|
||
@Override | ||
public boolean isDisabled() { | ||
return closed; | ||
} | ||
|
||
public void close() { | ||
closed = true; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...rcorp/pinpoint/plugin/commons/dbcp2/interceptor/DataSourceCloseConnectionInterceptor.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,46 @@ | ||
/* | ||
* Copyright 2016 NAVER Corp. | ||
* | ||
* 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.navercorp.pinpoint.plugin.commons.dbcp2.interceptor; | ||
|
||
import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor; | ||
import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; | ||
import com.navercorp.pinpoint.bootstrap.context.TraceContext; | ||
import com.navercorp.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptorForPlugin; | ||
import com.navercorp.pinpoint.bootstrap.interceptor.annotation.Scope; | ||
import com.navercorp.pinpoint.bootstrap.interceptor.annotation.TargetMethod; | ||
import com.navercorp.pinpoint.plugin.commons.dbcp2.CommonsDbcp2Constants; | ||
|
||
@Scope(CommonsDbcp2Constants.SCOPE) | ||
@TargetMethod(name="close") | ||
public class DataSourceCloseConnectionInterceptor extends SpanEventSimpleAroundInterceptorForPlugin { | ||
|
||
public DataSourceCloseConnectionInterceptor(TraceContext traceContext, MethodDescriptor descriptor) { | ||
super(traceContext, descriptor); | ||
} | ||
|
||
@Override | ||
public void doInBeforeTrace(SpanEventRecorder recorder, final Object target, Object[] args) { | ||
} | ||
|
||
@Override | ||
public void doInAfterTrace(SpanEventRecorder trace, Object target, Object[] args, Object result, Throwable throwable) { | ||
trace.recordServiceType(CommonsDbcp2Constants.SERVICE_TYPE); | ||
trace.recordApi(getMethodDescriptor()); | ||
trace.recordException(throwable); | ||
} | ||
|
||
} |
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.