Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
168
plugins/inputs/puppetagent/README.md
Normal file
168
plugins/inputs/puppetagent/README.md
Normal file
|
@ -0,0 +1,168 @@
|
|||
# PuppetAgent Input Plugin
|
||||
|
||||
The puppetagent plugin collects variables outputted from the
|
||||
'last_run_summary.yaml' file usually located in `/var/lib/puppet/state/`
|
||||
[PuppetAgent Runs][1].
|
||||
|
||||
```sh
|
||||
cat /var/lib/puppet/state/last_run_summary.yaml
|
||||
|
||||
---
|
||||
events:
|
||||
failure: 0
|
||||
total: 0
|
||||
success: 0
|
||||
resources:
|
||||
failed: 0
|
||||
scheduled: 0
|
||||
changed: 0
|
||||
skipped: 0
|
||||
total: 109
|
||||
failed_to_restart: 0
|
||||
restarted: 0
|
||||
out_of_sync: 0
|
||||
changes:
|
||||
total: 0
|
||||
time:
|
||||
user: 0.004331
|
||||
schedule: 0.001123
|
||||
filebucket: 0.000353
|
||||
file: 0.441472
|
||||
exec: 0.508123
|
||||
anchor: 0.000555
|
||||
yumrepo: 0.006989
|
||||
ssh_authorized_key: 0.000764
|
||||
service: 1.807795
|
||||
package: 1.325788
|
||||
total: 8.85354707064819
|
||||
config_retrieval: 4.75567007064819
|
||||
last_run: 1444936531
|
||||
cron: 0.000584
|
||||
version:
|
||||
config: 1444936521
|
||||
puppet: "3.7.5"
|
||||
```
|
||||
|
||||
```sh
|
||||
jcross@pit-devops-02 ~ >sudo ./telegraf_linux_amd64 --input-filter puppetagent --config tele.conf --test
|
||||
* Plugin: puppetagent, Collection 1
|
||||
> [] puppetagent_events_failure value=0
|
||||
> [] puppetagent_events_total value=0
|
||||
> [] puppetagent_events_success value=0
|
||||
> [] puppetagent_resources_failed value=0
|
||||
> [] puppetagent_resources_scheduled value=0
|
||||
> [] puppetagent_resources_changed value=0
|
||||
> [] puppetagent_resources_skipped value=0
|
||||
> [] puppetagent_resources_total value=109
|
||||
> [] puppetagent_resources_failedtorestart value=0
|
||||
> [] puppetagent_resources_restarted value=0
|
||||
> [] puppetagent_resources_outofsync value=0
|
||||
> [] puppetagent_changes_total value=0
|
||||
> [] puppetagent_time_user value=0.00393
|
||||
> [] puppetagent_time_schedule value=0.001234
|
||||
> [] puppetagent_time_filebucket value=0.000244
|
||||
> [] puppetagent_time_file value=0.587734
|
||||
> [] puppetagent_time_exec value=0.389584
|
||||
> [] puppetagent_time_anchor value=0.000399
|
||||
> [] puppetagent_time_sshauthorizedkey value=0.000655
|
||||
> [] puppetagent_time_service value=0
|
||||
> [] puppetagent_time_package value=1.297537
|
||||
> [] puppetagent_time_total value=9.45297606225586
|
||||
> [] puppetagent_time_configretrieval value=5.89822006225586
|
||||
> [] puppetagent_time_lastrun value=1444940131
|
||||
> [] puppetagent_time_cron value=0.000646
|
||||
> [] puppetagent_version_config value=1444940121
|
||||
> [] puppetagent_version_puppet value=3.7.5
|
||||
```
|
||||
|
||||
[1]: https://puppet.com/blog/puppet-monitoring-how-to-monitor-success-or-failure-of-puppet-runs/
|
||||
|
||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
||||
|
||||
In addition to the plugin-specific configuration settings, plugins support
|
||||
additional global and plugin configuration settings. These settings are used to
|
||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||
|
||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
||||
|
||||
## Configuration
|
||||
|
||||
```toml @sample.conf
|
||||
# Reads last_run_summary.yaml file and converts to measurements
|
||||
[[inputs.puppetagent]]
|
||||
## Location of puppet last run summary file
|
||||
location = "/var/lib/puppet/state/last_run_summary.yaml"
|
||||
```
|
||||
|
||||
## Metrics
|
||||
|
||||
### PuppetAgent int64 measurements
|
||||
|
||||
Meta:
|
||||
|
||||
- units: int64
|
||||
- tags: ``
|
||||
|
||||
Measurement names:
|
||||
|
||||
- puppetagent_changes_total
|
||||
- puppetagent_events_failure
|
||||
- puppetagent_events_total
|
||||
- puppetagent_events_success
|
||||
- puppetagent_resources_changed
|
||||
- puppetagent_resources_corrective_change
|
||||
- puppetagent_resources_failed
|
||||
- puppetagent_resources_failedtorestart
|
||||
- puppetagent_resources_outofsync
|
||||
- puppetagent_resources_restarted
|
||||
- puppetagent_resources_scheduled
|
||||
- puppetagent_resources_skipped
|
||||
- puppetagent_resources_total
|
||||
- puppetagent_time_service
|
||||
- puppetagent_time_lastrun
|
||||
- puppetagent_version_config
|
||||
|
||||
### PuppetAgent float64 measurements
|
||||
|
||||
Meta:
|
||||
|
||||
- units: float64
|
||||
- tags: ``
|
||||
|
||||
Measurement names:
|
||||
|
||||
- puppetagent_time_anchor
|
||||
- puppetagent_time_catalogapplication
|
||||
- puppetagent_time_configretrieval
|
||||
- puppetagent_time_convertcatalog
|
||||
- puppetagent_time_cron
|
||||
- puppetagent_time_exec
|
||||
- puppetagent_time_factgeneration
|
||||
- puppetagent_time_file
|
||||
- puppetagent_time_filebucket
|
||||
- puppetagent_time_group
|
||||
- puppetagent_time_lastrun
|
||||
- puppetagent_time_noderetrieval
|
||||
- puppetagent_time_notify
|
||||
- puppetagent_time_package
|
||||
- puppetagent_time_pluginsync
|
||||
- puppetagent_time_schedule
|
||||
- puppetagent_time_sshauthorizedkey
|
||||
- puppetagent_time_total
|
||||
- puppetagent_time_transactionevaluation
|
||||
- puppetagent_time_user
|
||||
- puppetagent_version_config
|
||||
|
||||
### PuppetAgent string measurements
|
||||
|
||||
Meta:
|
||||
|
||||
- units: string
|
||||
- tags: ``
|
||||
|
||||
Measurement names:
|
||||
|
||||
- puppetagent_version_puppet
|
||||
|
||||
## Example Output
|
43
plugins/inputs/puppetagent/last_run_summary.yaml
Normal file
43
plugins/inputs/puppetagent/last_run_summary.yaml
Normal file
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
events:
|
||||
failure: 0
|
||||
noop: 0
|
||||
total: 0
|
||||
success: 0
|
||||
resources:
|
||||
changed: 0
|
||||
corrective_change: 0
|
||||
failed: 0
|
||||
failed_to_restart: 0
|
||||
out_of_sync: 0
|
||||
restarted: 0
|
||||
scheduled: 0
|
||||
skipped: 0
|
||||
total: 109
|
||||
changes:
|
||||
total: 0
|
||||
time:
|
||||
anchor: 0.000555
|
||||
catalog_application: 0.010555
|
||||
config_retrieval: 4.75567007064819
|
||||
convert_catalog: 1.3
|
||||
cron: 0.000584
|
||||
exec: 0.508123
|
||||
fact_generation: 0.34
|
||||
file: 0.441472
|
||||
filebucket: 0.000353
|
||||
last_run: 1444936531
|
||||
node_retrieval: 1.235
|
||||
notify: 0.00035
|
||||
package: 1.325788
|
||||
plugin_sync: 0.325788
|
||||
schedule: 0.001123
|
||||
service: 1.807795
|
||||
ssh_authorized_key: 0.000764
|
||||
total: 8.85354707064819
|
||||
transaction_evaluation: 4.69765
|
||||
user: 0.004331
|
||||
yumrepo: 0.006989
|
||||
version:
|
||||
config: "environment:d6018ce"
|
||||
puppet: "3.7.5"
|
139
plugins/inputs/puppetagent/puppetagent.go
Normal file
139
plugins/inputs/puppetagent/puppetagent.go
Normal file
|
@ -0,0 +1,139 @@
|
|||
//go:generate ../../../tools/readme_config_includer/generator
|
||||
package puppetagent
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
type PuppetAgent struct {
|
||||
Location string `toml:"location"`
|
||||
}
|
||||
|
||||
type state struct {
|
||||
Events event
|
||||
Resources resource
|
||||
Changes change
|
||||
Time time
|
||||
Version version
|
||||
}
|
||||
|
||||
type event struct {
|
||||
Failure int64 `yaml:"failure"`
|
||||
Noop int64 `yaml:"noop"`
|
||||
Total int64 `yaml:"total"`
|
||||
Success int64 `yaml:"success"`
|
||||
}
|
||||
|
||||
type resource struct {
|
||||
Changed int64 `yaml:"changed"`
|
||||
CorrectiveChange int64 `yaml:"corrective_change"`
|
||||
Failed int64 `yaml:"failed"`
|
||||
FailedToRestart int64 `yaml:"failed_to_restart"`
|
||||
OutOfSync int64 `yaml:"out_of_sync"`
|
||||
Restarted int64 `yaml:"restarted"`
|
||||
Scheduled int64 `yaml:"scheduled"`
|
||||
Skipped int64 `yaml:"skipped"`
|
||||
Total int64 `yaml:"total"`
|
||||
}
|
||||
|
||||
type change struct {
|
||||
Total int64 `yaml:"total"`
|
||||
}
|
||||
|
||||
type time struct {
|
||||
Anchor float64 `yaml:"anchor"`
|
||||
CataLogApplication float64 `yaml:"catalog_application"`
|
||||
ConfigRetrieval float64 `yaml:"config_retrieval"`
|
||||
ConvertCatalog float64 `yaml:"convert_catalog"`
|
||||
Cron float64 `yaml:"cron"`
|
||||
Exec float64 `yaml:"exec"`
|
||||
FactGeneration float64 `yaml:"fact_generation"`
|
||||
File float64 `yaml:"file"`
|
||||
FileBucket float64 `yaml:"filebucket"`
|
||||
Group float64 `yaml:"group"`
|
||||
LastRun int64 `yaml:"last_run"`
|
||||
NodeRetrieval float64 `yaml:"node_retrieval"`
|
||||
Notify float64 `yaml:"notify"`
|
||||
Package float64 `yaml:"package"`
|
||||
PluginSync float64 `yaml:"plugin_sync"`
|
||||
Schedule float64 `yaml:"schedule"`
|
||||
Service float64 `yaml:"service"`
|
||||
SSHAuthorizedKey float64 `yaml:"ssh_authorized_key"`
|
||||
Total float64 `yaml:"total"`
|
||||
TransactionEvaluation float64 `yaml:"transaction_evaluation"`
|
||||
User float64 `yaml:"user"`
|
||||
}
|
||||
|
||||
type version struct {
|
||||
ConfigString string `yaml:"config"`
|
||||
Puppet string `yaml:"puppet"`
|
||||
}
|
||||
|
||||
func (*PuppetAgent) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (pa *PuppetAgent) Gather(acc telegraf.Accumulator) error {
|
||||
if len(pa.Location) == 0 {
|
||||
pa.Location = "/var/lib/puppet/state/last_run_summary.yaml"
|
||||
}
|
||||
|
||||
if _, err := os.Stat(pa.Location); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fh, err := os.ReadFile(pa.Location)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var puppetState state
|
||||
|
||||
err = yaml.Unmarshal(fh, &puppetState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tags := map[string]string{"location": pa.Location}
|
||||
structPrinter(&puppetState, acc, tags)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func structPrinter(s *state, acc telegraf.Accumulator, tags map[string]string) {
|
||||
e := reflect.ValueOf(s).Elem()
|
||||
|
||||
fields := make(map[string]interface{})
|
||||
for tLevelFNum := 0; tLevelFNum < e.NumField(); tLevelFNum++ {
|
||||
name := e.Type().Field(tLevelFNum).Name
|
||||
nameNumField := e.FieldByName(name).NumField()
|
||||
|
||||
for sLevelFNum := 0; sLevelFNum < nameNumField; sLevelFNum++ {
|
||||
sName := e.FieldByName(name).Type().Field(sLevelFNum).Name
|
||||
sValue := e.FieldByName(name).Field(sLevelFNum).Interface()
|
||||
|
||||
lname := strings.ToLower(name)
|
||||
lsName := strings.ToLower(sName)
|
||||
fields[fmt.Sprintf("%s_%s", lname, lsName)] = sValue
|
||||
}
|
||||
}
|
||||
acc.AddFields("puppetagent", fields, tags)
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("puppetagent", func() telegraf.Input {
|
||||
return &PuppetAgent{}
|
||||
})
|
||||
}
|
61
plugins/inputs/puppetagent/puppetagent_test.go
Normal file
61
plugins/inputs/puppetagent/puppetagent_test.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package puppetagent
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
func TestGather(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
|
||||
pa := PuppetAgent{
|
||||
Location: "last_run_summary.yaml",
|
||||
}
|
||||
require.NoError(t, pa.Gather(&acc))
|
||||
|
||||
tags := map[string]string{"location": "last_run_summary.yaml"}
|
||||
fields := map[string]interface{}{
|
||||
"events_failure": int64(0),
|
||||
"events_noop": int64(0),
|
||||
"events_success": int64(0),
|
||||
"events_total": int64(0),
|
||||
"resources_changed": int64(0),
|
||||
"resources_correctivechange": int64(0),
|
||||
"resources_failed": int64(0),
|
||||
"resources_failedtorestart": int64(0),
|
||||
"resources_outofsync": int64(0),
|
||||
"resources_restarted": int64(0),
|
||||
"resources_scheduled": int64(0),
|
||||
"resources_skipped": int64(0),
|
||||
"resources_total": int64(109),
|
||||
"changes_total": int64(0),
|
||||
"time_anchor": float64(0.000555),
|
||||
"time_catalogapplication": float64(0.010555),
|
||||
"time_configretrieval": float64(4.75567007064819),
|
||||
"time_convertcatalog": float64(1.3),
|
||||
"time_cron": float64(0.000584),
|
||||
"time_exec": float64(0.508123),
|
||||
"time_factgeneration": float64(0.34),
|
||||
"time_file": float64(0.441472),
|
||||
"time_filebucket": float64(0.000353),
|
||||
"time_group": float64(0),
|
||||
"time_lastrun": int64(1444936531),
|
||||
"time_noderetrieval": float64(1.235),
|
||||
"time_notify": float64(0.00035),
|
||||
"time_package": float64(1.325788),
|
||||
"time_pluginsync": float64(0.325788),
|
||||
"time_schedule": float64(0.001123),
|
||||
"time_service": float64(1.807795),
|
||||
"time_sshauthorizedkey": float64(0.000764),
|
||||
"time_total": float64(8.85354707064819),
|
||||
"time_transactionevaluation": float64(4.69765),
|
||||
"time_user": float64(0.004331),
|
||||
"version_configstring": "environment:d6018ce",
|
||||
"version_puppet": "3.7.5",
|
||||
}
|
||||
|
||||
acc.AssertContainsTaggedFields(t, "puppetagent", fields, tags)
|
||||
}
|
4
plugins/inputs/puppetagent/sample.conf
Normal file
4
plugins/inputs/puppetagent/sample.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Reads last_run_summary.yaml file and converts to measurements
|
||||
[[inputs.puppetagent]]
|
||||
## Location of puppet last run summary file
|
||||
location = "/var/lib/puppet/state/last_run_summary.yaml"
|
Loading…
Add table
Add a link
Reference in a new issue