From 024f66f49cc1b45de9658bfcda4480df59ecee03 Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Tue, 12 Oct 2021 13:26:54 +0200 Subject: [PATCH] Make nats optional; Update README.md --- README.md | 8 ++++++-- metric-store.go | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ac7e8f5..04f05c8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build & Test](https://github.com/ClusterCockpit/cc-metric-store/actions/workflows/test.yml/badge.svg)](https://github.com/ClusterCockpit/cc-metric-store/actions/workflows/test.yml) Go look at the `TODO.md` file and the [GitHub Issues](https://github.com/ClusterCockpit/cc-metric-store/issues) for a progress overview. Things work, but are not properly tested. -The [NATS.io](https://nats.io/) based writing endpoint consumes messages in [this format of the InfluxDB line protocol](https://github.com/ClusterCockpit/cc-specifications/blob/master/metrics/lineprotocol.md), but will change to another format in the future. +The [NATS.io](https://nats.io/) based writing endpoint consumes messages in [this format of the InfluxDB line protocol](https://github.com/ClusterCockpit/cc-specifications/blob/master/metrics/lineprotocol_alternative.md). ### REST API Endpoints @@ -31,6 +31,8 @@ if there was not data for a section of the requested data. 4. `GET /api/{cluster}/peek` - Return a map from every node in the specified cluster to a map from every metric to the newest value available for that metric - All cpu/socket level metrics are aggregated to the node level +5. `POST /api/write` + - You can send lines of the InfluxDB line protocol to this endpoint and they will be written to the store (Basically an alternative to NATS) ### Run tests @@ -93,8 +95,10 @@ All durations are specified in seconds. - `"sum"` means that values from the child levels are summed up for the parent level - `"avg"` means that values from the child levels are averaged for the parent level - `scope`: Unused at the moment, should be something like `"node"`, `"socket"` or `"cpu"` -- `nats`: Url of NATS.io server (The `updates` channel will be subscribed for metrics) +- `nats`: Url of NATS.io server (The `updates` channel will be subscribed for metrics), example: "nats://localhost:4222" +- `http-api-address`: Where to listen via HTTP, example: ":8080" - `jwt-public-key`: Base64 encoded string, use this to verify requests to the HTTP API +- `retention-on-memory`: Keep all values in memory for at least that amount of seconds ### Test the complete setup (excluding ClusterCockpit itself) diff --git a/metric-store.go b/metric-store.go index d983c05..6ed25df 100644 --- a/metric-store.go +++ b/metric-store.go @@ -25,6 +25,7 @@ type Config struct { RetentionInMemory int `json:"retention-in-memory"` Nats string `json:"nats"` JwtPublicKey string `json:"jwt-public-key"` + HttpApiAddress string `json:"http-api-address"` Checkpoints struct { Interval int `json:"interval"` RootDir string `json:"directory"` @@ -232,25 +233,29 @@ func main() { intervals(&wg, ctx) - wg.Add(2) + wg.Add(1) go func() { - err := StartApiServer(":8080", ctx) + err := StartApiServer(conf.HttpApiAddress, ctx) if err != nil { log.Fatal(err) } wg.Done() }() - go func() { - // err := ReceiveNats(conf.Nats, handleLine, runtime.NumCPU()-1, ctx) - err := ReceiveNats(conf.Nats, handleLine, 1, ctx) + if len(conf.Nats) != 0 { + wg.Add(1) - if err != nil { - log.Fatal(err) - } - wg.Done() - }() + go func() { + // err := ReceiveNats(conf.Nats, handleLine, runtime.NumCPU()-1, ctx) + err := ReceiveNats(conf.Nats, handleLine, 1, ctx) + + if err != nil { + log.Fatal(err) + } + wg.Done() + }() + } wg.Wait()