metrics improvements (#234)

This commit is contained in:
Michael Quigley 2023-05-11 15:56:29 -04:00
parent d1688c450d
commit ce4eac8e4c
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 21 additions and 13 deletions

View File

@ -227,14 +227,21 @@ func runFluxForRxTxArray(query string, queryApi api.QueryAPI) (rx, tx, timestamp
return nil, nil, nil, err
}
for result.Next() {
if v, ok := result.Record().Value().(int64); ok {
switch result.Record().Field() {
case "rx":
rx = append(rx, float64(v))
timestamps = append(timestamps, float64(result.Record().Time().UnixMilli()))
case "tx":
tx = append(tx, float64(v))
switch result.Record().Field() {
case "rx":
rxV := int64(0)
if v, ok := result.Record().Value().(int64); ok {
rxV = v
}
rx = append(rx, float64(rxV))
timestamps = append(timestamps, float64(result.Record().Time().UnixMilli()))
case "tx":
txV := int64(0)
if v, ok := result.Record().Value().(int64); ok {
txV = v
}
tx = append(tx, float64(txV))
}
}
return rx, tx, timestamps, nil
@ -245,9 +252,9 @@ func sliceSize(duration time.Duration) time.Duration {
case 30 * 24 * time.Hour:
return 24 * time.Hour
case 7 * 24 * time.Hour:
return 20 * time.Minute
return 4 * time.Hour
case 24 * time.Hour:
return 5 * time.Minute
return 30 * time.Minute
default:
return duration
}

View File

@ -50,8 +50,8 @@ const MetricsGraph = (props) => {
<CartesianGrid strokeDasharay={"3 3"} />
<XAxis dataKey={(v) => v.timestamp} scale={"time"} tickFormatter={(v) => moment(v).format("MMM DD") } style={{ fontSize: '75%'}}/>
<YAxis tickFormatter={(v) => bytesToSize(v)} style={{ fontSize: '75%' }}/>
<Bar stroke={"#231069"} fill={"#04adef"} dataKey={"rx"} />
<Bar stroke={"#231069"} fill={"#9BF316"} dataKey={"tx"} />
<Bar stroke={"#231069"} fill={"#04adef"} dataKey={(v) => v.rx ? v.rx : 0} />
<Bar stroke={"#231069"} fill={"#9BF316"} dataKey={(v) => v.tx ? v.tx : 0} />
<Tooltip />
</BarChart>
</ResponsiveContainer>

View File

@ -1,4 +1,5 @@
export const buildMetrics = (m) => {
console.log("build", m);
let metrics = {
data: m.samples,
rx: 0,
@ -6,8 +7,8 @@ export const buildMetrics = (m) => {
}
if(m.samples) {
m.samples.forEach(s => {
metrics.rx += s.rx;
metrics.tx += s.tx;
metrics.rx += s.rx ? s.rx : 0;
metrics.tx += s.tx ? s.tx : 0;
});
}
return metrics;