Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added source and port tags in jenkins_job metrics #6844

Merged
merged 4 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions plugins/inputs/jenkins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
- node_name
- status ("online", "offline")
- source
- port
- fields:
- disk_available
- temp_available
- memory_available
- memory_total
- swap_available
- swap_total
- response_time
- disk_available (Bytes)
- temp_available (Bytes)
- memory_available (Bytes)
- memory_total (Bytes)
- swap_available (Bytes)
- swap_total (Bytes)
- response_time (ms)
- num_executors

- jenkins_job
Expand All @@ -76,8 +77,9 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
- parents
- result
- source
- port
- fields:
- duration
- duration (ms)
- result_code (0 = SUCCESS, 1 = FAILURE, 2 = NOT_BUILD, 3 = UNSTABLE, 4 = ABORTED)

### Sample Queries:
Expand All @@ -94,7 +96,8 @@ SELECT mean("duration") AS "mean_duration" FROM "jenkins_job" WHERE time > now()

```
$ ./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_job,host=myhost,name=JOB1,parents=apps/br1,result=SUCCESS duration=2831i,result_code=0i 1516026630000000000
jenkins_job,host=myhost,name=JOB2,parents=apps/br2,result=SUCCESS duration=2285i,result_code=0i 1516027230000000000
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=JOB2,parents=apps/br2,result=SUCCESS,source=my-jenkins-instance,port=8080 duration=2285i,result_code=0i 1516027230000000000
```

32 changes: 23 additions & 9 deletions plugins/inputs/jenkins/jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Jenkins struct {
URL string
Username string
Password string
Source string
Port string
// HTTP Timeout specified as a string - 3s, 1m, 1h
ResponseTimeout internal.Duration

Expand Down Expand Up @@ -138,6 +140,22 @@ func (j *Jenkins) newHTTPClient() (*http.Client, error) {
func (j *Jenkins) initialize(client *http.Client) 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
j.jobFilter, err = filter.Compile(j.JobExclude)
if err != nil {
Expand Down Expand Up @@ -191,12 +209,8 @@ func (j *Jenkins) gatherNodeData(n node, acc telegraf.Accumulator) error {
tags["status"] = "offline"
}

u, err := url.Parse(j.URL)
if err != nil {
return err
}
tags["source"] = u.Hostname()
tags["port"] = u.Port()
tags["source"] = j.Source
tags["port"] = j.Port

fields := make(map[string]interface{})
fields["num_executors"] = n.NumExecutors
Expand Down Expand Up @@ -334,7 +348,7 @@ func (j *Jenkins) getJobDetail(jr jobRequest, acc telegraf.Accumulator) error {
return nil
}

gatherJobBuild(jr, build, acc)
j.gatherJobBuild(jr, build, acc)
return nil
}

Expand Down Expand Up @@ -432,8 +446,8 @@ func (jr jobRequest) parentsString() string {
return strings.Join(jr.parents, "/")
}

func gatherJobBuild(jr jobRequest, b *buildResponse, acc telegraf.Accumulator) {
tags := map[string]string{"name": jr.name, "parents": jr.parentsString(), "result": b.Result}
func (j *Jenkins) gatherJobBuild(jr jobRequest, b *buildResponse, acc telegraf.Accumulator) {
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["duration"] = b.Duration
fields["result_code"] = mapResultCode(b.Result)
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/jenkins/jenkins_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Test Suite
package jenkins

import (
Expand Down