Calculate Query Cost for All Users by Repository

Search across multiple repositories to calculate query costs for all users by repository using sort() and groupBy() functions

Query

logscale
#type=humio #kind=logs class=c.h.j.RunningQueriesLoggerJob message="Highest Cost query"
 | groupBy(repo, initiatingUser, totalLiveCost, totalStaticCost)
 | sort([totalLiveCost, totalStaticCost])

Introduction

In this example, the query uses sort() and groupBy() functions to find query costs. The query filters logs in humio repository that are tagged with kind equal to logs and then returns the events where the class field has values containing c.h.j.RunningQueriesLoggerJob, searching for the specific value Highest Cost query.

Example incoming data might look like this:

#type#kindclassmessagetimestampdataspaceinitiatingUsertotalLiveCosttotalStaticCostdeltaTotalCostrepo
humiologsc.h.j.RunningQueriesLoggerJobHighest Cost query2025-03-26T09:30:00Zproductionjohn.doe15008002300security-logs
humiologsc.h.j.RunningQueriesLoggerJobHighest Cost query2025-03-26T09:31:00Zdevelopmentjane.smith200012003200app-logs
humiologsc.h.j.RunningQueriesLoggerJobHighest Cost query2025-03-26T09:32:00Zstagingbob.wilson10005001500infra-logs
humiologsc.h.j.RunningQueriesLoggerJobHighest Cost query2025-03-26T09:33:00Zproductionjohn.doe18009002700security-logs
humiologsc.h.j.RunningQueriesLoggerJobHighest Cost query2025-03-26T09:34:00Zdevelopmentjane.smith250013003800app-logs
humiologsc.h.j.RunningQueriesLoggerJobHighest Cost query2025-03-26T09:35:00Zstagingalice.cooper12006001800infra-logs

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[/Filter/] 1{{Aggregate}} 2{{Aggregate}} result{{Result Set}} repo --> 0 0 --> 1 1 --> 2 2 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    #type=humio #kind=logs class=c.h.j.RunningQueriesLoggerJob message="Highest Cost query"

    Filters for Humio internal logs containing c.h.j. RunningQueriesLoggerJob in the class field and where the value in the message field is equal to Highest Cost query.

  3. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[/Filter/] 1{{Aggregate}} 2{{Aggregate}} result{{Result Set}} repo --> 0 0 --> 1 1 --> 2 2 --> result style 1 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    | groupBy(repo, initiatingUser, totalLiveCost, totalStaticCost)

    Groups the results by the repo field, the initiatingUser field, and by both cost types (the fields totalLiveCost, totalStaticCost), and returns a count in a field named _count.

  4. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[/Filter/] 1{{Aggregate}} 2{{Aggregate}} result{{Result Set}} repo --> 0 0 --> 1 1 --> 2 2 --> result style 2 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    | sort([totalLiveCost, totalStaticCost])

    Sorts the results by both the totalLiveCost field and the totalStaticCost field, in descending order by default.

  5. Event Result set.

Summary and Results

The query is used to search across multiple repositories and output query costs for all users by repository. The query returns the count in a field named _count. Use this query to focus on live and static costs separately.

Sample output from the incoming example data:

repoinitiatingUsertotalLiveCosttotalStaticCost_count
app-logsjane.smith200012001
security-logsjohn.doe15008001
infra-logsbob.wilson10005001