Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
remove daily health
Browse files Browse the repository at this point in the history
  • Loading branch information
Alextopher committed Sep 24, 2023
1 parent 5c45739 commit 2d1c4d8
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 407 deletions.
2 changes: 1 addition & 1 deletion aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Aggregator[T any] interface {

// StartAggregator starts the aggregator with the given Aggregator implementation, channel of type T, influxdb QueryAPI and WriteAPI.
// It returns the lastUpdated time and an error if any occurred during initialization.
func StartAggregator[T any](aggregator Aggregator[T], c <-chan T, reader api.QueryAPI, writer api.WriteAPI) (lastUpdated time.Time, err error) {
func StartAggregator[T any](aggregator Aggregator[T], c <-chan T) (lastUpdated time.Time, err error) {
lastUpdated, err = aggregator.Init(reader)
if err != nil {
return lastUpdated, err
Expand Down
151 changes: 0 additions & 151 deletions daily_health.go

This file was deleted.

4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/joho/godotenv v1.5.1
github.com/nxadm/tail v1.4.8
github.com/pelletier/go-toml/v2 v2.1.0
github.com/wcharczuk/go-chart/v2 v2.1.1
github.com/xeipuuv/gojsonschema v1.2.0
)

Expand All @@ -31,7 +30,6 @@ require (
github.com/antchfx/xpath v1.2.4 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/blend/go-sdk v1.20220411.3 // indirect
github.com/bytedance/sonic v1.10.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
Expand All @@ -47,7 +45,6 @@ require (
github.com/go-playground/validator/v10 v10.15.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down Expand Up @@ -96,7 +93,6 @@ require (
github.com/yosssi/ace v0.0.5 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/image v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7D
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/blend/go-sdk v1.20220411.3 h1:GFV4/FQX5UzXLPwWV03gP811pj7B8J2sbuq+GJQofXc=
github.com/blend/go-sdk v1.20220411.3/go.mod h1:7lnH8fTi6U4i1fArEXRyOIY2E1X4MALg09qsQqY1+ak=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
Expand Down Expand Up @@ -84,8 +82,6 @@ github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI=
github.com/gocolly/colly v1.2.0/go.mod h1:Hof5T3ZswNVsOHYmba1u03W65HDWgpV5HifSuueE0EA=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
Expand Down Expand Up @@ -233,8 +229,6 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/wcharczuk/go-chart/v2 v2.1.1 h1:2u7na789qiD5WzccZsFz4MJWOJP72G+2kUuJoSNqWnE=
github.com/wcharczuk/go-chart/v2 v2.1.1/go.mod h1:CyCAUt2oqvfhCl6Q5ZvAZwItgpQKZOkCJGb+VGv6l14=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand All @@ -260,9 +254,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
golang.org/x/image v0.12.0 h1:w13vZbU4o5rKOFFR8y7M+c4A5jXDC0uXTdHYRP8X2DQ=
golang.org/x/image v0.12.0/go.mod h1:Lu90jvHG7GfemOIcldsh9A2hS01ocl6oNO7ype5mEnk=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand Down Expand Up @@ -318,7 +309,6 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
Expand Down
144 changes: 0 additions & 144 deletions influx.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package main

import (
"context"
"crypto/tls"
"fmt"
"sort"

"github.com/COSI-Lab/Mirror/logging"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/influxdata/influxdb-client-go/v2/api"
)
Expand All @@ -27,143 +23,3 @@ func SetupInfluxClients(token string) {
}
reader = client.QueryAPI("COSI")
}

// QueryBytesSentByProject gets the bytes sent by each project in the last 24 hours
func QueryBytesSentByProject() (map[string]int64, error) {
// Map from short names to bytes sent
bytesSent := make(map[string]int64)

// You can paste this into the influxdb data explorer
/*
from(bucket: "stats")
|> range(start: -24h, stop: now())
|> filter(fn: (r) => r["_measurement"] == "mirror")
|> filter(fn: (r) => r["_field"] == "bytes_sent")
|> spread()
|> yield(name: "spread")
*/
result, err := reader.Query(context.Background(), "from(bucket: \"stats\") |> range(start: -24h, stop: now()) |> filter(fn: (r) => r[\"_measurement\"] == \"mirror\") |> filter(fn: (r) => r[\"_field\"] == \"bytes_sent\") |> spread() |> yield(name: \"spread\")")

if err != nil {
return nil, err
}

for result.Next() {
if result.Err() == nil {
// Get the data point
dp := result.Record()

// Get the project short name
project, ok := dp.ValueByKey("distro").(string)
if !ok {
logging.Warn("Error getting distro short name")
fmt.Printf("%T %v\n", project, project)
continue
}

// Get the bytes sent
sent, ok := dp.ValueByKey("_value").(int64)
if !ok {
logging.Warn("Error getting bytes sent")
fmt.Printf("%T %v\n", dp.ValueByKey("_value"), dp.ValueByKey("_value"))
continue
}

bytesSent[project] = sent
} else {
logging.Warn("InitNGINXStats Flux Query Error", result.Err())
}
}

return bytesSent, nil
}

// LineChart is a type for sorting data needed to create a line chart
type LineChart struct {
Sent []float64
Recv []float64
Times []int64
}

func (l *LineChart) Len() int {
return len(l.Sent)
}

func (l *LineChart) Swap(i, j int) {
l.Sent[i], l.Sent[j] = l.Sent[j], l.Sent[i]
l.Recv[i], l.Recv[j] = l.Recv[j], l.Recv[i]
l.Times[i], l.Times[j] = l.Times[j], l.Times[i]
}

func (l *LineChart) Less(i, j int) bool {
return l.Times[i] < l.Times[j]
}

// QueryWeeklyNetStats gets the bytes sent and received by the server in the last week
// Aggregates the data into 1 hour intervals
func QueryWeeklyNetStats() (line *LineChart, err error) {
// You can paste this into the influxdb data explorer
/*
from(bucket: "system")
|> range(start: -7d, stop: now())
|> filter(fn: (r) => r["_measurement"] == "net" and r["interface"] == "enp8s0")
|> filter(fn: (r) => r["_field"] == "bytes_sent" or r["_field"] == "bytes_recv")
|> aggregateWindow(every: 1h, fn: last)
|> derivative(unit: 1s, nonNegative: true)
|> yield(name: "nonnegative derivative")
*/
result, err := reader.Query(context.Background(), "from(bucket: \"system\") |> range(start: -7d, stop: now()) |> filter(fn: (r) => r[\"_measurement\"] == \"net\" and r[\"interface\"] == \"enp8s0\") |> filter(fn: (r) => r[\"_field\"] == \"bytes_sent\" or r[\"_field\"] == \"bytes_recv\") |> aggregateWindow(every: 1h, fn: last) |> derivative(unit: 1s, nonNegative: true) |> yield(name: \"nonnegative derivative\")")

if err != nil {
return nil, err
}

sent := make([]float64, 0)
recv := make([]float64, 0)
times := make([]int64, 0)

for result.Next() {
if result.Err() == nil {
// Get the data point
dp := result.Record()

// Get the field
field, ok := dp.ValueByKey("_field").(string)
if !ok {
logging.Warn("Error getting field")
fmt.Printf("%T %v\n", field, field)
continue
}

// Get the value
value, ok := dp.ValueByKey("_value").(float64)
if !ok {
logging.Warn("Error getting value")
fmt.Printf("%T %v\n", value, value)
continue
}

switch field {
case "bytes_sent":
sent = append(sent, value)
case "bytes_recv":
recv = append(recv, value)
times = append(times, dp.Time().Unix())
}
} else {
logging.Warn("InitNGINXStats Flux Query Error", result.Err())
}
}

line = &LineChart{
Sent: sent,
Recv: recv,
Times: times,
}

fmt.Println(len(sent), len(recv), len(times))

sort.Sort(line)

return line, nil
}
Loading

0 comments on commit 2d1c4d8

Please sign in to comment.