Skip to content

Commit

Permalink
update to v1.14.0 to fix Netprobe downloads plus other changes/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgalbavy-itrs committed Jun 5, 2024
1 parent 4fa3fd0 commit 69f8f41
Show file tree
Hide file tree
Showing 23 changed files with 651 additions and 53 deletions.
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
# Change Log

## Version v1.14.0

> **Released 2024-06-05**
>
> Please report issues via [github](https://github.com/ITRS-Group/cordial/issues) or the [ITRS Community Forum](https://community.itrsgroup.com/).
⚠️ You will need to update to this version if you use `geneos` to install Netprobe releases direct from the ITRS website as the base name of the redirect URL has changed and the old version no longer works.

### v1.14.0 Changes

* Update Go toolchain to use 1.22.4

* `tools/geneos`

* Add options to `tls create` to specify destination directory, outputting certificate bundles and setting the expiry period in days. Also, do not initialise the TLS subsystem if it's not found unless the `--force` flag is used.

* Hide `--name` option in `deploy`, repurpose short-form `-n` for new `--nosave` option

* Rename `logs` option `--nostandard` to `--no-stdout` (with alias) for consistency

* `cordial` package

* Only log file and function if logging at `Debug` level or greater

* Split logging methods into their own file, add options to `LogInit()` to specify filename and/or [`lunberjack`](https://pkg.go.dev/gopkg.in/natefinch/lumberjack.v2) settings. Log filenames can also include `~/` prefix for home directory.

* `tools/gateway-reporter`

* Add an optional XLSX password in `output` config section

### v1.14.0 Fixes

* `tools/geneos`

* Fix download base name for Netprobes to new value.

* Fix `deploy` importing of keyfiles (only import if given on command line)

* `package install` and `package update` - Fix the handling of package metadata (e.g. `+el8`) suffixes to that they are treated the same as a package without a metadata suffix - and the right one is selected for the system being installed

* `pkg/config`

* Better recovery on failing to find the user's config directory, return an error instead of panic-ing

---

## Version v1.13.2

> **Released 2024-05-23**
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dockerfile to build cordial components and tar.gz files

ARG GOVERSION=1.22.3
ARG GOVERSION=1.22.4

# The bullseye image seems to offer the most compatibility, including
# libemail.so dependencies
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

Cordial is a collection of utilities, integrations and support packages for ITRS Geneos.

> **Current Version v1.13.1**
> **Current Version v1.14.0**
> Released 2024-05-22
⚠️ You will need to update to this version if you use `geneos` to install Netprobe releases direct from the ITRS website as the base name of the redirect URL has changed and the old version no longer works.

> Released 2024-06-05
>
> See [`CHANGELOG.md`](CHANGELOG.md) for more details.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.14.0-dev
v1.14.0
34 changes: 34 additions & 0 deletions examples/api2/cpu/cpu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cpu

import (
"time"

"github.com/itrs-group/cordial/pkg/geneos/api"
)

type CPUPlugin struct {
api.Plugin
cpustats cpustat
}

var _ api.Sampler = (*CPUPlugin)(nil)

func init() {
cpuPlugin := &CPUPlugin{}
api.RegisterPlugin("cpu", cpuPlugin)
}

func (c *CPUPlugin) Open() error { return nil }

func (c *CPUPlugin) Interval() time.Duration {
return c.Plugin.Interval
}

func (c *CPUPlugin) SetInterval(i time.Duration) {
c.Plugin.Interval = i
}

func (c *CPUPlugin) Start() error { return nil }
func (c *CPUPlugin) Stop() error { return nil }
func (c *CPUPlugin) Close() error { return nil }
func (c *CPUPlugin) Pause() error { return nil }
87 changes: 87 additions & 0 deletions examples/api2/cpu/cpu_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//go:build linux

package cpu

import (
"bufio"
"fmt"
"os"
"strings"
"time"
)

// cpustats must be exported, along with all it's fields, so that
// it can be output by methods in the plugins package.
type cpustats struct {
Name string `column:"cpuName,sort=+num"`
Utilisation uint64 `column:"% utilisation,format=%.2f %%"`
User uint64 `column:"user,format=%.2f %%"`
Nice uint64 `column:"nice,format=%.2f %%"`
System uint64 `column:"system,format=%.2f %%"`
Idle uint64 `column:"idle,format=%.2f %%"`
IOWait uint64 `column:"iowait,format=%.2f %%"`
IRQ uint64 `column:"irq,format=%.2f %%"`
SoftIRQ uint64 `column:"softirq,format=%.2f %%"`
Steal uint64 `column:"steal,format=%.2f %%"`
Guest uint64 `column:"guest,format=%.2f %%"`
GuestNice uint64 `column:"guest_nice,format=%.2f %%"`
}

// one entry for each CPU row in /proc/stats
type cpustat struct {
lastsample time.Time
cpus map[string]cpustats
}

// SampleNow is the entry point for the example CPU sampler
func (p *CPUPlugin) SampleNow() (err error) {
// first time through, store initial stats, don't update table and wait for next call
var stat cpustat
laststats := p.cpustats
if laststats.lastsample.IsZero() {
// first time through, store initial stats, don't update table and wait for next call
var stat cpustat
err = parsestats(&stat)
if err != nil {
return
}
p.cpustats = stat
} else {
err = parsestats(&stat)
if err != nil {
return
}
p.cpustats = stat

// interval := stat.lastsample.Sub(laststats.lastsample)
// err = d.UpdateTableFromMapDelta(stat.cpus, laststats.cpus, interval)
p.cpustats = stat
}
return nil
}

func parsestats(c *cpustat) (err error) {
stats, err := os.Open("/proc/stat")
if err != nil {
return
}
c.lastsample = time.Now()
c.cpus = make(map[string]cpustats)
defer stats.Close()

lines := bufio.NewScanner(stats)
for lines.Scan() {
line := lines.Text()
if strings.HasPrefix(line, "cpu") {
var cpu cpustats
// line = strings.ReplaceAll(line, " ", " ")
fmt.Sscanln(line, cpu.Name, cpu.User, cpu.Nice, cpu.System, cpu.Idle, cpu.IOWait, cpu.IRQ, cpu.SoftIRQ, cpu.Steal, cpu.Guest, cpu.GuestNice)
if cpu.Name == "cpu" {
cpu.Name = "_Total"
}
cpu.Utilisation = cpu.User + cpu.Nice + cpu.System + cpu.IRQ + cpu.SoftIRQ + cpu.Steal + cpu.Guest + cpu.GuestNice
c.cpus[cpu.Name] = cpu
}
}
return
}
84 changes: 84 additions & 0 deletions examples/api2/cpu/cpu_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//go:build windows

package cpu

import (
"time"

"github.com/rs/zerolog/log"

"github.com/StackExchange/wmi"
"github.com/itrs-group/cordial/pkg/samplers"
)

// Win32_PerfRawData_PerfOS_Processor must be exported along with all it's
// fields so that methods in plugins package can output the results
type Win32_PerfRawData_PerfOS_Processor struct {
Name string `column:"cpuName"`
PercentUserTime uint64 `column:"% User Time,format=%.2f %%"`
PercentPrivilegedTime uint64 `column:"% Priv Time,format=%.2f %%"`
PercentIdleTime uint64 `column:"% Idle Time,format=%.2f %%"`
PercentProcessorTime uint64 `column:"% Proc Time,format=%.2f %%"`
PercentInterruptTime uint64 `column:"% Intr Time,format=%.2f %%"`
PercentDPCTime uint64 `column:"% DPC Time,format=%.2f %%"`
Timestamp_PerfTime uint64 `column:"-"`
Frequency_PerfTime uint64 `column:"-"`
}

// one entry for each CPU row in /proc/stats
type cpustat struct {
cpus map[string]Win32_PerfRawData_PerfOS_Processor
lastsample float64
frequency float64
}

func (p *CPUSampler) DoSample() (err error) {
log.Debug().Msg("called")
laststats := p.cpustats
if laststats.lastsample == 0 {
// first time through, store initial stats, don't update table and wait for next call
var stat cpustat
err = getstats(&stat)
if err != nil {
return
}
p.cpustats = stat
} else {
// calculate diff and publish
var stat cpustat

err = getstats(&stat)
if err != nil {
return
}
interval := stat.lastsample - laststats.lastsample

err = p.UpdateTableFromMapDelta(stat.cpus, laststats.cpus, time.Duration(interval)*10*time.Millisecond)
p.cpustats = stat
}

return
}

func getstats(c *cpustat) (err error) {
c.cpus = make(map[string]Win32_PerfRawData_PerfOS_Processor)

var dst []Win32_PerfRawData_PerfOS_Processor
q := wmi.CreateQuery(&dst, "")
err = wmi.Query(q, &dst)
if err != nil {
log.Fatal().Err(err).Msg("")
}

c.lastsample = float64(dst[0].Timestamp_PerfTime)
c.frequency = float64(dst[0].Frequency_PerfTime)

for k, v := range dst {
c.cpus[v.Name] = Win32_PerfRawData_PerfOS_Processor(dst[k])
}
return
}

func (p CPUSampler) initColumns() (cols samplers.Columns, columnnames []string, sortcol string, err error) {
return p.ColumnInfo(Win32_PerfRawData_PerfOS_Processor{})
}
51 changes: 51 additions & 0 deletions examples/api2/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"flag"
"fmt"
"net/url"
"time"

"github.com/rs/zerolog/log"

"github.com/itrs-group/cordial/pkg/geneos/api"
)

func main() {
// var wg sync.WaitGroup
var interval time.Duration
var (
hostname string
port uint
entityname, samplername string
)

flag.StringVar(&hostname, "h", "localhost", "Netprobe hostname")
flag.UintVar(&port, "p", 7036, "Netprobe port number")
flag.DurationVar(&interval, "t", 1*time.Second, "Global DoSample Interval in seconds (min 1)")
flag.StringVar(&entityname, "e", "", "Default entity to connect")
flag.StringVar(&samplername, "s", "", "Default sampler to connect")
flag.Parse()

if interval < 1*time.Second {
log.Fatal().Msgf("supplied sample interval (%v) too short, minimum 1 second", interval)
}

// connect to netprobe
// url := fmt.Sprintf("https://%s:%v/xmlrpc", hostname, port)
u := &url.URL{Scheme: "https", Host: fmt.Sprintf("%s:%d", hostname, port), Path: "/xmlrpc"}

p, err := api.NewXMLRPCClient(u.String(), api.InsecureSkipVerify())
if err != nil {
log.Fatal().Err(err).Msg("")
}

s := api.NewSampler(p, "cpu", entityname, samplername)

defer s.Close()
s.SetInterval(interval)
if err = s.Start(); err != nil {
log.Fatal().Err(err).Msg("")
}
select {} // and wait
}
Empty file added examples/cliauth/LICENSE
Empty file.
Binary file added examples/cliauth/cliauth
Binary file not shown.
Loading

0 comments on commit 69f8f41

Please sign in to comment.