# Average calculation problem (round-off 0) on CPULoad via JMX

**URL:** <https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689>\
**Category:** Kibana\
**Created:** [October 20, 2017, 11:17am UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689 "2017-10-20T11:17:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChuckNoxis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chucknoxis/32/23352_2.png) [@ChuckNoxis](https://discuss.elastic.co/u/ChuckNoxis)\
**Post date:** [October 20, 2017, 11:17am UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/1 "2017-10-20T11:17:34Z")

</div>

Hi,

I've installed an ELK on Ubuntu, i'm trying to monitor some data from a Java app with JMX (I followed [this tutorial](https://deors.wordpress.com/2017/02/21/build-your-own-application-performance-monitoring-apm-solution-with-elk-and-jmx-part-1/)).

When I want to create a visualization for my CPU Load, the result of the average equals 0.

 ![Sélection_016](https://us1.discourse-cdn.com/elastic/original/3X/9/b/9b1e541f9fa084e5bc0c1bcc572e87cb3025b9d2.png)

However, Kibana seems to receive the good values.

 ![Sélection_015](https://us1.discourse-cdn.com/elastic/original/3X/7/8/780e4f3f58551cf70880709b980ba0e64f948682.png)

I think it's maybe due to the type of data which seems not to be float but I don't know how to change it and where.  
Is it a Kibana or Elasticsearch misconfiguration ?

Thanks

---

<div class="post-metadata">

**Author:** ![ChuckNoxis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chucknoxis/32/23352_2.png) [@ChuckNoxis](https://discuss.elastic.co/u/ChuckNoxis)\
**Post date:** [October 23, 2017, 12:05pm UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/2 "2017-10-23T12:05:28Z")

</div>

Hi, little up here.

I still need some help on this, I've worked on all others data but I've only a problem on this one and I've no idea where is the problem. Maybe Kibana tries to round off the metric\_value\_number but I don't know how/where.  
I'm still discovering ELK.

Edit :  
When I was trying some different Time Range, it's display something for the CPU\_Load, but I'm able to see a value only when I select Last 7 days on Time Range. Weird.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/1/2124b9f783f33d0b210b847f9932cbf36f28a05a.png)

(I changed the Visualization to Gauge but there is no effect.)

It seems worked once but I've no idea why. I still have datas.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/1/610e70baeaa88df02dcc295da6abf8b1cb3a4821.png)  
 ![Sélection_031](https://us1.discourse-cdn.com/elastic/original/3X/a/5/a5bf45b299f41d9d6973b28494a5cc3cfa49bc44.png)

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 23, 2017, 2:51pm UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/3 "2017-10-23T14:51:09Z")

</div>

Hi Chuck,

that really sounds like a strange one. Could you maybe copy the "Request" and "Response" from the debug panel, at the visualization?

And could you maybe switch the metric aggregation to "unique count" on the "metric\_value\_number" field to check how many different values are there actually?

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![ChuckNoxis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chucknoxis/32/23352_2.png) [@ChuckNoxis](https://discuss.elastic.co/u/ChuckNoxis)\
**Post date:** [October 23, 2017, 3:08pm UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/4 "2017-10-23T15:08:09Z")

</div>

_Request_

```
{
  "size": 0,
  "aggs": {
    "2": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "1h",
        "time_zone": "Europe/Berlin",
        "min_doc_count": 1
      },
      "aggs": {
        "1": {
          "avg": {
            "field": "metric_value_number"
          }
        }
      }
    }
  },
  "version": true,
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "type:jmx AND metric_path:jvm.OperatingSystem.SystemCpuLoad",
            "analyze_wildcard": true
          }
        },
        {
          "range": {
            "@timestamp": {
              "gte": 1508166185803,
              "lte": 1508770985803,
              "format": "epoch_millis"
            }
          }
        }
      ],
      "must_not": []
    }
  },
  "_source": {
    "excludes": []
  },
  "highlight": {
    "pre_tags": [
      "@kibana-highlighted-field@"
    ],
    "post_tags": [
      "@/kibana-highlighted-field@"
    ],
    "fields": {
      "*": {
        "highlight_query": {
          "bool": {
            "must": [
              {
                "query_string": {
                  "query": "type:jmx AND metric_path:jvm.OperatingSystem.SystemCpuLoad",
                  "analyze_wildcard": true,
                  "all_fields": true
                }
              },
              {
                "range": {
                  "@timestamp": {
                    "gte": 1508166185803,
                    "lte": 1508770985803,
                    "format": "epoch_millis"
                  }
                }
              }
            ],
            "must_not": []
          }
        }
      }
    },
    "fragment_size": 2147483647
  }
}

```

_Response_

```
{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 15,
    "successful": 15,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 5266,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "2": {
      "buckets": [
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-19T17:00:00.000+02:00",
          "key": 1508425200000,
          "doc_count": 15
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-20T09:00:00.000+02:00",
          "key": 1508482800000,
          "doc_count": 10
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-20T10:00:00.000+02:00",
          "key": 1508486400000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-20T11:00:00.000+02:00",
          "key": 1508490000000,
          "doc_count": 359
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-20T12:00:00.000+02:00",
          "key": 1508493600000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-20T13:00:00.000+02:00",
          "key": 1508497200000,
          "doc_count": 356
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-20T14:00:00.000+02:00",
          "key": 1508500800000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-20T15:00:00.000+02:00",
          "key": 1508504400000,
          "doc_count": 359
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-20T16:00:00.000+02:00",
          "key": 1508508000000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0.00967741935483871
          },
          "key_as_string": "2017-10-20T17:00:00.000+02:00",
          "key": 1508511600000,
          "doc_count": 310
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T09:00:00.000+02:00",
          "key": 1508742000000,
          "doc_count": 31
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T10:00:00.000+02:00",
          "key": 1508745600000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T11:00:00.000+02:00",
          "key": 1508749200000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T12:00:00.000+02:00",
          "key": 1508752800000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T13:00:00.000+02:00",
          "key": 1508756400000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T14:00:00.000+02:00",
          "key": 1508760000000,
          "doc_count": 284
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T15:00:00.000+02:00",
          "key": 1508763600000,
          "doc_count": 284
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T16:00:00.000+02:00",
          "key": 1508767200000,
          "doc_count": 360
        },
        {
          "1": {
            "value": 0
          },
          "key_as_string": "2017-10-23T17:00:00.000+02:00",
          "key": 1508770800000,
          "doc_count": 18
        }
      ]
    }
  },
  "status": 200
}

```

_For the count_ (Seem's normal)

 ![Sélection_032](https://us1.discourse-cdn.com/elastic/original/3X/a/1/a1ea595554c179d005c97d8409016490a8421f0e.png)

Thanks for your help ! 😉

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 23, 2017, 3:09pm UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/5 "2017-10-23T15:09:53Z")

</div>

Could you add one other screenshot, with adding a sub-bucket aggregation type "split series", terms aggregation on the `metric_value_number` field (and set the size to 10 or 20 or so, please)?

---

<div class="post-metadata">

**Author:** ![ChuckNoxis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chucknoxis/32/23352_2.png) [@ChuckNoxis](https://discuss.elastic.co/u/ChuckNoxis)\
**Post date:** [October 23, 2017, 3:18pm UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/6 "2017-10-23T15:18:03Z")

</div>

Like this ?

 ![Sélection_033](https://us1.discourse-cdn.com/elastic/original/3X/f/c/fcd0cc59bad4c8d5027d704d0f358b3340b3a085.png)

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 23, 2017, 3:19pm UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/7 "2017-10-23T15:19:23Z")

</div>

Ah sorry missed half of the information ☹

On the y-axis you should just draw the count (and it looks like you selected a pretty small time range now with last 15 minutes?)

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![ChuckNoxis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chucknoxis/32/23352_2.png) [@ChuckNoxis](https://discuss.elastic.co/u/ChuckNoxis)\
**Post date:** [October 23, 2017, 3:25pm UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/8 "2017-10-23T15:25:44Z")

</div>

My bad, end of the day ahah.

 ![Sélection_034](https://us1.discourse-cdn.com/elastic/original/3X/6/c/6cc8fc6199a81bba7d809b89658ac32e5111528e.png)

Small time range shouldn't change something because the java app is on so I should receive the data but I put it back on 7 days.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 23, 2017, 3:46pm UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/9 "2017-10-23T15:46:02Z")

</div>

Okay that is actually a very weird behavior, since also the bucket aggregation says, that there are mostly documents with value `0` and just a very few with `1`, which could still average at a specific precision to `0`.

I think I need to dig a bit into that issue, so you might not get a response from me today anymore, but I will respond in the next days.

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 24, 2017, 8:10am UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/10 "2017-10-24T08:10:54Z")

</div>

I guess what could cause that issue, is that you have the `metric_value_number` field indexed as an `integer` instead of `float`. That way the `_source` of the documents, that is shown in discover will still have the original value, but whenever you search or aggregate on that field it behaves like an integer field.

Could you please check your mappings (e.g. in the Dev Tools Console via `GET /your_index_name/_mappings` and check what `type` the `metric_value_number` field have?

---

<div class="post-metadata">

**Author:** ![ChuckNoxis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chucknoxis/32/23352_2.png) [@ChuckNoxis](https://discuss.elastic.co/u/ChuckNoxis)\
**Post date:** [October 24, 2017, 8:42am UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/11 "2017-10-24T08:42:37Z")

</div>

It's that (hehe like my guess in the first post ^^), metric\_value\_number is a long.

 ![Sélection_035](https://us1.discourse-cdn.com/elastic/original/3X/b/6/b6519a83b2cbdc856f49f2240e438524322317dc.png)

How can i change it to double or float ?

And for my knowledge, how should I do to get this result in the console ? when I tried the GET method, I got an error ^^

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/7/a72ad9d821daf7e03644487a45a19e330d0111c8.png)

Thanks a lot for your help ! 🙂☀

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 24, 2017, 8:59am UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/12 "2017-10-24T08:59:05Z")

</div>

Try to remove the `_search` body with the `query` of the request.

To update the mapping you will basically need to write the mapping to a new index (see the [mapping documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)) and after that reindex your data into the new index (see e.g. [this reindex blog post](https://www.elastic.co/blog/reindex-is-coming)). After that you should be able to achieve what you want.

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![ChuckNoxis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chucknoxis/32/23352_2.png) [@ChuckNoxis](https://discuss.elastic.co/u/ChuckNoxis)\
**Post date:** [October 24, 2017, 10:15am UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/13 "2017-10-24T10:15:05Z")

</div>

Perfect

Once again, thanks for your help 🙂

I found [this](https://stackoverflow.com/questions/42074221/change-type-and-reindex-in-elasticsearch) on StackOverflow if someone have the same problem and want to change type / reindex step by step 😉

---

<div class="post-metadata">

**Author:** ![ChuckNoxis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chucknoxis/32/23352_2.png) [@ChuckNoxis](https://discuss.elastic.co/u/ChuckNoxis)\
**Post date:** [October 26, 2017, 9:31am UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/14 "2017-10-26T09:31:32Z")

</div>

Hi,

I'm back for a little question. How to change the type permanently ?

I saw this in the logs

 ![Sélection_047](https://us1.discourse-cdn.com/elastic/original/3X/2/d/2d39e564461dd091432dc197dba7be3e15e8e872.png)

And each day, because the index change with the date, it's reseting the field from double to long.

 ![Sélection_048](https://us1.discourse-cdn.com/elastic/original/3X/1/7/17812df4fc19abf6d77c96d98be56998ff011db2.png)

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 23, 2017, 9:31am UTC](https://discuss.elastic.co/t/average-calculation-problem-round-off-0-on-cpuload-via-jmx/104689/15 "2017-11-23T09:31:44Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
