cc-backend/schema/metrics.go

79 lines
1.8 KiB
Go
Raw Normal View History

2021-10-26 10:22:02 +02:00
package schema
import (
"fmt"
"io"
)
2022-01-07 09:39:00 +01:00
type JobData map[string]map[MetricScope]*JobMetric
2021-10-26 10:22:02 +02:00
type JobMetric struct {
2022-01-07 09:39:00 +01:00
Unit string `json:"unit"`
Scope MetricScope `json:"scope"`
Timestep int `json:"timestep"`
Series []Series `json:"series"`
StatisticsSeries *StatsSeries `json:"statisticsSeries"`
2021-12-17 15:49:22 +01:00
}
type Series struct {
Hostname string `json:"hostname"`
Id *int `json:"id,omitempty"`
Statistics *MetricStatistics `json:"statistics"`
Data []Float `json:"data"`
}
type MetricStatistics struct {
Avg float64 `json:"avg"`
Min float64 `json:"min"`
Max float64 `json:"max"`
}
type StatsSeries struct {
2022-01-07 09:39:00 +01:00
Mean []Float `json:"mean"`
Min []Float `json:"min"`
Max []Float `json:"max"`
2021-12-17 15:49:22 +01:00
Percentiles map[int][]Float `json:"percentiles,omitempty"`
2021-10-26 10:22:02 +02:00
}
type MetricScope string
const (
2022-01-07 09:39:00 +01:00
MetricScopeNode MetricScope = "node"
MetricScopeSocket MetricScope = "socket"
MetricScopeCpu MetricScope = "cpu"
MetricScopeHWThread MetricScope = "hwthread"
2021-10-26 10:22:02 +02:00
)
2022-01-07 09:39:00 +01:00
var metricScopeGranularity map[MetricScope]int = map[MetricScope]int{
MetricScopeNode: 1,
MetricScopeSocket: 2,
MetricScopeCpu: 3,
MetricScopeHWThread: 4,
}
func (e *MetricScope) MaxGranularity(other MetricScope) MetricScope {
a := metricScopeGranularity[*e]
b := metricScopeGranularity[other]
if a < b {
return *e
}
return other
}
2021-10-26 10:22:02 +02:00
func (e *MetricScope) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = MetricScope(str)
2022-01-07 09:39:00 +01:00
if _, ok := metricScopeGranularity[*e]; !ok {
2021-10-26 10:22:02 +02:00
return fmt.Errorf("%s is not a valid MetricScope", str)
}
return nil
}
func (e MetricScope) MarshalGQL(w io.Writer) {
fmt.Fprintf(w, "\"%s\"", e)
}