2024-05-03 21:08:01 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// For aggregation over multiple values at different cpus/sockets/..., not time!
|
|
|
|
type AggregationStrategy int
|
|
|
|
|
|
|
|
const (
|
|
|
|
NoAggregation AggregationStrategy = iota
|
|
|
|
SumAggregation
|
|
|
|
AvgAggregation
|
|
|
|
)
|
|
|
|
|
|
|
|
func (as *AggregationStrategy) UnmarshalJSON(data []byte) error {
|
|
|
|
var str string
|
|
|
|
if err := json.Unmarshal(data, &str); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch str {
|
|
|
|
case "":
|
|
|
|
*as = NoAggregation
|
|
|
|
case "sum":
|
|
|
|
*as = SumAggregation
|
|
|
|
case "avg":
|
|
|
|
*as = AvgAggregation
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("invalid aggregation strategy: %#v", str)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type MetricConfig struct {
|
|
|
|
// Interval in seconds at which measurements will arive.
|
|
|
|
Frequency int64 `json:"frequency"`
|
|
|
|
|
|
|
|
// Can be 'sum', 'avg' or null. Describes how to aggregate metrics from the same timestep over the hierarchy.
|
|
|
|
Aggregation AggregationStrategy `json:"aggregation"`
|
|
|
|
|
|
|
|
// Private, used internally...
|
2024-05-06 09:27:28 +02:00
|
|
|
Offset int
|
2024-05-03 21:08:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type HttpConfig struct {
|
|
|
|
// Address to bind to, for example "0.0.0.0:8081"
|
|
|
|
Address string `json:"address"`
|
|
|
|
|
|
|
|
// If not the empty string, use https with this as the certificate file
|
|
|
|
CertFile string `json:"https-cert-file"`
|
|
|
|
|
|
|
|
// If not the empty string, use https with this as the key file
|
|
|
|
KeyFile string `json:"https-key-file"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type NatsConfig struct {
|
|
|
|
// Address of the nats server
|
|
|
|
Address string `json:"address"`
|
|
|
|
|
|
|
|
// Username/Password, optional
|
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
|
2024-10-26 22:38:03 +02:00
|
|
|
//Creds file path
|
|
|
|
Credsfilepath string `json:"creds-file-path"`
|
|
|
|
|
2024-05-03 21:08:01 +02:00
|
|
|
Subscriptions []struct {
|
|
|
|
// Channel name
|
|
|
|
SubscribeTo string `json:"subscribe-to"`
|
|
|
|
|
|
|
|
// Allow lines without a cluster tag, use this as default, optional
|
|
|
|
ClusterTag string `json:"cluster-tag"`
|
|
|
|
} `json:"subscriptions"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Metrics map[string]MetricConfig `json:"metrics"`
|
|
|
|
HttpConfig *HttpConfig `json:"http-api"`
|
|
|
|
Checkpoints struct {
|
|
|
|
Interval string `json:"interval"`
|
|
|
|
RootDir string `json:"directory"`
|
|
|
|
Restore string `json:"restore"`
|
|
|
|
} `json:"checkpoints"`
|
|
|
|
Debug struct {
|
|
|
|
DumpToFile string `json:"dump-to-file"`
|
|
|
|
EnableGops bool `json:"gops"`
|
|
|
|
} `json:"debug"`
|
|
|
|
RetentionInMemory string `json:"retention-in-memory"`
|
|
|
|
JwtPublicKey string `json:"jwt-public-key"`
|
|
|
|
Archive struct {
|
|
|
|
Interval string `json:"interval"`
|
|
|
|
RootDir string `json:"directory"`
|
|
|
|
DeleteInstead bool `json:"delete-instead"`
|
|
|
|
} `json:"archive"`
|
|
|
|
Nats []*NatsConfig `json:"nats"`
|
|
|
|
}
|
|
|
|
|
2024-05-06 14:20:43 +02:00
|
|
|
var Keys Config
|
|
|
|
|
|
|
|
func Init(file string) {
|
2024-05-03 21:08:01 +02:00
|
|
|
configFile, err := os.Open(file)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer configFile.Close()
|
|
|
|
dec := json.NewDecoder(configFile)
|
|
|
|
dec.DisallowUnknownFields()
|
2024-05-06 14:20:43 +02:00
|
|
|
if err := dec.Decode(&Keys); err != nil {
|
2024-05-03 21:08:01 +02:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|