我正在尝试使用codahale指标将指标添加到普通Java应用程序.我想使用@Timed注释,但我不清楚它使用哪个MetricRegistry,或者如何告诉它使用哪个MetricRegistry.该应用程序是一个普通的Java 8应用程序,使用Maven 3构建,没有Spring,没有Hibernate.
我在dropwizard文档中找不到有关如何实现@Timed的任何文档:https://dropwizard.github.io/metrics/3.1.0/manual/
我添加了这些依赖项:
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-annotation</artifactId>
<version>3.0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我使用对Timer的编程调用时,我可以获得报告,因为我知道使用了哪些MetricsRegistry:
static final MetricRegistry metrics = new MetricRegistry();
private void update() throws SQLException {
Timer.Context time = metrics.timer("domainobject.update").time();
try {
[...]
} finally {
time.stop();
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用更优雅的@Timed注释时,我不知道使用了哪个注册表,因此我无法创建一个记者,这意味着我无法报告指标(我甚至不确定这是否确实任何东西):
@Timed(name = "domainobject.update")
private void update() throws SQLException {
[...]
}
Run Code Online (Sandbox Code Playgroud)
请告知如何使@Timed和其他Metrics注释在常规Java应用程序中工作.
附加信息:我发现这个奇怪的原因是我添加了Lombok框架和@ Slf4j注释确实有效.我在maven pom.xml中添加了Lombok作为依赖项:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.8</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我可以使用@ Sl4fj类注释向类中添加一个记录器,而不会使成员变量混乱:
@Slf4j
public class App {
public void logsome(){
log.info("Hello there");
}
} …Run Code Online (Sandbox Code Playgroud) 我需要为客户分析一个java应用程序.这是一个eclipse/maven项目,所以我决定使用eclipse TPTP(http://www.eclipse.org/tptp).
我尝试通过标准eclipse安装的更新管理器安装eclipse TPTP,但我放弃了,因为令人难以置信的复杂设置和下载具有非常神秘的名称的依赖项.
然后我从http://www.eclipse.org/tptp/home/downloads/?ver=4.5.1下载了"all in one TPTP 4.5.1"软件包,但是当我启动它时会弹出一个错误说"eclipse可执行程序启动程序无法找到它的伴随共享库".
我正在运行Windows XP,Sun Java 1.5,并在解压缩的eclipse TPTP安装中单击"eclipse.exe".
我需要做些什么才能让eclipse运行TPTP?
我正在构建一个Wicket Web应用程序,它将不得不处理大量的同时请求.我已经设置了一个测试环境和一些jmeter脚本来进行负载测试,我注意到如果我使大多数页面无状态,我可以减少应用程序的CPU和内存占用.
我已经在最大页面的onBeforeRender()方法中添加了代码,以向我展示哪些组件导致我的页面有状态.这是我检测到的代码:
@Override
protected void onBeforeRender() {
if (!getSession().isTemporary()) {
visitChildren(Component.class, new IVisitor<Component>() {
@Override
public Object component(Component component) {
String pageClassName = AbstractStatelessBasePage.this.getClass().getName();
if (!component.isStateless()) {
String msg = pageClassName+" is stateful because of stateful component " + component.getClass().getName() + " with id " + component.getId() + ".";
List<IBehavior> behaviourList = component.getBehaviors();
for (IBehavior iBehavior : behaviourList) {
if (!iBehavior.getStatelessHint(component)) {
msg += "\n\t" + "The component has stateful behaviour: " + iBehavior.getClass().getName();
}
}
LOG.error(msg);
}
checkedPages.add(pageClassName); …Run Code Online (Sandbox Code Playgroud) 我正在开发一个没有注释的Spring 2.0项目.我们使用具有不同前缀和后缀的几个PropertyPlaceholderConfigurer bean来加载来自不同属性文件的属性.这很好用.
由于存在大量属性文件和属性,我希望应用程序列出未使用的属性.这意味着,在属性文件中配置但从未在Spring应用程序上下文中引用的属性.
我编写了一个实现BeanFactoryPostProcessor的bean,并且在应用程序上下文中找到了不同PropertyPlaceHolderConfigurers的引用.这给了我一个使用的属性列表.
但是,我无法访问由PlaceHolderConfigurers加载的属性.因此,我无法显示未使用的属性.
有没有(简单)方法来获取PropertyPlaceholderConfigurer的属性?关于如何解决这个问题的任何其他建议?
编辑:解决方案是访问mergeProperties metod,如下所示:
PropertyPlaceholderConfigurer ppc =
(PropertyPlaceholderConfigurer) applicationContext.getBean("yourBeanId");
Method m = PropertiesLoaderSupport.class.getDeclaredMethod("mergeProperties",
new Class[] {});
m.setAccessible(true);
Properties loadedProperties = (Properties) m.invoke(propertyPlaceHolder, null);
Run Code Online (Sandbox Code Playgroud)
在获取最初加载的属性并在BeanFactoryPostProcessing期间获取beandefinitions之后,其余的很简单.减去两个集合,瞧:我们现在可以列出未使用的属性.
我正在构建的Java应用程序的任务之一是连接到远程SFTP服务器.为了做到这一点我有一个远程计算机的证书和本地身份(id_rsa并且id_rsa.pub将在.ssh文件夹中).这工作正常.
我想将证书和身份放在受密码保护的java密钥库中,以便更容易和更安全地配置.我有这个工作的证书,但我有问题在JKS或PKCS12密钥库中存储SSH身份(任何一个都可以工作).
为了隔离问题,我尝试了以下步骤:
我ssh-keygen -b 2048用来创建两个身份文件id_rsa_demo和id_rsa_demo.pubte本地目录.据我所知,这些是身份的私钥和公钥,所以我尝试将它们组合成一个identity.p12文件:
openssl pkcs12 -export \
-inkey "id_rsa_demo" \
-in "id_rsa_demo.pub" \
-out "identity.p12" \
-password "pass:topsecret" \
-name "demoalias"
Run Code Online (Sandbox Code Playgroud)
这给了我错误unable to load certificates.我四处搜索,似乎openssl需要一个带有-in参数完整链的证书.由于我生成的身份没有,我尝试了-nocerts选项,如下所示:
openssl pkcs12 -export \
-inkey "id_rsa_demo" \
-in "id_rsa_demo.pub" \
-out "identity.p12" \
-password "pass:topsecret" \
-name "demoalias" \
-nocerts
Run Code Online (Sandbox Code Playgroud)
我没有得到任何错误,但该-nocerts选项符合其承诺,并且不会将我的公钥添加到pkcs12文件中:
openssl pkcs12 -info -in identity.p12
Enter Import Password:
MAC …Run Code Online (Sandbox Code Playgroud) 我正在一个项目中,该项目将Raspberry Pi 3计算模块集成到硬件设计中,在PCB上PCB可以访问计算模块上的两个串行端口:
据我了解,BCM2835中有一个完整的16650兼容UART,称为“ PL011”,还有一个微型UART,通常用于与内部蓝牙芯片进行通信。
引导Raspbian Jesse时,我看到该/dev/ttyAMA0设备似乎在GPIO引脚14/15上进行通信,并且根据我的阅读,该通信通过PL011全UART芯片进行。我试图创建一个/boot/config.txt具有以下设备树覆盖的文件:
dtoverlay=uart1,txd1_pin=32,rxd1_pin=33
enable_uart=1
Run Code Online (Sandbox Code Playgroud)
这似乎无法为我提供/dev/ttyAMA1设备。这似乎与/boot/overlays/README文件中的说明一致,该说明指出:
Name: Uart1
Info: Enable uart1 in place of uart0
Run Code Online (Sandbox Code Playgroud)
我确实找到了微型UART的有限驱动程序,该驱动程序固定为115200波特,这似乎是使用微型UART而不是完整UART的驱动程序。
我想要做的是:无需重新设计硬件,配置“PL011”全UART使用CTS / RTS / TX / RX端口,和迷你UART使用TX / RX端口,让我可以在我的应用程序中使用两个串行端口。