Skip to content

Commit

Permalink
code: CHANGING migration from telegraf.shim to lightmetric.shim and c…
Browse files Browse the repository at this point in the history
…onfig format change
  • Loading branch information
tbelda-ems committed Jun 26, 2023
1 parent 42d34f1 commit e0a79ba
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 792 deletions.
2 changes: 1 addition & 1 deletion METRICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@
- ovirt-engine
- fields:
- sessions_created (int)
- gather_time_ns (int)
- gather_time_ns (int)
85 changes: 42 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,46 @@ Latest releases are built with a go-ovirt library version that should work with
* Edit ovirtstat.conf file as needed. Example:

```toml
[[inputs.ovirtstat]]
## OVirt Engine URL to be monitored and its credential
ovirturl = "https://ovirt-engine.local/ovirt-engine/api"
username = "user@internal"
password = "secret"
timeout = "10s"

## Optional SSL Config
# tls_ca = "/path/to/cafile"
## Use SSL but skip chain & host verification
# insecure_skip_verify = false

## optional alias tag for internal metrics
# internal_alias = ""

## Filter clusters by name, default is no filtering
## cluster names can be specified as glob patterns
# clusters_include = []
# clusters_exclude = []

## Filter hosts by name, default is no filtering
## host names can be specified as glob patterns
# hosts_include = []
# hosts_exclude = []

## Filter VMs by name, default is no filtering
## VM names can be specified as glob patterns
# vms_include = []
# vms_exclude = []

## Filter collectors by name, default is all collectors
## see possible collector names bellow
# collectors_include = []
# collectors_exclude = []

#### collector names available are (details in METRICS.md) ####
## Datacenters: datacenter stats in ovirtstat_datacenter measurement
## GlusterVolumes: gluster volume stats in ovirtstat_glustervolume measurement
## Hosts: hypervisor/host stats in ovirtstat_host measurement
## StorageDomains: cluster stats in ovirtstat_storagedomains measurement
## VMs: virtual machine stats in ovirtstat_vm measurement
## OVirt Engine URL to be monitored and its credential
ovirturl = "https://ovirt-engine.local/ovirt-engine/api"
username = "user@internal"
password = "secret"
timeout = "10s"

## Optional SSL Config
# tls_ca = "/path/to/cafile"
## Use SSL but skip chain & host verification
# insecure_skip_verify = false

## optional alias tag for internal metrics
# internal_alias = ""

## Filter clusters by name, default is no filtering
## cluster names can be specified as glob patterns
# clusters_include = []
# clusters_exclude = []

## Filter hosts by name, default is no filtering
## host names can be specified as glob patterns
# hosts_include = []
# hosts_exclude = []

## Filter VMs by name, default is no filtering
## VM names can be specified as glob patterns
# vms_include = []
# vms_exclude = []

## Filter collectors by name, default is all collectors
## see possible collector names bellow
# collectors_include = []
# collectors_exclude = []

#### collector names available are (details in METRICS.md) ####
## Datacenters: datacenter stats in ovirtstat_datacenter measurement
## GlusterVolumes: gluster volume stats in ovirtstat_glustervolume measurement
## Hosts: hypervisor/host stats in ovirtstat_host measurement
## StorageDomains: cluster stats in ovirtstat_storagedomains measurement
## VMs: virtual machine stats in ovirtstat_vm measurement
```

* Edit telegraf's execd input configuration as needed. Example:
Expand All @@ -66,7 +65,7 @@ Latest releases are built with a go-ovirt library version that should work with
## Gather oVirt Engine status and basic stats
[[inputs.execd]]
command = ["/path/to/ovirtstat_binary", "--config", "/path/to/ovirtstat.conf"]
signal = "none"
signal = "STDIN"
```

You can optionally tell ovirtstat the input's interval by adding --poll_interval <the_interval> parameters to the command. By default it expects 1m interval. If you want 30s interval configure it like this:
Expand All @@ -75,7 +74,7 @@ You can optionally tell ovirtstat the input's interval by adding --poll_interval
[[inputs.execd]]
interval = "30s"
command = ["/path/to/ovirtstat_binary", "--config", "/path/to/ovirtstat.conf", "--poll_interval", "30s"]
signal = "none"
signal = "STDIN"
```
Metric timestamp precision will be set according to the polling interval, so it will usually be 1s.

Expand Down
56 changes: 28 additions & 28 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"os"
"time"

"github.com/influxdata/telegraf/plugins/common/shim"
"github.com/tesibelda/lightmetric/shim"

"github.com/tesibelda/ovirtstat/plugins/inputs/ovirtstat"
)

const pluginName = "ovirtstat"

// Version cotains the actual version of ovirtstat
var Version string

Expand All @@ -25,7 +27,7 @@ func main() {
pollInterval = flag.Duration(
"poll_interval",
60*time.Second,
"how often to send metrics (default 1m)",
"how often to send metrics",
)
configFile = flag.String("config", "", "path to the config file for this plugin")
showVersion = flag.Bool("version", false, "show ovirtstat version and exit")
Expand All @@ -35,40 +37,38 @@ func main() {
// parse command line options
flag.Parse()
if *showVersion {
fmt.Println("ovirtstat", Version)
fmt.Println(pluginName, Version)
os.Exit(0)
}
oV := ovirtstat.New()

// create the shim. This is what will run your plugins.
shim := shim.New()
if shim == nil {
fmt.Fprintf(os.Stderr, "Error creating telegraf shim\n")
os.Exit(1)
// load config an wait for stdin signal from telegraf to gather data
if *configFile != "" {
if err = oV.LoadConfig(*configFile); err != nil {
fmt.Fprintf(os.Stderr, "Error loading configuration: %s\n", err)
os.Exit(1)
}
}

// If no config is specified, all imported plugins are loaded.
// otherwise follow what the config asks for.
// Check for settings from a config toml file,
// (or just use whatever plugins were imported above)
if err = shim.LoadConfig(configFile); err != nil {
fmt.Fprintf(os.Stderr, "Error loading configuration: %s\n", err)
os.Exit(1)
if *pollInterval != 0 {
if err = oV.SetPollInterval(*pollInterval); err != nil {
fmt.Fprintf(os.Stderr, "Error setting poll interval: %s\n", err)
os.Exit(1)
}
}

// Tell ovirtstat shim the configured polling interval
vcCfg, ok := shim.Input.(*ovirtstat.Config)
if !ok {
fmt.Fprintf(os.Stderr, "Error getting shim input as ovirtstat Config\n")
os.Exit(1)
}
if err = vcCfg.SetPollInterval(*pollInterval); err != nil {
fmt.Fprintf(os.Stderr, "Error setting ovirtstat shim polling interval: %s\n", err)
os.Exit(1)
if oV.Timeout > *pollInterval {
fmt.Fprintf(
os.Stderr,
"Timeout cannot be greater than poll_interval so using %s\n",
*pollInterval,
)
oV.Timeout = *pollInterval
}

// run a single plugin until stdin closes or we receive a termination signal
if err = shim.Run(*pollInterval); err != nil {
fmt.Fprintf(os.Stderr, "Error running telegraf shim: %s\n", err)
execd := shim.New(pluginName).WithPrecision(time.Second)
if err = execd.RunInput(oV.Gather); err != nil {
fmt.Fprintf(os.Stderr, "Error running oVirt Engine collector: %s\n", err)
os.Exit(2)
}
oV.Stop()
}
69 changes: 34 additions & 35 deletions etc/ovirtstat.conf
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
## Gather oVirt Engine status and basic stats
[[inputs.ovirtstat]]
## OVirt URL to be monitored and its credential
ovirturl = "https://ovirt-engine.local/ovirt-engine/api"
username = "user@internal"
password = "secret"
timeout = "10s"
######### Gather oVirt Engine status and basic stats #########
## OVirt URL to be monitored and its credential
ovirturl = "https://ovirt-engine.local/ovirt-engine/api"
username = "user@internal"
password = "secret"
timeout = "10s"

## Optional SSL Config
# tls_ca = "/path/to/cafile"
## Use SSL but skip chain & host verification
# insecure_skip_verify = false
## Optional SSL Config
# tls_ca = "/path/to/cafile"
## Use SSL but skip chain & host verification
# insecure_skip_verify = false

## optional alias tag for internal metrics
# internal_alias = ""
## optional alias tag for internal metrics
# internal_alias = ""

## Filter clusters by name, default is no filtering
## cluster names can be specified as glob patterns
# clusters_include = []
# clusters_exclude = []
## Filter clusters by name, default is no filtering
## cluster names can be specified as glob patterns
# clusters_include = []
# clusters_exclude = []

## Filter hosts by name, default is no filtering
## host names can be specified as glob patterns
# hosts_include = []
# hosts_exclude = []
## Filter hosts by name, default is no filtering
## host names can be specified as glob patterns
# hosts_include = []
# hosts_exclude = []

## Filter VMs by name, default is no filtering
## VM names can be specified as glob patterns
# vms_include = []
# vms_exclude = []
## Filter VMs by name, default is no filtering
## VM names can be specified as glob patterns
# vms_include = []
# vms_exclude = []

## Filter collectors by name, default is all collectors
## see possible collector names bellow
# collectors_include = []
# collectors_exclude = []
## Filter collectors by name, default is all collectors
## see possible collector names bellow
# collectors_include = []
# collectors_exclude = []

#### collector names available are (details in METRICS.md) ####
## Datacenters: datacenter stats in ovirtstat_datacenter measurement
## GlusterVolumes: gluster volume stats in ovirtstat_glustervolume measurement
## Hosts: hypervisor/host stats in ovirtstat_host measurement
## StorageDomains: cluster stats in ovirtstat_storagedomains measurement
## VMs: virtual machine stats in ovirtstat_vm measurement
#### collector names available are (details in METRICS.md) ####
## Datacenters: datacenter stats in ovirtstat_datacenter measurement
## GlusterVolumes: gluster volume stats in ovirtstat_glustervolume measurement
## Hosts: hypervisor/host stats in ovirtstat_host measurement
## StorageDomains: cluster stats in ovirtstat_storagedomains measurement
## VMs: virtual machine stats in ovirtstat_vm measurement
31 changes: 4 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,14 @@ module github.com/tesibelda/ovirtstat
go 1.19

require (
github.com/BurntSushi/toml v1.2.1
github.com/influxdata/telegraf v1.26.3
github.com/ovirt/go-ovirt v0.0.0-20220427092237-114c47f2835c
github.com/tesibelda/lightmetric/metric v0.0.0-20230611113744-7ad03904a8bd
github.com/tesibelda/lightmetric/shim v0.0.0-20230611113744-7ad03904a8bd
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/alecthomas/participle v0.4.1 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/awnumar/memcall v0.1.2 // indirect
github.com/awnumar/memguard v0.22.3 // indirect
github.com/benbjohnson/clock v1.3.3 // indirect
github.com/blues/jsonata-go v1.5.4 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gosnmp/gosnmp v1.35.0 // indirect
github.com/influxdata/toml v0.0.0-20190415235208-270119a8ce65 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/prometheus v0.42.0 // indirect
github.com/sleepinggenius2/gosmi v0.4.4 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/sys v0.8.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
github.com/influxdata/line-protocol/v2 v2.2.1 // indirect
)
Loading

0 comments on commit e0a79ba

Please sign in to comment.