renaming plugins -> inputs
This commit is contained in:
132
plugins/inputs/puppetagent/README.md
Normal file
132
plugins/inputs/puppetagent/README.md
Normal file
@@ -0,0 +1,132 @@
|
||||
## Telegraf Plugin: PuppetAgent
|
||||
|
||||
#### Description
|
||||
|
||||
The puppetagent plugin collects variables outputted from the 'last_run_summary.yaml' file
|
||||
usually located in `/var/lib/puppet/state/`
|
||||
[PuppetAgent Runs](https://puppetlabs.com/blog/puppet-monitoring-how-to-monitor-the-success-or-failure-of-puppet-runs).
|
||||
|
||||
```
|
||||
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"
|
||||
```
|
||||
|
||||
```
|
||||
jcross@pit-devops-02 ~ >sudo ./telegraf_linux_amd64 -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
|
||||
```
|
||||
|
||||
## Measurements:
|
||||
#### PuppetAgent int64 measurements:
|
||||
|
||||
Meta:
|
||||
- units: int64
|
||||
- tags: ``
|
||||
|
||||
Measurement names:
|
||||
- puppetagent_events_failure
|
||||
- puppetagent_events_total
|
||||
- puppetagent_events_success
|
||||
- puppetagent_resources_failed
|
||||
- puppetagent_resources_scheduled
|
||||
- puppetagent_resources_changed
|
||||
- puppetagent_resources_skipped
|
||||
- puppetagent_resources_total
|
||||
- puppetagent_resources_failedtorestart
|
||||
- puppetagent_resources_restarted
|
||||
- puppetagent_resources_outofsync
|
||||
- puppetagent_changes_total
|
||||
- puppetagent_time_service
|
||||
- puppetagent_time_lastrun
|
||||
- puppetagent_version_config
|
||||
|
||||
#### PuppetAgent float64 measurements:
|
||||
|
||||
Meta:
|
||||
- units: float64
|
||||
- tags: ``
|
||||
|
||||
Measurement names:
|
||||
- puppetagent_time_user
|
||||
- puppetagent_time_schedule
|
||||
- puppetagent_time_filebucket
|
||||
- puppetagent_time_file
|
||||
- puppetagent_time_exec
|
||||
- puppetagent_time_anchor
|
||||
- puppetagent_time_sshauthorizedkey
|
||||
- puppetagent_time_package
|
||||
- puppetagent_time_total
|
||||
- puppetagent_time_configretrieval
|
||||
- puppetagent_time_lastrun
|
||||
- puppetagent_time_cron
|
||||
- puppetagent_version_config
|
||||
|
||||
#### PuppetAgent string measurements:
|
||||
|
||||
Meta:
|
||||
- units: string
|
||||
- tags: ``
|
||||
|
||||
Measurement names:
|
||||
- puppetagent_version_puppet
|
||||
34
plugins/inputs/puppetagent/last_run_summary.yaml
Normal file
34
plugins/inputs/puppetagent/last_run_summary.yaml
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
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"
|
||||
137
plugins/inputs/puppetagent/puppetagent.go
Normal file
137
plugins/inputs/puppetagent/puppetagent.go
Normal file
@@ -0,0 +1,137 @@
|
||||
package puppetagent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/influxdb/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
// PuppetAgent is a PuppetAgent plugin
|
||||
type PuppetAgent struct {
|
||||
Location string
|
||||
}
|
||||
|
||||
var sampleConfig = `
|
||||
# Location of puppet last run summary file
|
||||
location = "/var/lib/puppet/state/last_run_summary.yaml"
|
||||
`
|
||||
|
||||
type State struct {
|
||||
Events event
|
||||
Resources resource
|
||||
Changes change
|
||||
Time time
|
||||
Version version
|
||||
}
|
||||
|
||||
type event struct {
|
||||
Failure int64 `yaml:"failure"`
|
||||
Total int64 `yaml:"total"`
|
||||
Success int64 `yaml:"success"`
|
||||
}
|
||||
|
||||
type resource struct {
|
||||
Failed int64 `yaml:"failed"`
|
||||
Scheduled int64 `yaml:"scheduled"`
|
||||
Changed int64 `yaml:"changed"`
|
||||
Skipped int64 `yaml:"skipped"`
|
||||
Total int64 `yaml:"total"`
|
||||
FailedToRestart int64 `yaml:"failed_to_restart"`
|
||||
Restarted int64 `yaml:"restarted"`
|
||||
OutOfSync int64 `yaml:"out_of_sync"`
|
||||
}
|
||||
|
||||
type change struct {
|
||||
Total int64 `yaml:"total"`
|
||||
}
|
||||
|
||||
type time struct {
|
||||
User float64 `yaml:"user"`
|
||||
Schedule float64 `yaml:"schedule"`
|
||||
FileBucket float64 `yaml:"filebucket"`
|
||||
File float64 `yaml:"file"`
|
||||
Exec float64 `yaml:"exec"`
|
||||
Anchor float64 `yaml:"anchor"`
|
||||
SSHAuthorizedKey float64 `yaml:"ssh_authorized_key"`
|
||||
Service float64 `yaml:"service"`
|
||||
Package float64 `yaml:"package"`
|
||||
Total float64 `yaml:"total"`
|
||||
ConfigRetrieval float64 `yaml:"config_retrieval"`
|
||||
LastRun int64 `yaml:"last_run"`
|
||||
Cron float64 `yaml:"cron"`
|
||||
}
|
||||
|
||||
type version struct {
|
||||
Config int64 `yaml:"config"`
|
||||
Puppet string `yaml:"puppet"`
|
||||
}
|
||||
|
||||
// SampleConfig returns sample configuration message
|
||||
func (pa *PuppetAgent) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
// Description returns description of PuppetAgent plugin
|
||||
func (pa *PuppetAgent) Description() string {
|
||||
return `Reads last_run_summary.yaml file and converts to measurments`
|
||||
}
|
||||
|
||||
// Gather reads stats from all configured servers accumulates stats
|
||||
func (pa *PuppetAgent) Gather(acc inputs.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 fmt.Errorf("%s", err)
|
||||
}
|
||||
|
||||
fh, err := ioutil.ReadFile(pa.Location)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s", err)
|
||||
}
|
||||
|
||||
var puppetState State
|
||||
|
||||
err = yaml.Unmarshal(fh, &puppetState)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s", err)
|
||||
}
|
||||
|
||||
tags := map[string]string{"location": pa.Location}
|
||||
structPrinter(&puppetState, acc, tags)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func structPrinter(s *State, acc inputs.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() inputs.Input {
|
||||
return &PuppetAgent{}
|
||||
})
|
||||
}
|
||||
48
plugins/inputs/puppetagent/puppetagent_test.go
Normal file
48
plugins/inputs/puppetagent/puppetagent_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package puppetagent
|
||||
|
||||
import (
|
||||
"github.com/influxdb/telegraf/testutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGather(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
|
||||
pa := PuppetAgent{
|
||||
Location: "last_run_summary.yaml",
|
||||
}
|
||||
pa.Gather(&acc)
|
||||
|
||||
tags := map[string]string{"location": "last_run_summary.yaml"}
|
||||
fields := map[string]interface{}{
|
||||
"events_failure": int64(0),
|
||||
"events_total": int64(0),
|
||||
"events_success": int64(0),
|
||||
"resources_failed": int64(0),
|
||||
"resources_scheduled": int64(0),
|
||||
"resources_changed": int64(0),
|
||||
"resources_skipped": int64(0),
|
||||
"resources_total": int64(109),
|
||||
"resources_failedtorestart": int64(0),
|
||||
"resources_restarted": int64(0),
|
||||
"resources_outofsync": int64(0),
|
||||
"changes_total": int64(0),
|
||||
"time_lastrun": int64(1444936531),
|
||||
"version_config": int64(1444936521),
|
||||
"time_user": float64(0.004331),
|
||||
"time_schedule": float64(0.001123),
|
||||
"time_filebucket": float64(0.000353),
|
||||
"time_file": float64(0.441472),
|
||||
"time_exec": float64(0.508123),
|
||||
"time_anchor": float64(0.000555),
|
||||
"time_sshauthorizedkey": float64(0.000764),
|
||||
"time_service": float64(1.807795),
|
||||
"time_package": float64(1.325788),
|
||||
"time_total": float64(8.85354707064819),
|
||||
"time_configretrieval": float64(4.75567007064819),
|
||||
"time_cron": float64(0.000584),
|
||||
"version_puppet": "3.7.5",
|
||||
}
|
||||
|
||||
acc.AssertContainsTaggedFields(t, "puppetagent", fields, tags)
|
||||
}
|
||||
Reference in New Issue
Block a user