After several rounds of using influxdb, I have settled on something more like your first model:
An example schema is listed below. The type of sample is defined by the “type” tag, the numeric value is generally stored in the “value” field, and then we add additional tags that may or may not be used as needed depending on the sample type. I’ve found this to be a lot more flexible that having a lot of different value names. With simple data structures like this, it is generally easier to write generic code that does things with data (algorithms, plotting, etc), because the sample format is always the same.
Cliff
The below schema is defined with Go types, and can be written/read directly using:
// SampleType... are constants used in the Sample.Type field.
const (
SampleTypeVoltage = "voltage"
SampleTypeCurrent = "current"
SampleTypeFrequency = "frequency"
SampleTypeTemperature = "temperature"
SampleTypeHumidity = "humidity"
SampleTypeAirflow = "airflow"
SampleTypeMoisture = "moisture"
SampleTypeDoorOpen = "doorOpen"
SampleTypeCPUUsage = "cpuUsage"
SampleTypeCPUTemp = "cpuTemp"
SampleTypeSysMemoryUsed = "sysMemoryUsed"
SampleTypeSysStorageUsed = "sysStorageUsed"
SampleTypeNetTx = "netTx"
SampleTypeNetRx = "netRx"
SampleTypeError = "error" // event
SampleTypeRule = "rule" // event
)
// DeviceType... are constants that define the type of device
// that collected the data and should be used in the Sample.DeviceType field
const (
DeviceTypeA = "a"
DeviceTypeB = "b"
)
// Sample defines a reading from a sensor, or system metric.
type Sample struct {
Time time.Time `influx:"time" json:"time"`
State string `json:"state,omitempty" influx:"state,tag"`
City string `json:"city,omitempty" influx:"city,tag"`
Facility string `json:"facility,omitempty" influx:"facility,tag"`
Floor string `json:"floor,omitempty" influx:"floor,tag"`
Cell string `json:"cell,omitempty" influx:"cell,tag"`
Cage string `json:"cage,omitempty" influx:"cage,tag"`
Aisle string `json:"aisle,omitempty" influx:"aisle,tag"`
SubRack string `json:"subRack,omitempty" influx:"subRack,tag"`
// Type is the metric type (i.e. SampleTypeVoltage)
Type string `json:"type" influx:"type,tag"`
// DeviceType is the device that generated the sample (i.e. DeviceTypeAts)
DeviceType string `json:"deviceType" influx:"deviceType,tag"`
Interval string `json:"interval,omitempty" influx:"interval,tag"`
Partition string `json:"partition,omitempty" influx:"partition,tag"`
// ID is the the device ID that generated the sample
ID string `json:"id" influx:"id,tag"`
// Value is the value of a numeric/boolean metric for this sample
Value float64 `json:"value,omitempty" influx:"value"`
// Duration describes the time window over which the sample was collected
// (if it is an average, etc)
Duration float64 `json:"duration,omitempty" influx:"duration"`
// Event is a string describing an event
Event string `json:"event,omitempty" influx:"event"`
}