jiangML opened a new issue, #30256:
URL: https://github.com/apache/shardingsphere/issues/30256
## Feature Request
**For English only**, other languages will not be accepted.
Please pay attention on issues you submitted, because we maybe need more
details.
If no response anymore and we cannot make decision by current information,
we will **close it**.
Please answer these questions before submitting your issue. Thanks!
### Is your feature request related to a problem?
```
public final class JDBCStateExporter implements MetricsExporter {
private final MetricConfiguration config = new
MetricConfiguration("jdbc_state", MetricCollectorType.GAUGE_METRIC_FAMILY,
"State of ShardingSphere-JDBC. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK");
@Override
public Optional<GaugeMetricFamilyMetricsCollector> export(final String
pluginType) {
Optional<ShardingSphereDriver> driver =
ShardingSphereDriverUtils.getShardingSphereDriver();
if (!driver.isPresent()) {
return Optional.empty();
}
GaugeMetricFamilyMetricsCollector result =
MetricsCollectorRegistry.get(config, pluginType);
result.cleanMetrics();
DriverDataSourceCache dataSourceCache =
AgentReflectionUtils.getFieldValue(driver.get(), "dataSourceCache");
Map<String, DataSource> dataSourceMap =
AgentReflectionUtils.getFieldValue(dataSourceCache, "dataSourceMap");
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
ShardingSphereDataSource dataSource = (ShardingSphereDataSource)
entry.getValue();
ContextManager contextManager =
AgentReflectionUtils.getFieldValue(dataSource, "contextManager");
result.addMetric(Collections.emptyList(),
contextManager.getInstanceContext().getInstance().getState().getCurrentState().ordinal());
}
return Optional.of(result);
}
}
```
```
public final class JDBCMetaDataInfoExporter implements MetricsExporter {
private final MetricConfiguration config = new
MetricConfiguration("jdbc_meta_data_info",
MetricCollectorType.GAUGE_METRIC_FAMILY, "Meta data information
of ShardingSphere-JDBC",
Arrays.asList("database", "type"), Collections.emptyMap());
@Override
public Optional<GaugeMetricFamilyMetricsCollector> export(final String
pluginType) {
Optional<ShardingSphereDriver> driver =
ShardingSphereDriverUtils.getShardingSphereDriver();
if (!driver.isPresent()) {
return Optional.empty();
}
GaugeMetricFamilyMetricsCollector result =
MetricsCollectorRegistry.get(config, pluginType);
result.cleanMetrics();
DriverDataSourceCache dataSourceCache =
AgentReflectionUtils.getFieldValue(driver.get(), "dataSourceCache");
Map<String, DataSource> dataSourceMap =
AgentReflectionUtils.getFieldValue(dataSourceCache, "dataSourceMap");
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
ShardingSphereDataSource dataSource = (ShardingSphereDataSource)
entry.getValue();
String databaseName =
AgentReflectionUtils.getFieldValue(dataSource, "databaseName");
ContextManager contextManager =
AgentReflectionUtils.getFieldValue(dataSource, "contextManager");
result.addMetric(Arrays.asList(databaseName,
"storage_unit_count"), contextManager.getStorageUnits(databaseName).size());
}
return Optional.of(result);
}
}
```
Simplified acquisition of ShardingSphereDataSource
### Describe the feature you would like.
Simplified acquisition of ShardingSphereDataSource
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]