Home > jDeskMetrics

jDeskMetrics

JDeskMetrics is a project mainly written in Java, it's free.

DeskMetrics Analytics component for Java

jDeskMetrics - Java component for DeskMetrics

jDeskMetrics is a Java integration component for DeskMetrics analytics platform. It implement the most basic DeskMetrics features and have no external dependency.

The basics

This is an example application:

package myapp;

import com.DeskMetrics.DeskMetrics;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static void main(String[] args) throws Exception
    {
        DeskMetrics deskmetrics = DeskMetrics.getInstance();
        String appID = "your_app_id";

        deskmetrics.start(appID, "0.5");
        System.out.println("Application started");
        deskmetrics.trackEvent("jDeskMetrics", "Sample event");
        System.out.println("Added some events");

        deskmetrics.trackCustomData("CustomJavaData", "CustomDataValue");
        deskmetrics.trackCustomDataR("CustomJavaDataR", "CustomDataValueR");

        deskmetrics.trackEventTimed("jDeskMetrics", "jTimed", 30, true);
        deskmetrics.trackEventTimed("jDeskMetrics", "jTimed", 20, false);
        deskmetrics.trackLog("jDeskMetrics send a log ;)");
        deskmetrics.trackException(new Exception("Oops, got an error in jDeskMetrics"));

        deskmetrics.stop();
        System.out.println("Application finished");
    }
}

You should run the "start" method before all and execute "stop" method when your application finishes. These steps are important because the data generated by DeskMetrics' Java component will be only sent when "stop" method is invoked, except on trackCustomDataR method.

Methods documentation

DeskMetrics.start(String app_id, String app_version)

This method must be called before all others. You can get the app_id value at DeskMetrics's dashboard

DeskMetrics.trackEvent(String category, String name)

Simple event tracking

DeskMetrics.trackEventValue(String category, String name, String value)

Simple event tracking with an extra ("value") option enabled.

DeskMetrics.trackCustomData(String name, String value)

Tracks an customized data (useful for emails, telephone, extra system configuration, etc)

DeskMetrics.trackCustomDataR(String name, String value)

Does exactly the same thing as trackCustomData, but does it in real time (e.g. without stop the application need).

DeskMetrics.trackLog(String message)

Autoexplicative :-)

DeskMetrics.trackEventTimed(String category, String name, int time, boolean finished)

Tracks events related to time and intervals. It is useful for long-time operations (like disk defrag, big file download, and so on). Time must be specified in seconds.

DeskMetrics.trackException(Exception e)

Tracks an exception and its details, like stack trace and message.

DeskMetrics.stop()

Method called at the end of application. All component data will be sent to DeskMetrics server at the end of this method.

Previous:Enjoy-Reading