-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support on jmx attributes of type java.util.Date #449
Conversation
@@ -190,7 +190,12 @@ private void processBeanValue( | |||
Object value) { | |||
if (value == null) { | |||
logScrape(domain + beanProperties + attrName, "null"); | |||
} else if (value instanceof Number || value instanceof String || value instanceof Boolean) { | |||
} else if (value instanceof Number || value instanceof String || value instanceof Boolean || value instanceof java.util.Date) { | |||
//output Date as Long (the number of milliseconds since January 1, 1970, 00:00:00 GMT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconds are usual for Prometheus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to output the number of seconds instead of milliseconds.
} else if (value instanceof Number || value instanceof String || value instanceof Boolean) { | ||
} else if (value instanceof Number || value instanceof String || value instanceof Boolean || value instanceof java.util.Date) { | ||
//output Date as Long (the number of milliseconds since January 1, 1970, 00:00:00 GMT) | ||
if( value instanceof java.util.Date){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watch your spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the unintended spaces.
} | ||
|
||
@Override | ||
public long getLastExchangeFailureTimestamp() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a Date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed the test :)
thank you very much for the feedbacks and could you review the latest commit please, thank you!
} else if (value instanceof Number || value instanceof String || value instanceof Boolean) { | ||
} else if (value instanceof Number || value instanceof String || value instanceof Boolean || value instanceof java.util.Date) { | ||
//output Date as Long (the number of seconds since January 1, 1970, 00:00:00 GMT) | ||
if(value instanceof java.util.Date){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting is still off here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a space after the if and before the {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to desired style
|
||
@Override | ||
public Date getLastExchangeFailureTimestamp() { | ||
int theMillisecondAtTheMoment = Calendar.getInstance().get(Calendar.MILLISECOND); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should preserve milliseconds if we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed data type from long to double to preserve milliseconds in decimal places, thank you.
Signed-off-by: jacky <jacky.chen@nzqa.govt.nz> Signed-off-by: jacky <jac.chen@gmail.com>
…heus conventions Signed-off-by: jacky <jac.chen@gmail.com>
…ents milliseconds Signed-off-by: jacky <jac.chen@gmail.com>
Signed-off-by: jacky <jac.chen@gmail.com>
Signed-off-by: jacky <jac.chen@gmail.com>
} else if (value instanceof Number || value instanceof String || value instanceof Boolean) { | ||
} else if (value instanceof Number || value instanceof String || value instanceof Boolean || value instanceof java.util.Date) { | ||
//output Date as Long (the number of seconds since January 1, 1970, 00:00:00 GMT) | ||
if(value instanceof java.util.Date){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a space after the if and before the {
} else if (value instanceof Number || value instanceof String || value instanceof Boolean || value instanceof java.util.Date) { | ||
if(value instanceof java.util.Date){ | ||
attrType = "java.lang.Double"; | ||
value = (double) ((java.util.Date) value).getTime() / 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually I do this as value / 1000.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to desired style
" route: \"$2\"\n" + | ||
" type: routes"; | ||
JmxCollector jc = new JmxCollector(rulePattern).register(registry); | ||
assertEquals(Double.valueOf((double)Camel.EXPECTED_DATE_IN_MILLISECONDS / 1000), registry.getSampleValue("org_apache_camel_LastExchangeFailureTimestamp", new String[]{"context", "route", "type"}, new String[]{"my-camel-context", "my-route-name", "routes"})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for the actual literal float value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated test to do that, cheers
Signed-off-by: jacky <jac.chen@gmail.com>
Thanks! |
* added support on jmx attributes of type java.util.Date Signed-off-by: jacky <jacky.chen@nzqa.govt.nz> Signed-off-by: jacky <jac.chen@gmail.com>
Dear maintainers,
We recently had an requirement to expose certain JMX attributes of java Date type to prometheus, specifically, a number of timestamps in the built-in JMX of Apache Camel library.
We thought that it might be useful for other users of the exporter, would you review our changes and let us know any feedbacks and critics please?
Thank you
Jacky