fields and tags

This commit is contained in:
2026-02-04 21:32:32 +01:00
parent a1ea1b230e
commit 5b46ecb0b1
2 changed files with 14 additions and 57 deletions

View File

@@ -81,22 +81,11 @@ func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
}
// Build tags
tags := map[string]string{
"application": measurement.Application,
}
tags := make(map[string]string)
if measurement.Device != "" {
tags["device"] = measurement.Device
}
// Add attributes as tags
for key, value := range measurement.Attributes {
if strValue, ok := value.(string); ok {
tags[key] = strValue
} else {
tags[key] = fmt.Sprintf("%v", value)
}
}
// Build fields from Values
fields := make(map[string]interface{})
for key, varType := range measurement.Values {
@@ -107,13 +96,22 @@ func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
if varType.Unit != "" {
fields[key+"_unit"] = varType.Unit
}
if varType.Variable != "" {
fields[key+"_variable"] = varType.Variable
}
// This is already the column name, so we can skip it
//if varType.Variable != "" {
// fields[key+"_variable"] = varType.Variable
//}
if varType.Status != "" {
fields[key+"_status"] = varType.Status
}
}
// Add attributes as fields
for key, value := range measurement.Attributes {
if strValue, ok := value.(string); ok {
fields[key] = strValue
} else {
fields[key] = fmt.Sprintf("%v", value)
}
}
// Ensure we have at least one field
if len(fields) == 0 {
@@ -124,7 +122,7 @@ func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
// Create point
pt, err := influxdb.NewPoint(
"observation",
measurement.Application,
tags,
fields,
measurement.Time,