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

Influxdbjson #424

Closed
wants to merge 5 commits into from
Closed

Influxdbjson #424

wants to merge 5 commits into from

Conversation

mark-rushakoff
Copy link
Contributor

(Replaces #421)

This was primarily intended to consume a JSON endpoint structed like InfluxDB's expvars endpoint under /debug/vars.

That endpoint follows a structure like

{
  "httpd::8086": {
    "name": "httpd",
    "tags": {
      "bind": ":8086"
    },
    "values": {
      "pointsWrittenOK": 33756,
      "queryReq": 19,
      "queryRespBytes": 26973,
      "req": 428,
      "writeReq": 205,
      "writeReqBytes": 3939161
    }
  }
}

There are an arbitrary number of top-level keys in the JSON response at
the configured URLs, and this plugin will iterate through all of their
values looking for objects with keys "name", "tags", and "values"
indicating a metric to be consumed by telegraf.

Running this on current master of InfluxDB, I am able to record nearly
the same information that is normally stored in the _internal
database; the only measurement missing from _internal is runtime,
which is present in the endpoint under the "memstats" key but does not follow
the point format and so is not consumed in this plugin.

$ influx -database=telegraf -execute 'SHOW FIELD KEYS FROM /influxdbjson/'
name: influxdbjson_influxdb_engine
----------------------------------
fieldKey
blksWrite
blksWriteBytes
blksWriteBytesC
pointsWrite
pointsWriteDedupe


name: influxdbjson_influxdb_httpd
---------------------------------
fieldKey
pointsWrittenOK
queryReq
queryRespBytes
req
writeReq
writeReqBytes


name: influxdbjson_influxdb_shard
---------------------------------
fieldKey
fieldsCreate
seriesCreate
writePointsOk
writeReq


name: influxdbjson_influxdb_subscriber
--------------------------------------
fieldKey
pointsWritten


name: influxdbjson_influxdb_wal
-------------------------------
fieldKey
autoFlush
flushDuration
idleFlush
memSize
pointsFlush
pointsWrite
pointsWriteReq
seriesFlush


name: influxdbjson_influxdb_write
---------------------------------
fieldKey
pointReq
pointReqLocal
req
subWriteOk
writeOk

(Potentially closes #366, btw.)

This was primarily intended to consume InfluxDB-style expvars,
particularly InfluxDB's `/debug/vars` endpoint.

That endpoint follows a structure like

```json
{
  "httpd::8086": {
    "name": "httpd",
    "tags": {
      "bind": ":8086"
    },
    "values": {
      "pointsWrittenOK": 33756,
      "queryReq": 19,
      "queryRespBytes": 26973,
      "req": 428,
      "writeReq": 205,
      "writeReqBytes": 3939161
    }
  }
}
```

There are an arbitrary number of top-level keys in the JSON response at
the configured URLs, and this plugin will iterate through all of their
values looking for objects with keys "name", "tags", and "values"
indicating a metric to be consumed by telegraf.

Running this on current master of InfluxDB, I am able to record nearly
the same information that is normally stored in the `_internal`
database; the only measurement missing from `_internal` is `runtime`,
which is present in expvars under the "memstats" key but does not follow
the expvar format and so is not consumed in this plugin.

```
$ influx -database=telegraf -execute 'SHOW FIELD KEYS FROM /expvar/'

name: expvar_influxdb_engine
----------------------------
fieldKey
blksWrite
blksWriteBytes
blksWriteBytesC
pointsWrite
pointsWriteDedupe

name: expvar_influxdb_httpd
---------------------------
fieldKey
pingReq
pointsWrittenOK
queryReq
queryRespBytes
req
writeReq
writeReqBytes

name: expvar_influxdb_shard
---------------------------
fieldKey
fieldsCreate
seriesCreate
writePointsOk
writeReq

name: expvar_influxdb_subscriber
--------------------------------
fieldKey
pointsWritten

name: expvar_influxdb_wal
-------------------------
fieldKey
autoFlush
flushDuration
idleFlush
memSize
metaFlush
pointsFlush
pointsWrite
pointsWriteReq
seriesFlush

name: expvar_influxdb_write
---------------------------
fieldKey
pointReq
pointReqLocal
req
subWriteOk
writeOk
```
@mark-rushakoff
Copy link
Contributor Author

@otoolep Does this telegraf plugin seem reasonable to you? It's directly dependent on the JSON structure of the core database's /debug/vars endpoint.

@mark-rushakoff mark-rushakoff mentioned this pull request Dec 8, 2015
}

// Add a tag to indicate the source of the data.
p.Tags["influxdbjson_url"] = url
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sparrc does adding this tag seem reasonable to you? Or do you think it would be better to allow the user to specify their own tags explicitly somehow?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mark-rushakoff let's change the name to just url, to be more consistent with other plugins

@otoolep
Copy link

otoolep commented Dec 8, 2015

I will definitely take a look at this shortly.

@otoolep
Copy link

otoolep commented Dec 8, 2015

Yes @mark-rushakoff -- this should be fine going forward.

@sparrc
Copy link
Contributor

sparrc commented Dec 11, 2015

@mark-rushakoff sorry to ask for a name change again 😅, but there aren't any other plugins that state the output format in their name, could you change to just influxdb or influx?


func (*InfluxDBJSON) SampleConfig() string {
return `
# Reads InfluxDB-formatted JSON from given URLs. For example,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be indented by 2 spaces

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this seems like it belongs more in the README, telegraf config file would be tens of thousands of lines if we had in/out examples for each plugin

@mark-rushakoff
Copy link
Contributor Author

I don't mind doing another rename and making the other requested changes, but I don't think that influxdb or influx are clear enough names. If I saw either of those as a plugin name I would assume the plugin was to consume data directly from InfluxDB, presumably via executing queries.

Maybe the underlying issue is that this plugin is attempting to consume data formatted in a way that isn't standardized per se. @otoolep said that it should be safe to rely on that format from InfluxDB, but aside from actually inspecting the endpoint (or the code in this PR), there isn't documentation on that format that I'm aware of.

@sparrc
Copy link
Contributor

sparrc commented Dec 15, 2015

@mark-rushakoff but from a consistency point of view, a plain plugin name assumes that it consumes metrics from that particular service. For example, the mysql, postgresql, and redis plugins all collect metrics on the actual database itself, they do not perform queries.

I agree with you that it's ambiguous in general, but other collection tools do the same thing (see https://collectd.org/wiki/index.php/Plugin:MySQL) and users are accustomed to this style of naming.

@mark-rushakoff
Copy link
Contributor Author

I wasn't familiar enough with the patterns other collection tools use. I'll rename to influxdb and include the other requested changes sometime this week.

@mark-rushakoff
Copy link
Contributor Author

Had some test trouble, so rebased onto master and also squashed into a single commit (which got tests passing again). Updated PR at #449.

@mark-rushakoff mark-rushakoff deleted the influxdbjson branch December 19, 2015 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InfluxDB input plugin
3 participants