Skip to content

Commit

Permalink
testing graphing of multiple time series on a single plot.
Browse files Browse the repository at this point in the history
  • Loading branch information
jharshman committed Dec 12, 2023
1 parent ca4ce3e commit 318279f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 8 additions & 1 deletion tscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,19 @@ func executeQuery(cmd *cobra.Command, args []string) error {
// todo: these need to be settable as they are not uniformly useful across all metric types.
PerSeriesAligner: monitoringpb.Aggregation_ALIGN_RATE,
CrossSeriesReducer: monitoringpb.Aggregation_REDUCE_MEAN,
GroupByFields: []string{"metric.labels.classification"},
},
View: monitoringpb.ListTimeSeriesRequest_FULL,
}

tsi := GoogleCloudMonitoringClient.ListTimeSeries(context.Background(), request)
// todo: handle multiple time series
ts, err := tsi.Next()
plot, err := tsplot.NewPlotFromTimeSeriesIterator(tsi)
if err != nil {
log.Fatal(err)
}

/*ts, err := tsi.Next()
if err != nil {
log.Fatal(err)
}
Expand All @@ -128,6 +134,7 @@ func executeQuery(cmd *cobra.Command, args []string) error {
if err != nil {
log.Fatal(err)
}
*/

saveFile := fmt.Sprintf("%s/test.png", "/tmp/")
return plot.Save(8*vg.Inch, 4*vg.Inch, saveFile)
Expand Down
15 changes: 9 additions & 6 deletions tsplot/plot.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package tsplot

import (
monitoring "cloud.google.com/go/monitoring/apiv3/v2"
"fmt"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"google.golang.org/api/iterator"
"google.golang.org/genproto/googleapis/api/metric"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
)
Expand Down Expand Up @@ -70,9 +72,8 @@ func NewPlotFromTimeSeries(ts *monitoringpb.TimeSeries, opts ...PlotOption) (*pl
return p, nil
}

/*
func NewPlotFromTimeSeriesIterator(tsi monitoring.TimeSeriesIterator) (*plot.Plot, error) {
var ts *monitoringpb.TimeSeries
func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator) (*plot.Plot, error) {
p := plot.New()
for {
timeSeries, err := tsi.Next()
if err != nil {
Expand All @@ -81,12 +82,14 @@ func NewPlotFromTimeSeriesIterator(tsi monitoring.TimeSeriesIterator) (*plot.Plo
}
return nil, err
}
ts = timeSeries
line, _ := createLine(timeSeries.GetPoints())
p.Y.Max = 400 // todo: make dynamic according to data
p.Add(line)
}

return nil, nil
return p, nil
}
*/

// createLine creates a line from data points.
func createLine(dataPoints []*monitoringpb.Point) (*plotter.Line, error) {
var XYs plotter.XYs
Expand Down

0 comments on commit 318279f

Please sign in to comment.