Painless to convert Kbps to Mbps

In kibana i have field in kilobit/second format, But to calculate the average and to visualize i would need to convert data into megabit/second .

k18mK

String speed = doc['speed_download.keyword'].value;
long size = Long.parseLong(speed);
long k = (size/256.0);
long m = (size/1024.0);
long g = (size/1048576.0);
long t = (size/1073741824.0);

return size;

Tried with above configuration and code, but it is not working. I am new to ELK, So can someone help to achieve this using painless(scripted filed) in kibana? it would be great helpful.

The code will give class_cast_exception. please check that.

Currently i have doc['speed_download'].value / 1024 and preview result of this code shows below.

[
 {
  "_id": "3929212e-4aea-4100-acc1-95388f801452\n",
  "speed_download": 276.81662055567693,
  "new_speed_download": [
   0.27032873034477234
  ]
 },
 {
  "_id": "ace7c3c3-4473-42e9-bbb5-5a144811d357\n",
  "speed_download": 529.0886454264323,
  "new_speed_download": [
   0.5166881084442139
  ]
 },

Discover result for the scripted field shown as below.

0.7B
0B
0B
0.1B
1.2B

But i need to display in KB & MB instead of B

Any help would be highly appreciated.

The below seems to work for me. My data set doesn't have a number big enough for MB but I don't see why this wouldn't work.

Scripted Field

Results

@aaron-nimocks. I am trying to visualize the average speed in [Day/Weekly/Monthly] basics using Line chart in that case it doesn't show the data in MB. it shows only in KBs. Ideally for the [Day/Weekly/Monthly] it need to show MBs.

My Line Chart visualization settings as follows.

Metrics
Y-Axis
Aggregation - Average
Field - New-Bytes

Buckets
X-Axis
Aggregation - Date Histogram
Field - Start_time
Minimum interval - Week

@aaron-nimocks, Thanks a lot for your support. with this i can able to view the speed in Bytes/KBs/MBs.

return doc['speed_download'].value*1024;

1 Like