Add new fields for Jenkins Total and Busy executors (#6957)
This commit is contained in:
parent
07a7b70f97
commit
e056097cb4
|
@ -96,6 +96,7 @@ SELECT mean("duration") AS "mean_duration" FROM "jenkins_job" WHERE time > now()
|
||||||
|
|
||||||
```
|
```
|
||||||
$ ./telegraf --config telegraf.conf --input-filter jenkins --test
|
$ ./telegraf --config telegraf.conf --input-filter jenkins --test
|
||||||
|
jenkins,host=myhost,port=80,source=my-jenkins-instance busy_executors=4i,total_executors=8i 1580418261000000000
|
||||||
jenkins_node,arch=Linux\ (amd64),disk_path=/var/jenkins_home,temp_path=/tmp,host=myhost,node_name=master,source=my-jenkins-instance,port=8080 swap_total=4294963200,memory_available=586711040,memory_total=6089498624,status=online,response_time=1000i,disk_available=152392036352,temp_available=152392036352,swap_available=3503263744,num_executors=2i 1516031535000000000
|
jenkins_node,arch=Linux\ (amd64),disk_path=/var/jenkins_home,temp_path=/tmp,host=myhost,node_name=master,source=my-jenkins-instance,port=8080 swap_total=4294963200,memory_available=586711040,memory_total=6089498624,status=online,response_time=1000i,disk_available=152392036352,temp_available=152392036352,swap_available=3503263744,num_executors=2i 1516031535000000000
|
||||||
jenkins_job,host=myhost,name=JOB1,parents=apps/br1,result=SUCCESS,source=my-jenkins-instance,port=8080 duration=2831i,result_code=0i 1516026630000000000
|
jenkins_job,host=myhost,name=JOB1,parents=apps/br1,result=SUCCESS,source=my-jenkins-instance,port=8080 duration=2831i,result_code=0i 1516026630000000000
|
||||||
jenkins_job,host=myhost,name=JOB2,parents=apps/br2,result=SUCCESS,source=my-jenkins-instance,port=8080 duration=2285i,result_code=0i 1516027230000000000
|
jenkins_job,host=myhost,name=JOB2,parents=apps/br2,result=SUCCESS,source=my-jenkins-instance,port=8080 duration=2285i,result_code=0i 1516027230000000000
|
||||||
|
|
|
@ -90,6 +90,7 @@ const sampleConfig = `
|
||||||
|
|
||||||
// measurement
|
// measurement
|
||||||
const (
|
const (
|
||||||
|
measurementJenkins = "jenkins"
|
||||||
measurementNode = "jenkins_node"
|
measurementNode = "jenkins_node"
|
||||||
measurementJob = "jenkins_job"
|
measurementJob = "jenkins_job"
|
||||||
)
|
)
|
||||||
|
@ -244,6 +245,15 @@ func (j *Jenkins) gatherNodesData(acc telegraf.Accumulator) {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get total and busy executors
|
||||||
|
tags := map[string]string{"source": j.Source, "port": j.Port}
|
||||||
|
fields := make(map[string]interface{})
|
||||||
|
fields["busy_executors"] = nodeResp.BusyExecutors
|
||||||
|
fields["total_executors"] = nodeResp.TotalExecutors
|
||||||
|
|
||||||
|
acc.AddFields(measurementJenkins, fields, tags)
|
||||||
|
|
||||||
// get node data
|
// get node data
|
||||||
for _, node := range nodeResp.Computers {
|
for _, node := range nodeResp.Computers {
|
||||||
err = j.gatherNodeData(node, acc)
|
err = j.gatherNodeData(node, acc)
|
||||||
|
@ -354,6 +364,8 @@ func (j *Jenkins) getJobDetail(jr jobRequest, acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
type nodeResponse struct {
|
type nodeResponse struct {
|
||||||
Computers []node `json:"computer"`
|
Computers []node `json:"computer"`
|
||||||
|
BusyExecutors int `json:"busyExecutors"`
|
||||||
|
TotalExecutors int `json:"totalExecutors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type node struct {
|
type node struct {
|
||||||
|
|
|
@ -106,6 +106,19 @@ func TestGatherNodeData(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
|
output: &testutil.Accumulator{
|
||||||
|
Metrics: []*testutil.Metric{
|
||||||
|
{
|
||||||
|
Tags: map[string]string{
|
||||||
|
"source": "127.0.0.1",
|
||||||
|
},
|
||||||
|
Fields: map[string]interface{}{
|
||||||
|
"busy_executors": 0,
|
||||||
|
"total_executors": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty monitor data",
|
name: "empty monitor data",
|
||||||
|
@ -130,6 +143,8 @@ func TestGatherNodeData(t *testing.T) {
|
||||||
responseMap: map[string]interface{}{
|
responseMap: map[string]interface{}{
|
||||||
"/api/json": struct{}{},
|
"/api/json": struct{}{},
|
||||||
"/computer/api/json": nodeResponse{
|
"/computer/api/json": nodeResponse{
|
||||||
|
BusyExecutors: 4,
|
||||||
|
TotalExecutors: 8,
|
||||||
Computers: []node{
|
Computers: []node{
|
||||||
{DisplayName: "ignore-1"},
|
{DisplayName: "ignore-1"},
|
||||||
{DisplayName: "ignore-2"},
|
{DisplayName: "ignore-2"},
|
||||||
|
@ -137,6 +152,19 @@ func TestGatherNodeData(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
output: &testutil.Accumulator{
|
||||||
|
Metrics: []*testutil.Metric{
|
||||||
|
{
|
||||||
|
Tags: map[string]string{
|
||||||
|
"source": "127.0.0.1",
|
||||||
|
},
|
||||||
|
Fields: map[string]interface{}{
|
||||||
|
"busy_executors": 4,
|
||||||
|
"total_executors": 8,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "normal data collection",
|
name: "normal data collection",
|
||||||
|
@ -144,6 +172,8 @@ func TestGatherNodeData(t *testing.T) {
|
||||||
responseMap: map[string]interface{}{
|
responseMap: map[string]interface{}{
|
||||||
"/api/json": struct{}{},
|
"/api/json": struct{}{},
|
||||||
"/computer/api/json": nodeResponse{
|
"/computer/api/json": nodeResponse{
|
||||||
|
BusyExecutors: 4,
|
||||||
|
TotalExecutors: 8,
|
||||||
Computers: []node{
|
Computers: []node{
|
||||||
{
|
{
|
||||||
DisplayName: "master",
|
DisplayName: "master",
|
||||||
|
@ -175,6 +205,15 @@ func TestGatherNodeData(t *testing.T) {
|
||||||
},
|
},
|
||||||
output: &testutil.Accumulator{
|
output: &testutil.Accumulator{
|
||||||
Metrics: []*testutil.Metric{
|
Metrics: []*testutil.Metric{
|
||||||
|
{
|
||||||
|
Tags: map[string]string{
|
||||||
|
"source": "127.0.0.1",
|
||||||
|
},
|
||||||
|
Fields: map[string]interface{}{
|
||||||
|
"busy_executors": 4,
|
||||||
|
"total_executors": 8,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Tags: map[string]string{
|
Tags: map[string]string{
|
||||||
"node_name": "master",
|
"node_name": "master",
|
||||||
|
@ -203,6 +242,8 @@ func TestGatherNodeData(t *testing.T) {
|
||||||
responseMap: map[string]interface{}{
|
responseMap: map[string]interface{}{
|
||||||
"/api/json": struct{}{},
|
"/api/json": struct{}{},
|
||||||
"/computer/api/json": nodeResponse{
|
"/computer/api/json": nodeResponse{
|
||||||
|
BusyExecutors: 4,
|
||||||
|
TotalExecutors: 8,
|
||||||
Computers: []node{
|
Computers: []node{
|
||||||
{
|
{
|
||||||
DisplayName: "slave",
|
DisplayName: "slave",
|
||||||
|
@ -216,6 +257,15 @@ func TestGatherNodeData(t *testing.T) {
|
||||||
},
|
},
|
||||||
output: &testutil.Accumulator{
|
output: &testutil.Accumulator{
|
||||||
Metrics: []*testutil.Metric{
|
Metrics: []*testutil.Metric{
|
||||||
|
{
|
||||||
|
Tags: map[string]string{
|
||||||
|
"source": "127.0.0.1",
|
||||||
|
},
|
||||||
|
Fields: map[string]interface{}{
|
||||||
|
"busy_executors": 4,
|
||||||
|
"total_executors": 8,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Tags: map[string]string{
|
Tags: map[string]string{
|
||||||
"node_name": "slave",
|
"node_name": "slave",
|
||||||
|
@ -252,19 +302,21 @@ func TestGatherNodeData(t *testing.T) {
|
||||||
t.Fatalf("%s: expected err, got nil", test.name)
|
t.Fatalf("%s: expected err, got nil", test.name)
|
||||||
}
|
}
|
||||||
if test.output == nil && len(acc.Metrics) > 0 {
|
if test.output == nil && len(acc.Metrics) > 0 {
|
||||||
t.Fatalf("%s: collected extra data", test.name)
|
t.Fatalf("%s: collected extra data %s", test.name, acc.Metrics)
|
||||||
} else if test.output != nil && len(test.output.Metrics) > 0 {
|
} else if test.output != nil && len(test.output.Metrics) > 0 {
|
||||||
for k, m := range test.output.Metrics[0].Tags {
|
for i := 0; i < len(test.output.Metrics); i++ {
|
||||||
if acc.Metrics[0].Tags[k] != m {
|
for k, m := range test.output.Metrics[i].Tags {
|
||||||
|
if acc.Metrics[i].Tags[k] != m {
|
||||||
t.Fatalf("%s: tag %s metrics unmatch Expected %s, got %s\n", test.name, k, m, acc.Metrics[0].Tags[k])
|
t.Fatalf("%s: tag %s metrics unmatch Expected %s, got %s\n", test.name, k, m, acc.Metrics[0].Tags[k])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for k, m := range test.output.Metrics[0].Fields {
|
for k, m := range test.output.Metrics[i].Fields {
|
||||||
if acc.Metrics[0].Fields[k] != m {
|
if acc.Metrics[i].Fields[k] != m {
|
||||||
t.Fatalf("%s: field %s metrics unmatch Expected %v(%T), got %v(%T)\n", test.name, k, m, m, acc.Metrics[0].Fields[k], acc.Metrics[0].Fields[k])
|
t.Fatalf("%s: field %s metrics unmatch Expected %v(%T), got %v(%T)\n", test.name, k, m, m, acc.Metrics[0].Fields[k], acc.Metrics[0].Fields[k])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue