mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-25 15:09:05 +01:00
Additional comments
This commit is contained in:
parent
2c08e53be4
commit
33fec95eac
@ -13,29 +13,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MetricCollector interface {
|
type MetricCollector interface {
|
||||||
Name() string
|
Name() string // Name of the metric collector
|
||||||
Init(config json.RawMessage) error
|
Init(config json.RawMessage) error // Initialize metric collector
|
||||||
Initialized() bool
|
Initialized() bool // Is metric collector initialized?
|
||||||
Read(duration time.Duration, output chan lp.CCMetric)
|
Read(duration time.Duration, output chan lp.CCMetric) // Read metrics from metric collector
|
||||||
Close()
|
Close() // Close / finish metric collector
|
||||||
}
|
}
|
||||||
|
|
||||||
type metricCollector struct {
|
type metricCollector struct {
|
||||||
name string
|
name string // name of the metric
|
||||||
init bool
|
init bool // is metric collector initialized?
|
||||||
meta map[string]string
|
meta map[string]string // static meta data tags
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name() returns the name of the metric collector
|
// Name returns the name of the metric collector
|
||||||
func (c *metricCollector) Name() string {
|
func (c *metricCollector) Name() string {
|
||||||
return c.name
|
return c.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup is for future use
|
||||||
func (c *metricCollector) setup() error {
|
func (c *metricCollector) setup() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialized() indicates whether the metric collector has been initialized.
|
// Initialized indicates whether the metric collector has been initialized
|
||||||
func (c *metricCollector) Initialized() bool {
|
func (c *metricCollector) Initialized() bool {
|
||||||
return c.init
|
return c.init
|
||||||
}
|
}
|
||||||
@ -64,6 +65,7 @@ func stringArrayContains(array []string, str string) (int, bool) {
|
|||||||
return -1, false
|
return -1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SocketList returns the list of physical sockets as read from /proc/cpuinfo
|
||||||
func SocketList() []int {
|
func SocketList() []int {
|
||||||
buffer, err := ioutil.ReadFile("/proc/cpuinfo")
|
buffer, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -89,6 +91,7 @@ func SocketList() []int {
|
|||||||
return packs
|
return packs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CpuList returns the list of physical CPUs (in contrast to logical CPUs) as read from /proc/cpuinfo
|
||||||
func CpuList() []int {
|
func CpuList() []int {
|
||||||
buffer, err := ioutil.ReadFile("/proc/cpuinfo")
|
buffer, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -117,8 +120,8 @@ func CpuList() []int {
|
|||||||
// RemoveFromStringList removes the string r from the array of strings s
|
// RemoveFromStringList removes the string r from the array of strings s
|
||||||
// If r is not contained in the array an error is returned
|
// If r is not contained in the array an error is returned
|
||||||
func RemoveFromStringList(s []string, r string) ([]string, error) {
|
func RemoveFromStringList(s []string, r string) ([]string, error) {
|
||||||
for i, item := range s {
|
for i := range s {
|
||||||
if r == item {
|
if r == s[i] {
|
||||||
return append(s[:i], s[i+1:]...), nil
|
return append(s[:i], s[i+1:]...), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ type defaultReceiverConfig struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Receiver configuration: Listen address, port
|
||||||
type ReceiverConfig struct {
|
type ReceiverConfig struct {
|
||||||
Addr string `json:"address"`
|
Addr string `json:"address"`
|
||||||
Port string `json:"port"`
|
Port string `json:"port"`
|
||||||
@ -23,15 +24,17 @@ type receiver struct {
|
|||||||
|
|
||||||
type Receiver interface {
|
type Receiver interface {
|
||||||
Start()
|
Start()
|
||||||
Close()
|
Close() // Close / finish metric receiver
|
||||||
Name() string
|
Name() string // Name of the metric receiver
|
||||||
SetSink(sink chan lp.CCMetric)
|
SetSink(sink chan lp.CCMetric) // Set sink channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name returns the name of the metric receiver
|
||||||
func (r *receiver) Name() string {
|
func (r *receiver) Name() string {
|
||||||
return r.name
|
return r.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSink set the sink channel
|
||||||
func (r *receiver) SetSink(sink chan lp.CCMetric) {
|
func (r *receiver) SetSink(sink chan lp.CCMetric) {
|
||||||
r.sink = sink
|
r.sink = sink
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SampleReceiver configuration: receiver type, listen address, port
|
||||||
type SampleReceiverConfig struct {
|
type SampleReceiverConfig struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Addr string `json:"address"`
|
Addr string `json:"address"`
|
||||||
@ -24,6 +25,10 @@ type SampleReceiver struct {
|
|||||||
// wg sync.WaitGroup
|
// wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implement functions required for Receiver interface
|
||||||
|
// Start(), Close()
|
||||||
|
// See: metricReceiver.go
|
||||||
|
|
||||||
func (r *SampleReceiver) Start() {
|
func (r *SampleReceiver) Start() {
|
||||||
cclog.ComponentDebug(r.name, "START")
|
cclog.ComponentDebug(r.name, "START")
|
||||||
|
|
||||||
@ -44,6 +49,7 @@ func (r *SampleReceiver) Start() {
|
|||||||
// }()
|
// }()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close receiver: close network connection, close files, close libraries, ...
|
||||||
func (r *SampleReceiver) Close() {
|
func (r *SampleReceiver) Close() {
|
||||||
cclog.ComponentDebug(r.name, "CLOSE")
|
cclog.ComponentDebug(r.name, "CLOSE")
|
||||||
|
|
||||||
@ -54,13 +60,21 @@ func (r *SampleReceiver) Close() {
|
|||||||
// r.wg.Wait()
|
// r.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New function to create a new instance of the receiver
|
||||||
|
// Initialize the receiver by giving it a name and reading in the config JSON
|
||||||
func NewSampleReceiver(name string, config json.RawMessage) (Receiver, error) {
|
func NewSampleReceiver(name string, config json.RawMessage) (Receiver, error) {
|
||||||
r := new(SampleReceiver)
|
r := new(SampleReceiver)
|
||||||
r.name = fmt.Sprintf("HttpReceiver(%s)", name)
|
|
||||||
|
// Set name of SampleReceiver
|
||||||
|
// The name should be chosen in such a way that different instances of SampleReceiver can be distinguished
|
||||||
|
r.name = fmt.Sprintf("SampleReceiver(%s)", name)
|
||||||
|
|
||||||
// Set static information
|
// Set static information
|
||||||
r.meta = map[string]string{"source": r.name}
|
r.meta = map[string]string{"source": r.name}
|
||||||
|
|
||||||
|
// Set defaults in r.config
|
||||||
|
// Allow overwriting these defaults by reading config JSON
|
||||||
|
|
||||||
// Read the sample receiver specific JSON config
|
// Read the sample receiver specific JSON config
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &r.config)
|
err := json.Unmarshal(config, &r.config)
|
||||||
|
@ -10,17 +10,18 @@ type defaultSinkConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type sink struct {
|
type sink struct {
|
||||||
meta_as_tags bool
|
meta_as_tags bool // Use meta data tags as tags
|
||||||
name string
|
name string // Name of the sink
|
||||||
}
|
}
|
||||||
|
|
||||||
type Sink interface {
|
type Sink interface {
|
||||||
Write(point lp.CCMetric) error
|
Write(point lp.CCMetric) error // Write metric to the sink
|
||||||
Flush() error
|
Flush() error // Flush buffered metrics
|
||||||
Close()
|
Close() // Close / finish metric sink
|
||||||
Name() string
|
Name() string // Name of the metric sink
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name returns the name of the metric sink
|
||||||
func (s *sink) Name() string {
|
func (s *sink) Name() string {
|
||||||
return s.name
|
return s.name
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,9 @@ func (s *SampleSink) Close() {
|
|||||||
// Initialize the sink by giving it a name and reading in the config JSON
|
// Initialize the sink by giving it a name and reading in the config JSON
|
||||||
func NewSampleSink(name string, config json.RawMessage) (Sink, error) {
|
func NewSampleSink(name string, config json.RawMessage) (Sink, error) {
|
||||||
s := new(SampleSink)
|
s := new(SampleSink)
|
||||||
|
|
||||||
|
// Set name of sampleSink
|
||||||
|
// The name should be chosen in such a way that different instances of SampleSink can be distinguished
|
||||||
s.name = fmt.Sprintf("SampleSink(%s)", name) // Always specify a name here
|
s.name = fmt.Sprintf("SampleSink(%s)", name) // Always specify a name here
|
||||||
|
|
||||||
// Set defaults in s.config
|
// Set defaults in s.config
|
||||||
|
Loading…
Reference in New Issue
Block a user