问题描述
考虑一个java代码:
Consider a java code:
String host = "zabbixHost";
int port = 10051;
ZabbixSender zabbixSender = new ZabbixSender(host, port);
DataObject dataObject = new DataObject();
dataObject.setHost("testHost");
dataObject.setKey("test.ping.count");
dataObject.setValue("10");
// TimeUnit is SECONDS.
dataObject.setClock(System.currentTimeMillis()/1000);
SenderResult result = zabbixSender.send(dataObject);
System.out.println("result:" + result);
if (result.success()) {
System.out.println("send success.");
} else {
System.err.println("sned fail!");
}
结果是{"failed":0,"processed":1,"spentSeconds":0.001715,"total":1}
然后我从命令行通过 zabbix_sender
工具发送一个请求:
Then I send a request by zabbix_sender
tool from command line:
zabbix_sender -z zabbixHost -p 10051 -s testHost -k test.ping.count -o 8 -v
输出为:
info from server: "processed: 1; failed: 0; total: 1; seconds spent: 0.002052"
sent: 1; skipped: 0; total: 1
目前有 2 个值被发送到 Zabbix.但是当我看到 test.ping.count
的监控图形时,只显示了 8
值.例如.即使响应成功,也未收到来自 java 代码的值.
For now 2 values were sent into Zabbix. But when I got to the monitoring graphic for test.ping.count
and only 8
value is shown. E.g. value from java code was not received even when response was successful.
这是怎么回事?如何解决这种情况?
What is going on? How to fix such situation?
注意
库是 - io.github.hengyunabc:zabbix-sender:0.0.3
Zabbix 版本为 3.0
The library is - io.github.hengyunabc:zabbix-sender:0.0.3
Zabbix version is 3.0
推荐答案
问题出在时间戳上,zabbix-sender with version 0.0.1
set request (not dataobject) 以毫秒为单位的时钟,而版本 0.0.3
以秒为单位.所以使用正确的版本修复问题.
The problem was with timestamps, zabbix-sender with version 0.0.1
set request (not dataobject) clock in milliseconds while version 0.0.3
in seconds. So using right version fix issues.
maven 示例(来源):
maven sample (source):
<dependency>
<groupId>io.github.hengyunabc</groupId>
<artifactId>zabbix-sender</artifactId>
<version>0.0.3</version>
</dependency>
这篇关于为什么zabbix不显示从java代码接收到的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!