telegraf: Telegraf Graylog Doesn't Pull Metrics

Relevant telegraf.conf

# Read flattened metrics from one or more GrayLog HTTP endpoints
[[inputs.graylog]]
  ## API endpoint, currently supported API:
  ##
  ##   - multiple  (Ex http://<host>:12900/system/metrics/multiple)
  ##   - namespace (Ex http://<host>:12900/system/metrics/namespace/{namespace})
  ##
  ## For namespace endpoint, the metrics array will be ignored for that call.
  ## Endpoint can contain namespace and multiple type calls.
  ##
  ## Please check http://[graylog-server-ip]:12900/api-browser for full list
  ## of endpoints
  servers = [
    "http://192.168.187.15:9000/api/system/metrics",
  ]

  timeout = "5s"

  ## Metrics list
  ## List of metrics can be found on Graylog webservice documentation.
  ## Or by hitting the web service api at:
  ##   http://[graylog-host]:12900/system/metrics
  metrics = [
    "org.graylog2.inputs",
    "org.graylog2.plugins",
    "org.graylog2.buffers",
    "org.graylog2.throughput"
  ]

  ## Username and password
  username = "admin"
  password = "********"

  ## Optional TLS Config
  # tls_ca = "/etc/telegraf/ca.pem"
  # tls_cert = "/etc/telegraf/cert.pem"
  # tls_key = "/etc/telegraf/key.pem"
  ## Use TLS but skip chain & host verification
  # insecure_skip_verify = true

Logs from Telegraf

root@influx:~# telegraf --config /etc/telegraf/telegraf.conf --input-filter graylog --test --debug
2022-10-02T00:52:07Z I! Starting Telegraf 1.25.0-ed0b59f1
2022-10-02T00:52:07Z I! Available plugins: 223 inputs, 9 aggregators, 26 processors, 20 parsers, 57 outputs
2022-10-02T00:52:07Z I! Loaded inputs: graylog
2022-10-02T00:52:07Z I! Loaded aggregators: 
2022-10-02T00:52:07Z I! Loaded processors: 
2022-10-02T00:52:07Z W! Outputs are not used in testing mode!
2022-10-02T00:52:07Z I! Tags enabled: 
2022-10-02T00:52:07Z D! [agent] Initializing plugins
2022-10-02T00:52:07Z D! [agent] Starting service inputs
2022-10-02T00:52:07Z D! [agent] Stopping service inputs
2022-10-02T00:52:07Z D! [agent] Input channel closed
2022-10-02T00:52:07Z D! [agent] Stopped Successfully

System info

Telegraf 1.25.0-ed0b59f1, Debian 11, LXC

Docker

  • Running as an LXC container under Proxmox.

Steps to reproduce

  1. Configure a graylog input to pull from the metrics api
  2. Test configuration with telegraf cli using --debug
  3. Validate that no data is received as shown in the telegraf log. …

Expected behavior

When I visit the API for Graylog directly to pull a list of fields, then endpoint is:

http://localhost:9000/api/system/metrics

Actual behavior

The API is accessible directly, but Telegraf just isn’t trying. See the screenshot in Additional Info.

Additional info

Screenshot of the current Graylog API Browser.

Screenshot 2022-10-01 at 8 00 09 PM

It looks like the endpoint changed, the url of the API browser changed, and this may have caused things to break in the Telegraf plugin.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@hackdefendr I am using an api-token to access. I have used this method since Graylog 2.3 series to access API to use it to pull performance metrics via Zabbix and then alerts in Grafana. I have replicated same method here for TICK stack.

From Joschi (Graylog Guy) - Github repo

Accessing API via token (see line 35) https://gist.github.com/joschi/21bc88207881581099570dd85588f7df[https://gist.github.com/joschi/21bc88207881581099570dd85588f7df

Accessing API via session token https://gist.github.com/joschi/72fb7e75b171c10d3717

You will see that accessing via sesion token has an expiry and so is not suitable for use with telegraf plugin. In your initial post, you are showing a username and password possibly in your telegraf.conf. I suggest replacing with an API key with appropriate permissions. I generally use an admin level key.

From your initial post.

## Username and password
  username = "admin"
  password = "********"

In the telegraf graylog input plugin at https://github.com/influxdata/telegraf/blob/master/plugins/inputs/graylog/graylog.go

We can see the following

Function Gather server makes the request and within in the function sendRequest(serverURL) makes the request.

//	error: Any error that may have occurred
func (h *GrayLog) gatherServer(
	acc telegraf.Accumulator,
	serverURL string,
) error {
	resp, _, err := h.sendRequest(serverURL)
	if err != nil {
		return err
	}
	requestURL, err := url.Parse(serverURL)
	if err != nil {
		return fmt.Errorf("unable to parse address '%s': %s", serverURL, err)
	}

	host, port, _ := net.SplitHostPort(requestURL.Host)
	var dat ResponseMetrics
	if err := json.Unmarshal([]byte(resp), &dat); err != nil {
		return err
	}
	for _, mItem := range dat.Metrics {
		fields := make(map[string]interface{})
		tags := map[string]string{
			"server": host,
			"port":   port,
			"name":   mItem.Name,
			"type":   mItem.Type,
		}
		h.flatten(mItem.Fields, fields, "")
		acc.AddFields(mItem.FullName, fields, tags)
	}
	return nil
}

An in the sendRequest method, we see

func (h *GrayLog) sendRequest(serverURL string) (string, float64, error) {
	headers := map[string]string{
		"Content-Type": "application/json",
		"Accept":       "application/json",
	}
	method := "GET"
	content := bytes.NewBufferString("")
	headers["Authorization"] = "Basic " + base64.URLEncoding.EncodeToString([]byte(h.Username+":"+h.Password))
	// Prepare URL
	requestURL, err := url.Parse(serverURL)

This means that if we set the username to the value of an api token and password to “token” , it will match the token example from before so that the authorisation header would be.

For example

api key = 8oe6l5b0db378b0qfsufa1j9jr4bnlvng1m6o998rag8fcmusj1
username =token

Will result in the following header

Authorisation: Basic 8oe6l5b0db378b0qfsufa1j9jr4bnlvng1m6o998rag8fcmusj1:token

Therefore looking at the examples provided it is clear that only the permanent api token method is supported. @powersj I think the documentation needs to be updated to reflect this issue or the code could be changed to support session method as well. However, the plugin works and does not need to be depreciated.

Hope this helps. Cyberkryption

I really appreciate that you took the time to look! I’ll leave this bug open to track deprecating the plugin.

I spent the previous evening looking over the code for this plugin and I don’t even know Go, but I was willing to try. In the end, I have nothing to show. I have no idea how to fix this plugin and if you don’t have the time then deprecation is the right path.