Skip to content

Commit

Permalink
chore: clean up all markdown lint errors in first half of docs direct…
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored Nov 24, 2021
1 parent 96e939a commit 0036757
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 189 deletions.
124 changes: 62 additions & 62 deletions docs/AGGREGATORS.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
### Aggregator Plugins
# Aggregator Plugins

This section is for developers who want to create a new aggregator plugin.

### Aggregator Plugin Guidelines
## Aggregator Plugin Guidelines

* A aggregator must conform to the [telegraf.Aggregator][] interface.
* Aggregators should call `aggregators.Add` in their `init` function to
register themselves. See below for a quick example.
* To be available within Telegraf itself, plugins must add themselves to the
`github.com/influxdata/telegraf/plugins/aggregators/all/all.go` file.
- The `SampleConfig` function should return valid toml that describes how the
* The `SampleConfig` function should return valid toml that describes how the
plugin can be configured. This is included in `telegraf config`. Please
consult the [Sample Config][] page for the latest style guidelines.
* The `Description` function should say in one line what this aggregator does.
* The Aggregator plugin will need to keep caches of metrics that have passed
through it. This should be done using the builtin `HashID()` function of
each metric.
* When the `Reset()` function is called, all caches should be cleared.
- Follow the recommended [Code Style][].
* Follow the recommended [Code Style][].

### Aggregator Plugin Example

Expand All @@ -27,21 +27,21 @@ package min
// min.go

import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/aggregators"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/aggregators"
)

type Min struct {
// caches for metric fields, names, and tags
fieldCache map[uint64]map[string]float64
nameCache map[uint64]string
tagCache map[uint64]map[string]string
// caches for metric fields, names, and tags
fieldCache map[uint64]map[string]float64
nameCache map[uint64]string
tagCache map[uint64]map[string]string
}

func NewMin() telegraf.Aggregator {
m := &Min{}
m.Reset()
return m
m := &Min{}
m.Reset()
return m
}

var sampleConfig = `
Expand All @@ -53,77 +53,77 @@ var sampleConfig = `
`

func (m *Min) Init() error {
return nil
return nil
}

func (m *Min) SampleConfig() string {
return sampleConfig
return sampleConfig
}

func (m *Min) Description() string {
return "Keep the aggregate min of each metric passing through."
return "Keep the aggregate min of each metric passing through."
}

func (m *Min) Add(in telegraf.Metric) {
id := in.HashID()
if _, ok := m.nameCache[id]; !ok {
// hit an uncached metric, create caches for first time:
m.nameCache[id] = in.Name()
m.tagCache[id] = in.Tags()
m.fieldCache[id] = make(map[string]float64)
for k, v := range in.Fields() {
if fv, ok := convert(v); ok {
m.fieldCache[id][k] = fv
}
}
} else {
for k, v := range in.Fields() {
if fv, ok := convert(v); ok {
if _, ok := m.fieldCache[id][k]; !ok {
// hit an uncached field of a cached metric
m.fieldCache[id][k] = fv
continue
}
if fv < m.fieldCache[id][k] {
id := in.HashID()
if _, ok := m.nameCache[id]; !ok {
// hit an uncached metric, create caches for first time:
m.nameCache[id] = in.Name()
m.tagCache[id] = in.Tags()
m.fieldCache[id] = make(map[string]float64)
for k, v := range in.Fields() {
if fv, ok := convert(v); ok {
m.fieldCache[id][k] = fv
}
}
} else {
for k, v := range in.Fields() {
if fv, ok := convert(v); ok {
if _, ok := m.fieldCache[id][k]; !ok {
// hit an uncached field of a cached metric
m.fieldCache[id][k] = fv
continue
}
if fv < m.fieldCache[id][k] {
// set new minimum
m.fieldCache[id][k] = fv
}
}
}
}
m.fieldCache[id][k] = fv
}
}
}
}
}

func (m *Min) Push(acc telegraf.Accumulator) {
for id, _ := range m.nameCache {
fields := map[string]interface{}{}
for k, v := range m.fieldCache[id] {
fields[k+"_min"] = v
}
acc.AddFields(m.nameCache[id], fields, m.tagCache[id])
}
for id, _ := range m.nameCache {
fields := map[string]interface{}{}
for k, v := range m.fieldCache[id] {
fields[k+"_min"] = v
}
acc.AddFields(m.nameCache[id], fields, m.tagCache[id])
}
}

func (m *Min) Reset() {
m.fieldCache = make(map[uint64]map[string]float64)
m.nameCache = make(map[uint64]string)
m.tagCache = make(map[uint64]map[string]string)
m.fieldCache = make(map[uint64]map[string]float64)
m.nameCache = make(map[uint64]string)
m.tagCache = make(map[uint64]map[string]string)
}

func convert(in interface{}) (float64, bool) {
switch v := in.(type) {
case float64:
return v, true
case int64:
return float64(v), true
default:
return 0, false
}
switch v := in.(type) {
case float64:
return v, true
case int64:
return float64(v), true
default:
return 0, false
}
}

func init() {
aggregators.Add("min", func() telegraf.Aggregator {
return NewMin()
})
aggregators.Add("min", func() telegraf.Aggregator {
return NewMin()
})
}
```

Expand Down
8 changes: 5 additions & 3 deletions docs/AGGREGATORS_AND_PROCESSORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ As of release 1.1.0, Telegraf has the concept of Aggregator and Processor Plugin
These plugins sit in-between Input & Output plugins, aggregating and processing
metrics as they pass through Telegraf:

```
```text
┌───────────┐
│ │
│ CPU │───┐
Expand Down Expand Up @@ -44,12 +44,14 @@ to control which metrics are passed through a processor or aggregator. If a
metric is filtered out the metric bypasses the plugin and is passed downstream
to the next plugin.

### Processor
## Processor

Processor plugins process metrics as they pass through and immediately emit
results based on the values they process. For example, this could be printing
all metrics or adding a tag to all metrics that pass through.

### Aggregator
## Aggregator

Aggregator plugins, on the other hand, are a bit more complicated. Aggregators
are typically for emitting new _aggregate_ metrics, such as a running mean,
minimum, maximum, or standard deviation. For this reason, all _aggregator_
Expand Down
16 changes: 8 additions & 8 deletions docs/COMMANDS_AND_FLAGS.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# Telegraf Commands & Flags

### Usage
## Usage

```
```shell
telegraf [commands]
telegraf [flags]
```

### Commands
## Commands

|command|description|
|--------|-----------------------------------------------|
|`config` |print out full sample configuration to stdout|
|`version`|print the version to stdout|

### Flags
## Flags

|flag|description|
|-------------------|------------|
|`--aggregator-filter <filter>` |filter the aggregators to enable, separator is `:`|
|`--config <file>` |configuration file to load|
|`--config-directory <directory>` |directory containing additional *.conf files|
|`--watch-config` |Telegraf will restart on local config changes. <br> Monitor changes using either fs notifications or polling. Valid values: `inotify` or `poll`.<br> Monitoring is off by default.|
|`--watch-config` |Telegraf will restart on local config changes. Monitor changes using either fs notifications or polling. Valid values: `inotify` or `poll`. Monitoring is off by default.|
|`--plugin-directory` |directory containing *.so files, this directory will be searched recursively. Any Plugin found will be loaded and namespaced.|
|`--debug` |turn on debug logging|
|`--input-filter <filter>` |filter the inputs to enable, separator is `:`|
Expand All @@ -32,15 +32,15 @@ telegraf [flags]
|`--pprof-addr <address>` |pprof address to listen on, don't activate pprof if empty|
|`--processor-filter <filter>` |filter the processors to enable, separator is `:`|
|`--quiet` |run in quiet mode|
|`--section-filter` |filter config sections to output, separator is `:` <br> Valid values are `agent`, `global_tags`, `outputs`, `processors`, `aggregators` and `inputs`|
|`--section-filter` |filter config sections to output, separator is `:`. Valid values are `agent`, `global_tags`, `outputs`, `processors`, `aggregators` and `inputs`|
|`--sample-config` |print out full sample configuration|
|`--once` |enable once mode: gather metrics once, write them, and exit|
|`--test` |enable test mode: gather metrics once and print them|
|`--test-wait` |wait up to this many seconds for service inputs to complete in test or once mode|
|`--usage <plugin>` |print usage for a plugin, ie, `telegraf --usage mysql`|
|`--version` |display the version and exit|

### Examples
## Examples

**Generate a telegraf config file:**

Expand All @@ -55,7 +55,7 @@ telegraf [flags]
`telegraf --config telegraf.conf --test`

**Run telegraf with all plugins defined in config file:**

`telegraf --config telegraf.conf`

**Run telegraf, enabling the cpu & memory input, and influxdb output plugins:**
Expand Down
Loading

0 comments on commit 0036757

Please sign in to comment.