stagemonitor / stagemonitor-mailinglist

GitHub issues abused as a mailing list
3 stars 0 forks source link

Custom stats using stagemonitor #42

Open ratheesh001 opened 7 years ago

ratheesh001 commented 7 years ago

In my tomcat application, I have few params like db connections( used/free), and some other custom stats that is being logged into log files. What is the best way to get these stats into elastic search and view in kibana dashborad using stage monitor. By adding the configuration stagemonitor.reporting.elasticsearch.onlyLogElasticsearchMetricReports=true, will I be able to see the data that is periodically send to elastic in the log files.

felixbarny commented 7 years ago

The best way would be to programmatically track the metrics in stagemonitor's metric registry: https://github.com/stagemonitor/stagemonitor/wiki/Track-your-own-metrics#programmatic

Then you can create a custom kibana dashboard for your metrics.

ratheesh001 commented 7 years ago

Thanks felix for quick response. I am already having few params that is exposed over JMX. Can this data be periodically send to elastic?

felixbarny commented 7 years ago

You can use this code to register a gauge to the metric registry which pulls metrics from jmx:

public class MBeanGauge<T> implements Gauge<T> {
    private final ObjectInstance objectInstance;

    private MBeanGauge(String objectName) {
        this.objectInstance = MBeanUtils.queryMBeans(objectName).iterator().next();
    }

    @Override
    public T getValue() {
        return (T) MBeanUtils.getValueFromMBean(objectInstance, "Count");
    }
}