2

I have a value, expressed in bytes, being returned from an Azure Log Analytics query:

enter image description here

I want to convert this to megabytes and make it more human readable. In this case, "4.19 MB".

When I try to convert the byte value into megabyte, I can't seem to get KQL to add the desired precision of 2 places.

Tried: RequestBodySize = strcat(round(RequestBodySize / 1000 / 1000, 2), ' MB') but this results in "4.0 MB".

How do I get this value to correctly reflect a precision of 2?

EDIT 1:

  • format_bytes(RequestBodySize, 2) returns "4 MB". No precision.
  • Same with `format_bytes(RequestBodySize, 2, 'MB')

enter image description here

ericOnline
  • 1,586
  • 1
  • 19
  • 54

4 Answers4

2

I used a simple query to simulate the case and it works as expected for me. In the first example, I added the unit to the field's name to maintain consistent value format that is aligned with the way values are projected in queries:

AzureDiagnostics
| where TimeGenerated > startofday(ago(20d))
| summarize volumeSizeMB = round(sum(_BilledSize)/pow(1024,2),2)

Results:
17.27

And when adding the unit to the value:

AzureDiagnostics
| where TimeGenerated > startofday(ago(20d))
| summarize volumeSize = strcat(round(sum(_BilledSize)/pow(1024,2),2), ' MB')

Results:
17.27 MB

If your issue persists and you don't see the expected precision, I suggest you open support case to have it investigated.

1

Use print format_bytes(12345678) to get 12 MB.

Use print format_bytes(12345678, 2) to get 11.77 MB.

Read the doc for more info.

Slavik N
  • 4,705
  • 17
  • 23
1

Hi The answers above me are great, just wanted to add one small input. the reason you are not getting the fraction after the decimal is because you are dividing two integers. to get a real number you will need to first convert one of the numbers to float or double, by using the todouble() toflout() https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/todoublefunction RequestBodySize = strcat(round(todouble(RequestBodySize) / 1024 / 1024, 2), ' MB') or, as suggested by Yossi, just multiply by 1.0 RequestBodySize = strcat(round(1.0 * RequestBodySize / 1024 / 1024, 2), ' MB')

Shemer
  • 51
  • 4
0

try something like this: | summarize GB = 1.0 * sum(TheThingsYouSub) / 1024 / 1024 / 1024 by SomeFilter