我想在influxdb中获取每个构建的阶段名称和父文件夹,并在grafana仪表板上显示。
我正在使用InfluxDB收集其他jenkins构建指标,但不支持阶段名称,因此我为阶段名称创建了customData,因此,无论哪个阶段构建都会解析,它都会收集阶段名称并发送到influxdb和我得到的数据如下。
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
由此,我可以轻松地在每个构建明智的位置(作业明智)获取数据,但是在获取数据文件夹的智能方面却很挣扎。
下面的屏幕快照来自grafana,它显示了每个作业的明智数据,该数据统计每个作业通过每个阶段解析的次数
但是就像我提到的那样,不要明智地获取数据文件夹。因此,我还在表中数据的最后一列文件夹内的每个作业中解析硬编码的值。
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"
通过它,我得到了额外的stage8,每个文件夹名称具有2个不同的值。
在grafana中,我正试图创建查询,以获取期望的数据,例如
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
但是使用此查询
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
[当我尝试在InfluxDB中运行此查询时出现错误
ERR: mixing aggregate and non-aggregate queries is not supported
请注意,如何将多个值分组并在表中显示为行
谢谢。
我很惊讶,您根本没有任何结果,mysql工作台根本不喜欢您的查询。
[请咨询When to use single quotes, double quotes, and backticks in MySQL以了解有关单引号和反引号的更多信息
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`