Skip to content
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

Compute cpu instantaneous usage in the core #1081

Open
vishh opened this issue Jan 27, 2016 · 1 comment
Open

Compute cpu instantaneous usage in the core #1081

vishh opened this issue Jan 27, 2016 · 1 comment

Comments

@vishh
Copy link
Contributor

vishh commented Jan 27, 2016

As of now cpu instantaneous usage metrics are computed on the fly, in the REST handler. Instead they should be computed in the core.

cc @timstclair @pwittrock

@mboussaa
Copy link

mboussaa commented Mar 3, 2016

the only way I found to get the cpu usage per container is doing like following in Java:

 public static double getInstantPercentCPUUsage(JSONObject obj0) throws ParseException {

        JSONObject obj = obj0.getJSONObject(obj0.keys().next()) ;
        JSONObject firstValue = obj.getJSONArray("stats").getJSONObject(obj.getJSONArray("stats").length()-1);
        JSONObject secondValue = obj.getJSONArray("stats").getJSONObject(obj.getJSONArray("stats").length()-2);
        String ts1 = firstValue.getString("timestamp");
        String ts2 = secondValue.getString("timestamp");

        int cpuUsage1 = firstValue.getJSONObject("cpu").getJSONObject("usage").getInt("total");
        int cpuUsage2 = secondValue.getJSONObject("cpu").getJSONObject("usage").getInt("total");

        DateTimeFormatter parser = ISODateTimeFormat.dateTime();
        DateTime dt1 = parser.parseDateTime(ts1);
        DateTime dt2 = parser.parseDateTime(ts2);

        DateTimeFormatter formatter = DateTimeFormat.mediumDateTime();
        return (cpuUsage1-cpuUsage2)/((dt1.getSecondOfDay()-dt2.getSecondOfDay())*10000000) ;
    }

It is the derivative cpu usage over time. I don't know if that right !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants