use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class DataSourceConnectionInterceptor method attachment.
void attachment(Advice advice) {
try {
HikariDataSource target = (HikariDataSource) advice.getTarget();
ResourceManager.set(new Attachment(target.getJdbcUrl(), "hikari", Type.DataBaseType.types(), new HikariTemplate().setUrl(target.getJdbcUrl()).setUsername(target.getUsername()).setPassword(target.getPassword()).setDriverClassName(target.getDriverClassName()).setConnectionTimeout(target.getConnectionTimeout()).setConnectionTestQuery(target.getConnectionTestQuery()).setIdleTimeout(target.getIdleTimeout()).setMaxLifetime(target.getMaxLifetime()).setMinimumIdle(target.getIdleTimeout()).setMaximumPoolSize(target.getMaximumPoolSize()).setValidationTimeout(target.getValidationTimeout())));
} catch (Throwable t) {
logger.error(t.getMessage());
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class TraceTraceEncoder method attachment.
void attachment(AbstractContext ctx) {
if (ctx.isClusterTest) {
return;
}
try {
if (ctx.ext != null) {
Object t = ctx.ext;
if (Attachment.class.isAssignableFrom(t.getClass())) {
Attachment attachment = (Attachment) t;
Object key = Converter.TemplateConverter.ofClass(attachment.getExt().getClass()).getKey();
ctx.ext = key + "@##" + JSON.toJSONString(attachment);
}
return;
}
String middleware = PradarCoreUtils.makeLogSafe(ctx.getMiddlewareName() == null ? "" : ctx.getMiddlewareName());
if (StringUtil.isEmpty(middleware)) {
return;
}
Object t = ResourceManager.get(ctx.index, middleware);
if (t == null) {
String serviceName = PradarCoreUtils.makeLogSafe(ctx.getServiceName() == null ? "" : ctx.getServiceName());
t = ResourceManager.get(serviceName, middleware);
if (t == null) {
String methodName = PradarCoreUtils.makeLogSafe(ctx.getMethodName() == null ? "" : ctx.getMethodName());
t = ResourceManager.get(serviceName + methodName, middleware);
if (t == null) {
return;
}
}
}
ctx.ext = t;
if (ctx.ext instanceof Attachment) {
Attachment attachment = (Attachment) ctx.ext;
Object key = Converter.TemplateConverter.ofClass(attachment.getExt().getClass()).getKey();
ctx.ext = key + "@##" + JSON.toJSONString(ctx.ext);
}
} catch (Throwable t) {
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class SpringRedisClientInfoCollector method attachment.
/**
* 业务流量的信息采集
*
* @param advice
*/
protected void attachment(Advice advice) {
try {
if (Pradar.isClusterTest()) {
return;
}
LettuceConnectionFactory biz = (LettuceConnectionFactory) advice.getTarget();
Object standaloneConfiguration = biz.getStandaloneConfiguration();
Object clusterConfiguration = biz.getClusterConfiguration();
Object sentinelConfiguration = biz.getSentinelConfiguration();
if (clusterConfiguration != null) {
Set<RedisNode> nodeSet = ((RedisClusterConfiguration) clusterConfiguration).getClusterNodes();
StringBuilder builder = new StringBuilder();
for (RedisNode node : nodeSet) {
String host = node.getHost();
String port = String.valueOf(node.getPort());
builder.append(host.concat(":").concat(port)).append(",");
}
String nodes = builder.deleteCharAt(builder.length() - 1).toString();
String password = null;
try {
char[] passwdbyte = ((RedisClusterConfiguration) clusterConfiguration).getPassword().get();
password = new String(passwdbyte);
} catch (NoSuchElementException e) {
//
}
ResourceManager.set(new Attachment(Arrays.asList(nodes.split(",")), "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceClusterTemplate().setNodes(nodes).setPassword(password)));
} else if (sentinelConfiguration != null) {
RedisSentinelConfiguration redisSentinelConfiguration = (RedisSentinelConfiguration) sentinelConfiguration;
String masterName = redisSentinelConfiguration.getMaster().getName();
String password = null;
try {
char[] passwdbyte = redisSentinelConfiguration.getPassword().get();
password = new String(passwdbyte);
} catch (NoSuchElementException e) {
//
}
Integer database = Integer.parseInt(String.valueOf(redisSentinelConfiguration.getDatabase()));
Set<RedisNode> nodeSet = redisSentinelConfiguration.getSentinels();
StringBuilder builder = new StringBuilder();
for (RedisNode node : nodeSet) {
String host = node.getHost();
String port = String.valueOf(node.getPort());
builder.append(host.concat(":").concat(port)).append(",");
}
String nodes = builder.deleteCharAt(builder.length() - 1).toString();
List<String> sentinelRemoteAddress = new ArrayList<String>();
try {
AbstractRedisClient client = Reflect.on(biz).get("client");
ChannelGroup channelGroup = Reflect.on(client).get("channels");
Iterator iterator = channelGroup.iterator();
while (iterator.hasNext()) {
Object o = iterator.next();
if (o instanceof NioSocketChannel) {
NioSocketChannel channel = (NioSocketChannel) o;
InetSocketAddress inetSocketAddress = channel.remoteAddress();
String host = inetSocketAddress.getAddress().getHostName();
String port = String.valueOf(inetSocketAddress.getPort());
sentinelRemoteAddress.add(host.concat(":").concat(port));
}
}
} catch (Throwable t) {
logger.error(Throwables.getStackTraceAsString(t));
}
sentinelRemoteAddress.addAll(Arrays.asList(nodes.split(",")));
ResourceManager.set(new Attachment(sentinelRemoteAddress, "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceSentinelTemplate().setNodes(nodes).setPassword(password).setMaster(masterName).setDatabase(database)));
} else /**
*standalone肯定不为空 放后面 因为可能为localhost
*/
if (standaloneConfiguration != null && !("localhost".equals(((RedisStandaloneConfiguration) standaloneConfiguration).getHostName()))) {
RedisStandaloneConfiguration configuration = (RedisStandaloneConfiguration) standaloneConfiguration;
String host = configuration.getHostName();
Integer port = configuration.getPort();
Integer db = configuration.getDatabase();
String password = null;
try {
char[] passwdbyte = configuration.getPassword().get();
password = new String(passwdbyte);
} catch (NoSuchElementException e) {
//
}
String node = host.concat(":").concat(String.valueOf(port));
ResourceManager.set(new Attachment(Arrays.asList(node), "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceSingleTemplate().setNodes(node).setPassword(password).setDatabase(db)));
}
} catch (Throwable t) {
logger.error("[redis-lettuce] collector spring biz info error , {}", Throwables.getStackTraceAsString(t));
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class RedisMasterSlaveAttachRedisURIsInterceptor method cacheNodesInfo.
void cacheNodesInfo(List<RedisURI> redisURIS) {
boolean isSentinel = false;
try {
List<String> indexes = new ArrayList<String>();
StringBuilder nodeBuilder = new StringBuilder();
String password = null;
String nodes = "";
String db = "";
for (RedisURI redisURI : redisURIS) {
/**
* 先判断是否哨兵模式,如果是哨兵模式,取里面的sentinels,masterId为sentinelMasterId
*/
if (!StringUtil.isEmpty(redisURI.getSentinelMasterId())) {
isSentinel = true;
String sentinelMasterId = redisURI.getSentinelMasterId();
List<RedisURI> lists = redisURI.getSentinels();
for (RedisURI inner : lists) {
String node = inner.getHost().concat(":").concat(String.valueOf(inner.getPort()));
indexes.add(node);
nodeBuilder.append(node).append(",");
password = inner.getPassword() == null ? null : new String(inner.getPassword());
db = String.valueOf(inner.getDatabase());
}
nodes = nodeBuilder.deleteCharAt(nodeBuilder.length() - 1).toString();
Attachment attachment = new Attachment(indexes, "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceSentinelTemplate().setMaster(sentinelMasterId).setNodes(nodes).setPassword(password));
ResourceManager.set(attachment);
}
if (isSentinel) {
continue;
}
/**
* 主从模式,lettuce的主从不需要用户关注master,为了页面展示,放一个节点到Master
*/
String node = redisURI.getHost().concat(":").concat(String.valueOf(redisURI.getPort()));
indexes.add(node);
nodeBuilder.append(node).append(",");
password = redisURI.getPassword() == null ? null : new String(redisURI.getPassword());
db = String.valueOf(redisURI.getDatabase());
}
nodes = nodeBuilder.deleteCharAt(nodeBuilder.length() - 1).toString();
Attachment attachment = new Attachment(indexes, "redis-lettuce", new String[] { "redis" }, new RedisTemplate.LettuceMasterSlaveTemplate().setMaster(null).setNodes(nodes).setPassword(password));
ResourceManager.set(attachment);
} catch (Throwable t) {
logger.error(ThrowableUtils.toString(t));
}
}
use of com.pamirs.attach.plugin.dynamic.Attachment in project LinkAgent by shulieTech.
the class BaseRedissonTimeSeriesMethodInterceptor method attachment.
/**
* 入参是org.redisson.config.BaseConfig
* 但是有的版本是私有类
*
* @param config
*/
private void attachment(Object config) {
try {
if (Pradar.isClusterTest() || config == null) {
return;
}
ClusterServersConfig config1 = null;
Reflect reflect = Reflect.on(config);
String password = null;
try {
password = reflect.get("password");
} catch (Throwable t) {
}
Integer database = null;
try {
database = Integer.parseInt(String.valueOf(reflect.get("database")));
} catch (Throwable t) {
}
AbstractTemplate template;
if (config instanceof ClusterServersConfig) {
List nodeAddresses = reflect.get("nodeAddresses");
StringBuilder nodeBuilder = new StringBuilder();
for (Object object : nodeAddresses) {
if (URI.class.isAssignableFrom(object.getClass())) {
URI uri = (URI) object;
nodeBuilder.append(uri.getHost().concat(":").concat(String.valueOf(uri.getPort()))).append(",");
} else if (String.class.isAssignableFrom(object.getClass())) {
nodeBuilder.append(removePre(object.toString())).append(",");
}
}
String nodes = nodeBuilder.deleteCharAt(nodeBuilder.length() - 1).toString();
template = new RedisTemplate.RedissionClusterTemplate().setNodes(nodes).setPassword(password);
} else if (config instanceof MasterSlaveServersConfig) {
Set nodeAddresses = reflect.get("slaveAddresses");
StringBuilder nodeBuilder = new StringBuilder();
for (Object object : nodeAddresses) {
if (URI.class.isAssignableFrom(object.getClass())) {
URI uri = (URI) object;
nodeBuilder.append(uri.getHost().concat(":").concat(String.valueOf(uri.getPort()))).append(",");
} else if (String.class.isAssignableFrom(object.getClass())) {
nodeBuilder.append(removePre(object.toString())).append(",");
}
}
String nodes = nodeBuilder.deleteCharAt(nodeBuilder.length() - 1).toString();
Object masterNodeObj = reflect.get("masterAddress");
String masterAddr = "";
if (masterNodeObj instanceof URI) {
masterAddr = ((URI) masterNodeObj).getHost().concat(":").concat(String.valueOf(((URI) masterNodeObj).getPort()));
;
} else {
masterAddr = removePre(String.valueOf(masterNodeObj));
}
template = new RedissonMasterSlaveTemplate().setMaster(masterAddr).setNodes(nodes).setPassword(password).setDatabase(database);
} else if (config instanceof SingleServerConfig) {
String nodes = "";
Object address = Reflect.on(config).get("address");
if (String.class.isAssignableFrom(address.getClass())) {
nodes = removePre((String) address);
} else if (URI.class.isAssignableFrom(address.getClass())) {
URI uri = (URI) address;
nodes = uri.getHost().concat(":").concat(String.valueOf(uri.getPort()));
}
template = new RedissionSingleTemplate().setNodes(nodes).setPassword(password).setDatabase(database);
} else if (config instanceof SentinelServersConfig) {
List sentinelAddresses = reflect.get("sentinelAddresses");
StringBuilder nodeBuilder = new StringBuilder();
for (Object object : sentinelAddresses) {
if (URI.class.isAssignableFrom(object.getClass())) {
URI uri = (URI) object;
nodeBuilder.append(uri.getHost().concat(":").concat(String.valueOf(uri.getPort()))).append(",");
} else if (String.class.isAssignableFrom(object.getClass())) {
nodeBuilder.append(removePre(object.toString())).append(",");
}
}
String nodes = nodeBuilder.deleteCharAt(nodeBuilder.length() - 1).toString();
template = new RedissionSentinelTemplate().setNodes(nodes).setMaster(removePre(((SentinelServersConfig) config).getMasterName())).setNodes(nodes).setDatabase((database));
} else if (config instanceof ReplicatedServersConfig) {
List nodeAddresses = reflect.get("nodeAddresses");
StringBuilder nodeBuilder = new StringBuilder();
for (Object object : nodeAddresses) {
if (URI.class.isAssignableFrom(object.getClass())) {
URI uri = (URI) object;
nodeBuilder.append(uri.getHost().concat(":").concat(String.valueOf(uri.getPort()))).append(",");
} else if (String.class.isAssignableFrom(object.getClass())) {
nodeBuilder.append(removePre(object.toString())).append(",");
}
}
String nodes = nodeBuilder.deleteCharAt(nodeBuilder.length() - 1).toString();
template = new RedissonReplicatedTemplate().setDatabase(database).setNodes(nodes).setPassword(password);
} else {
LOGGER.error("Redisson not instanceof any know config:{}", config);
return;
}
final Attachment attachment = new Attachment(null, RedissonConstants.PLUGIN_NAME, new String[] { RedissonConstants.MIDDLEWARE_NAME }, template);
// ResourceManager.set(attachment);
Pradar.getInvokeContext().setExt(attachment);
} catch (Throwable t) {
LOGGER.error("Redisson attachment error", t);
}
}
Aggregations