mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
Add example for collector
This commit is contained in:
parent
1815825206
commit
e0b9c9e8b2
64
collectors/likwid.go
Normal file
64
collectors/likwid.go
Normal file
@ -0,0 +1,64 @@
|
||||
package collectors
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
protocol "github.com/influxdata/line-protocol"
|
||||
)
|
||||
|
||||
type LikwidCollector struct {
|
||||
name string
|
||||
tags []*protocol.Tag
|
||||
fields []*protocol.Field
|
||||
t time.Time
|
||||
encoder *protocol.Encoder
|
||||
}
|
||||
|
||||
func (c *LikwidCollector) Name() string {
|
||||
return c.name
|
||||
}
|
||||
func (c *LikwidCollector) TagList() []*protocol.Tag {
|
||||
return c.tags
|
||||
}
|
||||
|
||||
func (c *LikwidCollector) FieldList() []*protocol.Field {
|
||||
return c.fields
|
||||
}
|
||||
|
||||
func (c *LikwidCollector) Time() time.Time {
|
||||
return c.t
|
||||
}
|
||||
|
||||
func (c *LikwidCollector) New() {
|
||||
buf := &bytes.Buffer{}
|
||||
c.encoder = protocol.NewEncoder(buf)
|
||||
c.encoder.SetMaxLineBytes(1024)
|
||||
}
|
||||
|
||||
func (c *LikwidCollector) Start(
|
||||
level string,
|
||||
frequency time.Duration,
|
||||
duration int) {
|
||||
ticker := time.NewTicker(frequency * time.Second)
|
||||
done := make(chan bool)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
case t := <-ticker.C:
|
||||
fmt.Println("Tick at", t)
|
||||
|
||||
c.encoder.Encode(c)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
time.Sleep(1600 * time.Second)
|
||||
ticker.Stop()
|
||||
done <- true
|
||||
fmt.Println("Ticker stopped")
|
||||
}
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module github.com/ClusterCockpit/cc-metric-collector
|
||||
|
||||
go 1.16
|
||||
|
||||
require github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097
|
Loading…
Reference in New Issue
Block a user