2017-04-18 01:48:38 +02:00
|
|
|
package influxdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
"github.com/influxdata/influxdb/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InsertGlobals implementation of database
|
2018-01-17 20:20:35 +01:00
|
|
|
func (conn *Connection) InsertGlobals(stats *runtime.GlobalStats, time time.Time, site string, domain string) {
|
|
|
|
tags := models.Tags{}
|
2017-11-21 15:12:06 +01:00
|
|
|
|
|
|
|
measurementGlobal := MeasurementGlobal
|
|
|
|
counterMeasurementModel := CounterMeasurementModel
|
|
|
|
counterMeasurementFirmware := CounterMeasurementFirmware
|
|
|
|
counterMeasurementAutoupdater := CounterMeasurementAutoupdater
|
|
|
|
|
|
|
|
if site != runtime.GLOBAL_SITE {
|
2018-01-17 20:20:35 +01:00
|
|
|
tags.Set([]byte("site"), []byte(site))
|
2017-11-21 15:12:06 +01:00
|
|
|
|
|
|
|
measurementGlobal += "_site"
|
|
|
|
counterMeasurementModel += "_site"
|
|
|
|
counterMeasurementFirmware += "_site"
|
|
|
|
counterMeasurementAutoupdater += "_site"
|
|
|
|
}
|
2018-01-17 20:20:35 +01:00
|
|
|
if domain != runtime.GLOBAL_DOMAIN {
|
|
|
|
tags.Set([]byte("domain"), []byte(domain))
|
|
|
|
|
|
|
|
measurementGlobal += "_domain"
|
|
|
|
counterMeasurementModel += "_domain"
|
|
|
|
counterMeasurementFirmware += "_domain"
|
|
|
|
counterMeasurementAutoupdater += "_domain"
|
|
|
|
}
|
2017-11-21 15:12:06 +01:00
|
|
|
|
|
|
|
conn.addPoint(measurementGlobal, tags, GlobalStatsFields(stats), time)
|
2018-01-17 20:20:35 +01:00
|
|
|
conn.addCounterMap(counterMeasurementModel, stats.Models, time, site, domain)
|
|
|
|
conn.addCounterMap(counterMeasurementFirmware, stats.Firmwares, time, site, domain)
|
|
|
|
conn.addCounterMap(counterMeasurementAutoupdater, stats.Autoupdater, time, site, domain)
|
2017-04-18 01:48:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalStatsFields returns fields for InfluxDB
|
|
|
|
func GlobalStatsFields(stats *runtime.GlobalStats) map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
|
|
|
"nodes": stats.Nodes,
|
|
|
|
"gateways": stats.Gateways,
|
|
|
|
"clients.total": stats.Clients,
|
|
|
|
"clients.wifi": stats.ClientsWifi,
|
|
|
|
"clients.wifi24": stats.ClientsWifi24,
|
|
|
|
"clients.wifi5": stats.ClientsWifi5,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Saves the values of a CounterMap in the database.
|
|
|
|
// The key are used as 'value' tag.
|
|
|
|
// The value is used as 'counter' field.
|
2018-01-17 20:20:35 +01:00
|
|
|
func (conn *Connection) addCounterMap(name string, m runtime.CounterMap, t time.Time, site string, domain string) {
|
2017-04-18 01:48:38 +02:00
|
|
|
for key, count := range m {
|
|
|
|
conn.addPoint(
|
|
|
|
name,
|
|
|
|
models.Tags{
|
|
|
|
models.Tag{Key: []byte("value"), Value: []byte(key)},
|
2017-11-21 15:12:06 +01:00
|
|
|
models.Tag{Key: []byte("site"), Value: []byte(site)},
|
2018-01-17 20:20:35 +01:00
|
|
|
models.Tag{Key: []byte("domain"), Value: []byte(domain)},
|
2017-04-18 01:48:38 +02:00
|
|
|
},
|
|
|
|
models.Fields{"count": count},
|
2017-04-18 03:10:16 +02:00
|
|
|
t,
|
2017-04-18 01:48:38 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|