mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
be20f956c2
* InfiniBandCollector: Scale raw readings from octets to bytes * Fix clock frequency coming from LikwidCollector and update docs * Build DEB package for Ubuntu 20.04 for releases * Fix memstat collector with numa_stats option * Remove useless prints from MemstatCollector * Replace ioutils with os and io (#87) * Use lower case for error strings in RocmSmiCollector * move maybe-usable-by-other-cc-components to pkg. Fix all files to use the new paths (#88) * Add collector for monitoring the execution of cc-metric-collector itself (#81) * Add collector to monitor execution of cc-metric-collector itself * Register SelfCollector * Fix import paths for moved packages
81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
package collectors
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
|
|
lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
|
|
)
|
|
|
|
type MetricCollector interface {
|
|
Name() string // Name of the metric collector
|
|
Init(config json.RawMessage) error // Initialize metric collector
|
|
Initialized() bool // Is metric collector initialized?
|
|
Parallel() bool
|
|
Read(duration time.Duration, output chan lp.CCMetric) // Read metrics from metric collector
|
|
Close() // Close / finish metric collector
|
|
}
|
|
|
|
type metricCollector struct {
|
|
name string // name of the metric
|
|
init bool // is metric collector initialized?
|
|
parallel bool // can the metric collector be executed in parallel with others
|
|
meta map[string]string // static meta data tags
|
|
}
|
|
|
|
// Name returns the name of the metric collector
|
|
func (c *metricCollector) Name() string {
|
|
return c.name
|
|
}
|
|
|
|
// Name returns the name of the metric collector
|
|
func (c *metricCollector) Parallel() bool {
|
|
return c.parallel
|
|
}
|
|
|
|
// Setup is for future use
|
|
func (c *metricCollector) setup() error {
|
|
return nil
|
|
}
|
|
|
|
// Initialized indicates whether the metric collector has been initialized
|
|
func (c *metricCollector) Initialized() bool {
|
|
return c.init
|
|
}
|
|
|
|
// intArrayContains scans an array of ints if the value str is present in the array
|
|
// If the specified value is found, the corresponding array index is returned.
|
|
// The bool value is used to signal success or failure
|
|
func intArrayContains(array []int, str int) (int, bool) {
|
|
for i, a := range array {
|
|
if a == str {
|
|
return i, true
|
|
}
|
|
}
|
|
return -1, false
|
|
}
|
|
|
|
// stringArrayContains scans an array of strings if the value str is present in the array
|
|
// If the specified value is found, the corresponding array index is returned.
|
|
// The bool value is used to signal success or failure
|
|
func stringArrayContains(array []string, str string) (int, bool) {
|
|
for i, a := range array {
|
|
if a == str {
|
|
return i, true
|
|
}
|
|
}
|
|
return -1, false
|
|
}
|
|
|
|
// RemoveFromStringList removes the string r from the array of strings s
|
|
// If r is not contained in the array an error is returned
|
|
func RemoveFromStringList(s []string, r string) ([]string, error) {
|
|
for i := range s {
|
|
if r == s[i] {
|
|
return append(s[:i], s[i+1:]...), nil
|
|
}
|
|
}
|
|
return s, fmt.Errorf("no such string in list")
|
|
}
|