-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to v1.14.0 to fix Netprobe downloads plus other changes/fixes
- Loading branch information
1 parent
4fa3fd0
commit 69f8f41
Showing
23 changed files
with
651 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.14.0-dev | ||
v1.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Binary file not shown.
Oops, something went wrong.