Add source and port tags to jenkins_job metrics (#6844)
This commit is contained in:
parent
7faf05023d
commit
1b1d78b8dd
|
@ -60,14 +60,15 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
|
||||||
- node_name
|
- node_name
|
||||||
- status ("online", "offline")
|
- status ("online", "offline")
|
||||||
- source
|
- source
|
||||||
|
- port
|
||||||
- fields:
|
- fields:
|
||||||
- disk_available
|
- disk_available (Bytes)
|
||||||
- temp_available
|
- temp_available (Bytes)
|
||||||
- memory_available
|
- memory_available (Bytes)
|
||||||
- memory_total
|
- memory_total (Bytes)
|
||||||
- swap_available
|
- swap_available (Bytes)
|
||||||
- swap_total
|
- swap_total (Bytes)
|
||||||
- response_time
|
- response_time (ms)
|
||||||
- num_executors
|
- num_executors
|
||||||
|
|
||||||
- jenkins_job
|
- jenkins_job
|
||||||
|
@ -76,8 +77,9 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
|
||||||
- parents
|
- parents
|
||||||
- result
|
- result
|
||||||
- source
|
- source
|
||||||
|
- port
|
||||||
- fields:
|
- fields:
|
||||||
- duration
|
- duration (ms)
|
||||||
- result_code (0 = SUCCESS, 1 = FAILURE, 2 = NOT_BUILD, 3 = UNSTABLE, 4 = ABORTED)
|
- result_code (0 = SUCCESS, 1 = FAILURE, 2 = NOT_BUILD, 3 = UNSTABLE, 4 = ABORTED)
|
||||||
|
|
||||||
### Sample Queries:
|
### Sample Queries:
|
||||||
|
@ -94,7 +96,8 @@ 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_node,arch=Linux\ (amd64),disk_path=/var/jenkins_home,temp_path=/tmp,host=myhost,node_name=master swap_total=4294963200,memory_available=586711040,memory_total=6089498624,status=online,response_time=1000i,disk_available=152392036352,temp_available=152392036352,swap_available=3503263744 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 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 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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ type Jenkins struct {
|
||||||
URL string
|
URL string
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
|
Source string
|
||||||
|
Port string
|
||||||
// HTTP Timeout specified as a string - 3s, 1m, 1h
|
// HTTP Timeout specified as a string - 3s, 1m, 1h
|
||||||
ResponseTimeout internal.Duration
|
ResponseTimeout internal.Duration
|
||||||
|
|
||||||
|
@ -138,6 +140,22 @@ func (j *Jenkins) newHTTPClient() (*http.Client, error) {
|
||||||
func (j *Jenkins) initialize(client *http.Client) error {
|
func (j *Jenkins) initialize(client *http.Client) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// init jenkins tags
|
||||||
|
u, err := url.Parse(j.URL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if u.Port() == "" {
|
||||||
|
if u.Scheme == "http" {
|
||||||
|
j.Port = "80"
|
||||||
|
} else if u.Scheme == "https" {
|
||||||
|
j.Port = "443"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
j.Port = u.Port()
|
||||||
|
}
|
||||||
|
j.Source = u.Hostname()
|
||||||
|
|
||||||
// init job filter
|
// init job filter
|
||||||
j.jobFilter, err = filter.Compile(j.JobExclude)
|
j.jobFilter, err = filter.Compile(j.JobExclude)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -191,12 +209,8 @@ func (j *Jenkins) gatherNodeData(n node, acc telegraf.Accumulator) error {
|
||||||
tags["status"] = "offline"
|
tags["status"] = "offline"
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := url.Parse(j.URL)
|
tags["source"] = j.Source
|
||||||
if err != nil {
|
tags["port"] = j.Port
|
||||||
return err
|
|
||||||
}
|
|
||||||
tags["source"] = u.Hostname()
|
|
||||||
tags["port"] = u.Port()
|
|
||||||
|
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
fields["num_executors"] = n.NumExecutors
|
fields["num_executors"] = n.NumExecutors
|
||||||
|
@ -334,7 +348,7 @@ func (j *Jenkins) getJobDetail(jr jobRequest, acc telegraf.Accumulator) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gatherJobBuild(jr, build, acc)
|
j.gatherJobBuild(jr, build, acc)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,8 +446,8 @@ func (jr jobRequest) parentsString() string {
|
||||||
return strings.Join(jr.parents, "/")
|
return strings.Join(jr.parents, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
func gatherJobBuild(jr jobRequest, b *buildResponse, acc telegraf.Accumulator) {
|
func (j *Jenkins) gatherJobBuild(jr jobRequest, b *buildResponse, acc telegraf.Accumulator) {
|
||||||
tags := map[string]string{"name": jr.name, "parents": jr.parentsString(), "result": b.Result}
|
tags := map[string]string{"name": jr.name, "parents": jr.parentsString(), "result": b.Result, "source": j.Source, "port": j.Port}
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
fields["duration"] = b.Duration
|
fields["duration"] = b.Duration
|
||||||
fields["result_code"] = mapResultCode(b.Result)
|
fields["result_code"] = mapResultCode(b.Result)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Test Suite
|
||||||
package jenkins
|
package jenkins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
Loading…
Reference in New Issue