Get multiple group wise data query from InfluxDB in Grafana

I want to get stage name per build and parent folder wise in influxdb and show on grafana dashboard.

I’m using InfluxDB to collect other jenkins build metrics but stage name is not built-in supported hence I’ve created customData for stage name, hence through whichever stage build will parse, it collects the stage name and send to influxdb and I get data as below.

    time                 build_number build_time project_name      project_name_1    project_path                project_path_1              stage1                  stage2                       stage3                       stage4                     stage5                     stage6 stage7              stage8
----                 ------------ ---------- ------------      --------------    ------------                --------------              ------                  ------                       ------                       ------                     ------                     ------ ------              ------
1588084985624000000  3            19824      TestPetclinic     TestPetclinic     TestFolder/TestPetclinic    TestFolder/TestPetclinic    Checkout SCM                                                                                                                                   Publish to InfluxDB petclinic
1588085162281000000  4            38600      testPipeline      testPipeline      petclinic/testPipeline      petclinic/testPipeline                              Get application version      Send Parameters To Spinnaker Build                                                        Publish to InfluxDB petclinic
1588085231934000000  4            38785      TestPetclinic     TestPetclinic     TestFolder/TestPetclinic    TestFolder/TestPetclinic                            Get application version      Send Parameters To Spinnaker Build                                                        Publish to InfluxDB petclinic
1588085356705000000  5            3616       TestPetclinic     TestPetclinic     TestFolder/TestPetclinic    TestFolder/TestPetclinic    Checkout SCM                                                                                                                                   Publish to InfluxDB petclinic
1588085797787000000  7            41916      TestPetclinic     TestPetclinic     TestFolder/TestPetclinic    TestFolder/TestPetclinic    Checkout SCM            Get application version                                                                                                Publish to InfluxDB petclinic
1588086095058000000  10           81730      TestPetclinic     TestPetclinic     TestFolder/TestPetclinic    TestFolder/TestPetclinic    Checkout SCM            Get application version                                                                                                Publish to InfluxDB TestFolder
1588087475800000000  11           43199      TestPetclinic     TestPetclinic     TestFolder/TestPetclinic    TestFolder/TestPetclinic    Checkout SCM            Get application version                                                                                                Publish to InfluxDB TestFolder
1588087564498000000  12           18748      TestPetclinic     TestPetclinic     TestFolder/TestPetclinic    TestFolder/TestPetclinic    Checkout SCM            Get application version                                                                                                Publish to InfluxDB TestFolder

From this I can easily get data per build wise(job wise) but struggling with getting data folder wise.

Hence I’m also parsing hard-coded value in each job inside folder, last column in above table data ex.

Folder Name: abc > Job 1 contains custom data field key: stage8 value: "abc"
Folder Name: abc > Job 2 contains custom data field key: stage8 value: "abc"

Folder Name: xyz > Job 1 contains custom data field key: stage8 value: "xyz"
Folder Name: xyz > Job 2 contains custom data field key: stage8 value: "xyz"

Through which I get extra stage8 with 2 different values as per folder name.

Next in grafana, I’m trying to create the query, to get expected data like

stage8      Checkout SCM    Get application version     Send Parameters To Spinnaker        Build   Unit Test & Publish Report      Jacoco
petclinic        14              15                          8                               7       4                               3
TestFolder       11              12                          9                               8       8                               8

But with this query

SELECT count("stage1") as "Checkout SCM", count("stage2") as "Get application version" , count("stage3") as "Send Parameters To Spinnaker", count("stage4") as "Build", count("stage5") as "Unit Test & Publish Report", count("stage6") as "Jacoco" FROM "jenkins_custom_data" GROUP BY "stage8" 


stage8      Checkout SCM    Get application version     Send Parameters To Spinnaker        Build   Unit Test & Publish Report      Jacoco
           23              27                          17                               15       12                               11

And when I run group by query for stage8

SELECT count("stage1") as "Checkout SCM", count("stage2") as "Get application version" , count("stage3") as "Send Parameters To Spinnaker", count("stage4") as "Build", count("stage5") as "Unit Test & Publish Report", count("stage6") as "Jacoco", stage8 FROM "jenkins_custom_data" group by stage8

Then I get this error

ERR: mixing aggregate and non-aggregate queries is not supported

Now, I’ve got this query individually

select count("stage1") as "Checkout SCM", count("stage2") as "Get application version" , count("stage3") as "Send Parameters To Spinnaker", count("stage4") as "Build", count("stage5") as "Unit Test & Publish Report", count("stage6") as "Jacoco" from jenkins_custom_data where stage8 = 'petclinic'

select count("stage1") as "Checkout SCM", count("stage2") as "Get application version" , count("stage3") as "Send Parameters To Spinnaker", count("stage4") as "Build", count("stage5") as "Unit Test & Publish Report", count("stage6") as "Jacoco" from jenkins_custom_data where stage8 = 'TestFolder'

And able to get data but when join these 2 query in table then cannot say that which result is from which query because again raw name cannot display because of mix aggregation query.

Please advise to resolve this.

Thanks

Hello @JaydeepUniverse,
Welcome! If you’re using v1.7+, I highly recommend taking advantage of flux and joins() to perform math across measurements.