Add source and port tags to jenkins plugin (#6641)

This commit is contained in:
Nick Neisen 2019-11-13 14:38:33 -07:00 committed by Daniel Nelson
parent 48c271640c
commit 0c918b099b
3 changed files with 13 additions and 2 deletions

View File

@ -8,7 +8,7 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
```toml ```toml
[[inputs.jenkins]] [[inputs.jenkins]]
## The Jenkins URL ## The Jenkins URL in the format "schema://host:port"
url = "http://my-jenkins-instance:8080" url = "http://my-jenkins-instance:8080"
# username = "admin" # username = "admin"
# password = "admin" # password = "admin"
@ -59,6 +59,7 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
- temp_path - temp_path
- node_name - node_name
- status ("online", "offline") - status ("online", "offline")
- source
- fields: - fields:
- disk_available - disk_available
- temp_available - temp_available
@ -74,6 +75,7 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
- name - name
- parents - parents
- result - result
- source
- fields: - fields:
- duration - duration
- 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)

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"net/http" "net/http"
"net/url"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -43,7 +44,7 @@ type Jenkins struct {
} }
const sampleConfig = ` const sampleConfig = `
## The Jenkins URL ## The Jenkins URL in the format "schema://host:port"
url = "http://my-jenkins-instance:8080" url = "http://my-jenkins-instance:8080"
# username = "admin" # username = "admin"
# password = "admin" # password = "admin"
@ -190,6 +191,13 @@ func (j *Jenkins) gatherNodeData(n node, acc telegraf.Accumulator) error {
tags["status"] = "offline" tags["status"] = "offline"
} }
u, err := url.Parse(j.URL)
if err != nil {
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

View File

@ -181,6 +181,7 @@ func TestGatherNodeData(t *testing.T) {
"status": "online", "status": "online",
"disk_path": "/path/1", "disk_path": "/path/1",
"temp_path": "/path/2", "temp_path": "/path/2",
"source": "127.0.0.1",
}, },
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"response_time": int64(10032), "response_time": int64(10032),