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 5895519
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 330 deletions.
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
70 changes: 0 additions & 70 deletions influx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/tls"
"fmt"
"sort"

"github.com/COSI-Lab/Mirror/logging"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
Expand Down Expand Up @@ -98,72 +97,3 @@ func (l *LineChart) Swap(i, j int) {
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
}
46 changes: 23 additions & 23 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,55 +46,62 @@ func (mt messageType) String() string {
}
}

// LogEntryT enables programmatic creation of log entries
type LogEntryT struct {
// LogEntry enables programmatic creation of log entries
type LogEntry struct {
typ messageType
time time.Time
message string
}

// NewLogEntry creates a new LogEntryT with the current time
func NewLogEntry(mt messageType, message string) LogEntryT {
return LogEntryT{
// NewLogEntry creates a new LogEntry with the current time
func NewLogEntry(mt messageType, message string) LogEntry {
return LogEntry{
typ: mt,
time: time.Now(),
message: message,
}
}

// InfoLogEntry creates a new LogEntryT with the current time and [INFO] tag
func InfoLogEntry(message string) LogEntryT {
// InfoLogEntry creates a new LogEntry with the current time and [INFO] tag
func InfoLogEntry(message string) LogEntry {
return NewLogEntry(InfoT, message)
}

// WarnLogEntry creates a new LogEntryT with the current time and [WARN] tag
func WarnLogEntry(message string) LogEntryT {
// WarnLogEntry creates a new LogEntry with the current time and [WARN] tag
func WarnLogEntry(message string) LogEntry {
return NewLogEntry(WarnT, message)
}

// ErrorLogEntry creates a new LogEntryT with the current time and [ERROR] tag
func ErrorLogEntry(message string) LogEntryT {
// ErrorLogEntry creates a new LogEntry with the current time and [ERROR] tag
func ErrorLogEntry(message string) LogEntry {
return NewLogEntry(ErrorT, message)
}

// PanicLogEntry creates a new LogEntryT with the current time and [PANIC] tag
func PanicLogEntry(message string) LogEntryT {
// PanicLogEntry creates a new LogEntry with the current time and [PANIC] tag
func PanicLogEntry(message string) LogEntry {
return NewLogEntry(PanicT, message)
}

// SuccessLogEntry creates a new LogEntryT with the current time and [SUCCESS] tag
func SuccessLogEntry(message string) LogEntryT {
// SuccessLogEntry creates a new LogEntry with the current time and [SUCCESS] tag
func SuccessLogEntry(message string) LogEntry {
return NewLogEntry(SuccessT, message)
}

func (le LogEntryT) String() string {
func (le LogEntry) String() string {
if le.message[len(le.message)-1] != '\n' {
return fmt.Sprintf("%s %s %s\n", time.Now().Format(tm), le.typ.String(), le.message)
}

return fmt.Sprintf("%s %s %s", time.Now().Format(tm), le.typ.String(), le.message)
}

// Log prints the log entry to stdout
func (le LogEntry) Log() {
logger.Lock()
fmt.Print(le.String())
logger.Unlock()
}

func logf(mt messageType, format string, v ...interface{}) {
logger.Lock()
if format[len(format)-1] != '\n' {
Expand Down Expand Up @@ -172,10 +179,3 @@ func Logf(mt messageType, format string, v ...interface{}) {
func Log(mt messageType, v ...interface{}) {
logln(mt, v...)
}

// LogEntry logs a LogEntryT
func LogEntry(le LogEntryT) {
logger.Lock()
fmt.Print(le.String())
logger.Unlock()
}
Loading

0 comments on commit 5895519

Please sign in to comment.