Skip to content

Commit

Permalink
update flags for tscli
Browse files Browse the repository at this point in the history
  • Loading branch information
jharshman committed Dec 14, 2023
1 parent 54f14a9 commit 3af0e29
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions tscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ from Google Cloud Monitoring (formerly StackDriver).
startTime string
endTime string
outDir string
title string
groupBy string
)

func init() {
Expand All @@ -63,9 +65,13 @@ func init() {
rootCmd.Flags().StringVar(&startTime, "start", "", "Start time of window for which the query returns time series data for. Hours or minutes accepted, i.e: -5h or -5m.")
rootCmd.Flags().StringVar(&endTime, "end", "now", "End of the time window for which the query returns time series data for. Hours or minutes accepted, i.e: -5h or -5m or now.")
rootCmd.Flags().StringVarP(&outDir, "output", "o", "", "Specify output directory for resulting plot. Defaults to current working directory.")
rootCmd.Flags().StringVarP(&title, "title", "t", "", "Specify title of graph.")
rootCmd.Flags().StringVar(&groupBy, "group-by", "", "Key to group metric by when dealing with multiple time series.")
rootCmd.MarkFlagRequired("project")
rootCmd.MarkFlagRequired("query")
rootCmd.MarkFlagRequired("start")
rootCmd.MarkFlagRequired("title")
rootCmd.MarkFlagRequired("output")
}

func auth(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -113,30 +119,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"},
GroupByFields: []string{fmt.Sprintf("metric.labels.%s", groupBy)},
},
View: monitoringpb.ListTimeSeriesRequest_FULL,
}

tsi := GoogleCloudMonitoringClient.ListTimeSeries(context.Background(), request)
// todo: handle multiple time series
plot, err := tsplot.NewPlotFromTimeSeriesIterator(tsi, "classification", tsplot.WithXTimeTicks(time.Kitchen), tsplot.WithTitle("decodes"), tsplot.WithXAxisName("UTC"))
plot, err := tsplot.NewPlotFromTimeSeriesIterator(tsi, groupBy, tsplot.WithXTimeTicks(time.Kitchen), tsplot.WithTitle(title), tsplot.WithXAxisName("UTC"))
if err != nil {
log.Fatal(err)
}

/*ts, err := tsi.Next()
if err != nil {
log.Fatal(err)
}
plot, err := tsplot.NewPlotFromTimeSeries(ts, tsplot.WithXTimeTicks(time.Kitchen), tsplot.WithXAxisName("UTC"), tsplot.WithTitle("decodes_raw"))
if err != nil {
log.Fatal(err)
}
*/

saveFile := fmt.Sprintf("%s/test.png", "/tmp/")
saveFile := fmt.Sprintf("%s/%s.png", outDir, title)
return plot.Save(8*vg.Inch, 4*vg.Inch, saveFile)
}

Expand Down

0 comments on commit 3af0e29

Please sign in to comment.