ccmessage

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 13 Imported by: 7

README

ClusterCockpit messages

As described in the ClusterCockpit specifications, the whole ClusterCockpit stack uses metrics, events and control in the InfluxDB line protocol format. This is also the input and output format for the ClusterCockpit Metric Collector but internally it uses an extended format while processing, named CCMessage.

It is basically a copy of the InfluxDB line protocol MutableMetric interface with one extension. Besides the tags and fields, it contains a list of meta information (re-using the Tag structure of the original protocol):

type ccMessage struct {
    name   string                 // Measurement name
    meta   map[string]string      // map of meta data tags
    tags   map[string]string      // map of of tags
    fields map[string]interface{} // map of of fields
    tm     time.Time              // timestamp
}

type CCMessage interface {
    ToPoint(metaAsTags map[string]bool) *write.Point  // Generate influxDB point for data type ccMessage
    ToLineProtocol(metaAsTags map[string]bool) string // Generate influxDB line protocol for data type ccMessage
    String() string                                   // Return line-protocol like string

    Name() string        // Get metric name
    SetName(name string) // Set metric name

    Time() time.Time     // Get timestamp
    SetTime(t time.Time) // Set timestamp

    Tags() map[string]string                   // Map of tags
    AddTag(key, value string)                  // Add a tag
    GetTag(key string) (value string, ok bool) // Get a tag by its key
    HasTag(key string) (ok bool)               // Check if a tag key is present
    RemoveTag(key string)                      // Remove a tag by its key

    Meta() map[string]string                    // Map of meta data tags
    AddMeta(key, value string)                  // Add a meta data tag
    GetMeta(key string) (value string, ok bool) // Get a meta data tab addressed by its key
    HasMeta(key string) (ok bool)               // Check if a meta data key is present
    RemoveMeta(key string)                      // Remove a meta data tag by its key

    Fields() map[string]interface{}                   // Map of fields
    AddField(key string, value interface{})           // Add a field
    GetField(key string) (value interface{}, ok bool) // Get a field addressed by its key
    HasField(key string) (ok bool)                    // Check if a field key is present
    RemoveField(key string)                           // Remove a field addressed by its key
}

func NewMessage(name string, tags map[string]string, meta map[string]string, fields map[string]interface{}, tm time.Time) (CCMessage, error)
func FromMessage(other CCMessage) CCMessage
func FromInfluxMetric(other lp.Metric) CCMessage

The CCMessage interface provides the same functions as the MutableMetric like {Add, Get, Remove, Has}{Tag, Field} and additionally provides {Add, Get, Remove, Has}Meta.

The InfluxDB protocol creates a new metric with influx.New(name, tags, fields, time) while CCMessage uses ccMessage.New(name, tags, meta, fields, time) where tags and meta are both of type map[string]string.

You can copy a CCMessage with FromFromMessage(other CCMessage) CCMessage. If you get an influx.Metric from a function, like the line protocol parser, you can use FromInfluxMetric(other influx.Metric) CCMessage to get a CCMessage out of it (see NatsReceiver for an example).

Although the cc-specifications defines that there is only a value field for the metric value, the CCMessage still can have multiple values similar to the InfluxDB line protocol.

Documentation

Overview

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	CCMSG_TYPE_METRIC = iota
	CCMSG_TYPE_EVENT
	CCMSG_TYPE_LOG
	CCMSG_TYPE_CONTROL
)
View Source
const (
	MIN_CCMSG_TYPE     = CCMSG_TYPE_METRIC
	MAX_CCMSG_TYPE     = CCMSG_TYPE_CONTROL
	CCMSG_TYPE_INVALID = MAX_CCMSG_TYPE + 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CCMessage

type CCMessage interface {
	ToPoint(metaAsTags map[string]bool) *write.Point  // Generate influxDB point for data type ccMessage
	ToLineProtocol(metaAsTags map[string]bool) string // Generate influxDB line protocol for data type ccMessage
	ToJSON(metaAsTags map[string]bool) (json.RawMessage, error)

	Name() string        // Get metric name
	SetName(name string) // Set metric name

	Time() time.Time     // Get timestamp
	SetTime(t time.Time) // Set timestamp

	Tags() map[string]string                   // Map of tags
	AddTag(key, value string)                  // Add a tag
	GetTag(key string) (value string, ok bool) // Get a tag by its key
	HasTag(key string) (ok bool)               // Check if a tag key is present
	RemoveTag(key string)                      // Remove a tag by its key

	Meta() map[string]string                    // Map of meta data tags
	AddMeta(key, value string)                  // Add a meta data tag
	GetMeta(key string) (value string, ok bool) // Get a meta data tab addressed by its key
	HasMeta(key string) (ok bool)               // Check if a meta data key is present
	RemoveMeta(key string)                      // Remove a meta data tag by its key

	Fields() map[string]interface{}                   // Map of fields
	AddField(key string, value interface{})           // Add a field
	GetField(key string) (value interface{}, ok bool) // Get a field addressed by its key
	HasField(key string) (ok bool)                    // Check if a field key is present
	RemoveField(key string)                           // Remove a field addressed by its key
	String() string                                   // Return line-protocol like string

	MessageType() CCMessageType // Return message type
	IsMetric() bool
	GetMetricValue() interface{}
	IsLog() bool
	GetLogValue() string
	IsEvent() bool
	GetEventValue() string
	IsControl() bool
	GetControlValue() string
	GetControlMethod() string
}

ccMessage access functions

func EmptyMessage

func EmptyMessage() CCMessage

func FromBytes

func FromBytes(data []byte) ([]CCMessage, error)

func FromInfluxMetric

func FromInfluxMetric(other lp1.Metric) CCMessage

FromInfluxMetric copies the influxDB line protocol metric <other>

func FromJSON

func FromJSON(input json.RawMessage) (CCMessage, error)

func FromMessage

func FromMessage(other CCMessage) CCMessage

FromMetric copies the metric <other>

func NewEvent

func NewEvent(name string,
	tags map[string]string,
	meta map[string]string,
	event string,
	tm time.Time,
) (CCMessage, error)

func NewGetControl

func NewGetControl(name string,
	tags map[string]string,
	meta map[string]string,
	tm time.Time,
) (CCMessage, error)

func NewJobStartEvent

func NewJobStartEvent(job *schema.Job) (CCMessage, error)

func NewJobStopEvent

func NewJobStopEvent(job *schema.Job) (CCMessage, error)

func NewLog

func NewLog(name string,
	tags map[string]string,
	meta map[string]string,
	log string,
	tm time.Time,
) (CCMessage, error)

func NewMessage

func NewMessage(
	name string,
	tags map[string]string,
	meta map[string]string,
	fields map[string]interface{},
	tm time.Time,
) (CCMessage, error)

New creates a new measurement point

func NewMetric

func NewMetric(name string,
	tags map[string]string,
	meta map[string]string,
	value interface{},
	tm time.Time,
) (CCMessage, error)

func NewPutControl

func NewPutControl(name string,
	tags map[string]string,
	meta map[string]string,
	value string,
	tm time.Time,
) (CCMessage, error)

func NewQuery added in v0.2.0

func NewQuery(name string,
	tags map[string]string,
	meta map[string]string,
	q string,
	tm time.Time,
) (CCMessage, error)

type CCMessageType

type CCMessageType int

func (CCMessageType) FieldKey

func (t CCMessageType) FieldKey() string

func (CCMessageType) String

func (t CCMessageType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL