mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-11-04 02:35:07 +01:00 
			
		
		
		
	Ccmessage migration (#119)
* Add cpu_used (all-cpu_idle) to CpustatCollector * Update cc-metric-collector.init * Allow selection of timestamp precision in HttpSink * Add comment about precision requirement for cc-metric-store * Fix for API changes in gofish@v0.15.0 * Update requirements to latest version * Read sensors through redfish * Update golang toolchain to 1.21 * Remove stray error check * Update main config in configuration.md * Update Release action to use golang 1.22 stable release, no golang RPMs anymore * Update runonce action to use golang 1.22 stable release, no golang RPMs anymore * Switch to CCMessage for all files. --------- Co-authored-by: Holger Obermaier <Holger.Obermaier@kit.edu> Co-authored-by: Holger Obermaier <40787752+ho-ob@users.noreply.github.com>
This commit is contained in:
		@@ -4,10 +4,10 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GangliaMetricName(point lp.CCMetric) string {
 | 
			
		||||
func GangliaMetricName(point lp.CCMessage) string {
 | 
			
		||||
	name := point.Name()
 | 
			
		||||
	metricType, typeOK := point.GetTag("type")
 | 
			
		||||
	metricTid, tidOk := point.GetTag("type-id")
 | 
			
		||||
@@ -39,7 +39,7 @@ func GangliaMetricRename(name string) string {
 | 
			
		||||
	return name
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GangliaSlopeType(point lp.CCMetric) uint {
 | 
			
		||||
func GangliaSlopeType(point lp.CCMessage) uint {
 | 
			
		||||
	name := point.Name()
 | 
			
		||||
	if name == "mem_total" || name == "swap_total" {
 | 
			
		||||
		return 0
 | 
			
		||||
@@ -151,7 +151,7 @@ type GangliaMetricConfig struct {
 | 
			
		||||
	Name  string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetCommonGangliaConfig(point lp.CCMetric) GangliaMetricConfig {
 | 
			
		||||
func GetCommonGangliaConfig(point lp.CCMessage) GangliaMetricConfig {
 | 
			
		||||
	mname := GangliaMetricRename(point.Name())
 | 
			
		||||
	if oldname, ok := point.GetMeta("oldname"); ok {
 | 
			
		||||
		mname = GangliaMetricRename(oldname)
 | 
			
		||||
@@ -207,7 +207,7 @@ func GetCommonGangliaConfig(point lp.CCMetric) GangliaMetricConfig {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetGangliaConfig(point lp.CCMetric) GangliaMetricConfig {
 | 
			
		||||
func GetGangliaConfig(point lp.CCMessage) GangliaMetricConfig {
 | 
			
		||||
	mname := GangliaMetricRename(point.Name())
 | 
			
		||||
	if oldname, ok := point.GetMeta("oldname"); ok {
 | 
			
		||||
		mname = GangliaMetricRename(oldname)
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ import (
 | 
			
		||||
	"os/exec"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const GMETRIC_EXEC = `gmetric`
 | 
			
		||||
@@ -35,7 +35,7 @@ type GangliaSink struct {
 | 
			
		||||
	config         GangliaSinkConfig
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *GangliaSink) Write(point lp.CCMetric) error {
 | 
			
		||||
func (s *GangliaSink) Write(point lp.CCMessage) error {
 | 
			
		||||
	var err error = nil
 | 
			
		||||
	//var tagsstr []string
 | 
			
		||||
	var argstr []string
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
	influx "github.com/influxdata/line-protocol/v2/lineprotocol"
 | 
			
		||||
	"golang.org/x/exp/slices"
 | 
			
		||||
)
 | 
			
		||||
@@ -75,7 +75,7 @@ type HttpSink struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Write sends metric m as http message
 | 
			
		||||
func (s *HttpSink) Write(m lp.CCMetric) error {
 | 
			
		||||
func (s *HttpSink) Write(m lp.CCMessage) error {
 | 
			
		||||
 | 
			
		||||
	// Lock for encoder usage
 | 
			
		||||
	s.encoderLock.Lock()
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
	influxdb2 "github.com/influxdata/influxdb-client-go/v2"
 | 
			
		||||
	influxdb2Api "github.com/influxdata/influxdb-client-go/v2/api"
 | 
			
		||||
	influxdb2ApiHttp "github.com/influxdata/influxdb-client-go/v2/api/http"
 | 
			
		||||
@@ -112,7 +112,7 @@ func (s *InfluxAsyncSink) connect() error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *InfluxAsyncSink) Write(m lp.CCMetric) error {
 | 
			
		||||
func (s *InfluxAsyncSink) Write(m lp.CCMessage) error {
 | 
			
		||||
	if s.customFlushInterval != 0 && s.flushTimer == nil {
 | 
			
		||||
		// Run a batched flush for all lines that have arrived in the defined interval
 | 
			
		||||
		s.flushTimer = time.AfterFunc(s.customFlushInterval, func() {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
	influxdb2 "github.com/influxdata/influxdb-client-go/v2"
 | 
			
		||||
	influxdb2Api "github.com/influxdata/influxdb-client-go/v2/api"
 | 
			
		||||
	influx "github.com/influxdata/line-protocol/v2/lineprotocol"
 | 
			
		||||
@@ -224,7 +224,7 @@ func (s *InfluxSink) connect() error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Write sends metric m in influxDB line protocol
 | 
			
		||||
func (s *InfluxSink) Write(m lp.CCMetric) error {
 | 
			
		||||
func (s *InfluxSink) Write(m lp.CCMessage) error {
 | 
			
		||||
 | 
			
		||||
	// Lock for encoder usage
 | 
			
		||||
	s.encoderLock.Lock()
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,7 @@ import (
 | 
			
		||||
	"unsafe"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
	"github.com/NVIDIA/go-nvml/pkg/dl"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -110,7 +110,7 @@ type LibgangliaSink struct {
 | 
			
		||||
	cstrCache      map[string]*C.char
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *LibgangliaSink) Write(point lp.CCMetric) error {
 | 
			
		||||
func (s *LibgangliaSink) Write(point lp.CCMessage) error {
 | 
			
		||||
	var err error = nil
 | 
			
		||||
	var c_name *C.char
 | 
			
		||||
	var c_value *C.char
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
package sinks
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type defaultSinkConfig struct {
 | 
			
		||||
@@ -15,7 +15,7 @@ type sink struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Sink interface {
 | 
			
		||||
	Write(point lp.CCMetric) error // Write metric to the sink
 | 
			
		||||
	Write(point lp.CCMessage) error // Write metric to the sink
 | 
			
		||||
	Flush() error                  // Flush buffered metrics
 | 
			
		||||
	Close()                        // Close / finish metric sink
 | 
			
		||||
	Name() string                  // Name of the metric sink
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
	influx "github.com/influxdata/line-protocol"
 | 
			
		||||
	nats "github.com/nats-io/nats.go"
 | 
			
		||||
)
 | 
			
		||||
@@ -59,7 +59,7 @@ func (s *NatsSink) connect() error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *NatsSink) Write(m lp.CCMetric) error {
 | 
			
		||||
func (s *NatsSink) Write(m lp.CCMessage) error {
 | 
			
		||||
	s.lock.Lock()
 | 
			
		||||
	_, err := s.encoder.Encode(m.ToPoint(s.meta_as_tags))
 | 
			
		||||
	s.lock.Unlock()
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ import (
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
	"github.com/gorilla/mux"
 | 
			
		||||
	"github.com/prometheus/client_golang/prometheus"
 | 
			
		||||
	"github.com/prometheus/client_golang/prometheus/promhttp"
 | 
			
		||||
@@ -55,7 +55,7 @@ func intToFloat64(input interface{}) (float64, error) {
 | 
			
		||||
	return 0, errors.New("cannot cast value to float64")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getLabelValue(metric lp.CCMetric) []string {
 | 
			
		||||
func getLabelValue(metric lp.CCMessage) []string {
 | 
			
		||||
	labelValues := []string{}
 | 
			
		||||
	if tid, tidok := metric.GetTag("type-id"); tidok && metric.HasTag("type") {
 | 
			
		||||
		labelValues = append(labelValues, tid)
 | 
			
		||||
@@ -68,7 +68,7 @@ func getLabelValue(metric lp.CCMetric) []string {
 | 
			
		||||
	return labelValues
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getLabelNames(metric lp.CCMetric) []string {
 | 
			
		||||
func getLabelNames(metric lp.CCMessage) []string {
 | 
			
		||||
	labelNames := []string{}
 | 
			
		||||
	if t, tok := metric.GetTag("type"); tok && metric.HasTag("type-id") {
 | 
			
		||||
		labelNames = append(labelNames, t)
 | 
			
		||||
@@ -81,7 +81,7 @@ func getLabelNames(metric lp.CCMetric) []string {
 | 
			
		||||
	return labelNames
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *PrometheusSink) newMetric(metric lp.CCMetric) error {
 | 
			
		||||
func (s *PrometheusSink) newMetric(metric lp.CCMessage) error {
 | 
			
		||||
	var value float64 = 0
 | 
			
		||||
	name := metric.Name()
 | 
			
		||||
	opts := prometheus.GaugeOpts{
 | 
			
		||||
@@ -119,7 +119,7 @@ func (s *PrometheusSink) newMetric(metric lp.CCMetric) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *PrometheusSink) updateMetric(metric lp.CCMetric) error {
 | 
			
		||||
func (s *PrometheusSink) updateMetric(metric lp.CCMessage) error {
 | 
			
		||||
	var value float64 = 0.0
 | 
			
		||||
	name := metric.Name()
 | 
			
		||||
	labelValues := getLabelValue(metric)
 | 
			
		||||
@@ -152,7 +152,7 @@ func (s *PrometheusSink) updateMetric(metric lp.CCMetric) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *PrometheusSink) Write(m lp.CCMetric) error {
 | 
			
		||||
func (s *PrometheusSink) Write(m lp.CCMessage) error {
 | 
			
		||||
	return s.updateMetric(m)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ import (
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type SampleSinkConfig struct {
 | 
			
		||||
@@ -28,7 +28,7 @@ type SampleSink struct {
 | 
			
		||||
// See: metricSink.go
 | 
			
		||||
 | 
			
		||||
// Code to submit a single CCMetric to the sink
 | 
			
		||||
func (s *SampleSink) Write(point lp.CCMetric) error {
 | 
			
		||||
func (s *SampleSink) Write(point lp.CCMessage) error {
 | 
			
		||||
	// based on s.meta_as_tags use meta infos as tags
 | 
			
		||||
	log.Print(point)
 | 
			
		||||
	return nil
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ import (
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const SINK_MAX_FORWARD = 50
 | 
			
		||||
@@ -26,7 +26,7 @@ var AvailableSinks = map[string]func(name string, config json.RawMessage) (Sink,
 | 
			
		||||
 | 
			
		||||
// Metric collector manager data structure
 | 
			
		||||
type sinkManager struct {
 | 
			
		||||
	input      chan lp.CCMetric // input channel
 | 
			
		||||
	input      chan lp.CCMessage // input channel
 | 
			
		||||
	done       chan bool        // channel to finish / stop metric sink manager
 | 
			
		||||
	wg         *sync.WaitGroup  // wait group for all goroutines in cc-metric-collector
 | 
			
		||||
	sinks      map[string]Sink  // Mapping sink name to sink
 | 
			
		||||
@@ -36,7 +36,7 @@ type sinkManager struct {
 | 
			
		||||
// Sink manager access functions
 | 
			
		||||
type SinkManager interface {
 | 
			
		||||
	Init(wg *sync.WaitGroup, sinkConfigFile string) error
 | 
			
		||||
	AddInput(input chan lp.CCMetric)
 | 
			
		||||
	AddInput(input chan lp.CCMessage)
 | 
			
		||||
	AddOutput(name string, config json.RawMessage) error
 | 
			
		||||
	Start()
 | 
			
		||||
	Close()
 | 
			
		||||
@@ -108,7 +108,7 @@ func (sm *sinkManager) Start() {
 | 
			
		||||
			cclog.ComponentDebug("SinkManager", "DONE")
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		toTheSinks := func(p lp.CCMetric) {
 | 
			
		||||
		toTheSinks := func(p lp.CCMessage) {
 | 
			
		||||
			// Send received metric to all outputs
 | 
			
		||||
			cclog.ComponentDebug("SinkManager", "WRITE", p)
 | 
			
		||||
			for _, s := range sm.sinks {
 | 
			
		||||
@@ -139,7 +139,7 @@ func (sm *sinkManager) Start() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AddInput adds the input channel to the sink manager
 | 
			
		||||
func (sm *sinkManager) AddInput(input chan lp.CCMetric) {
 | 
			
		||||
func (sm *sinkManager) AddInput(input chan lp.CCMessage) {
 | 
			
		||||
	sm.input = input
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	//	"time"
 | 
			
		||||
	cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type StdoutSink struct {
 | 
			
		||||
@@ -21,7 +21,7 @@ type StdoutSink struct {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *StdoutSink) Write(m lp.CCMetric) error {
 | 
			
		||||
func (s *StdoutSink) Write(m lp.CCMessage) error {
 | 
			
		||||
	fmt.Fprint(
 | 
			
		||||
		s.output,
 | 
			
		||||
		m.ToLineProtocol(s.meta_as_tags),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user