Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jharshman committed Dec 11, 2023
1 parent 06f0602 commit 2ee8f60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 154 deletions.
72 changes: 19 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/bitly/tsplot)](https://goreportcard.com/report/github.com/bitly/tsplot)
[![Go Reference](https://pkg.go.dev/badge/github.com/bitly/tsplot.svg)](https://pkg.go.dev/github.com/bitly/tsplot)

This package provides a method of querying for raw time series data from the GCM APIs and additionally plotting that data for use in other applications.

This came to be due to what we consider a small limitation in the Google APIs which require us to re-draw graphs to include them in other applications such as
Slack bots. There is no facility in the Google API that provides a PNG of already graphed data.

## Authentication
This package makes no effort to assist in authentication to the Google APIs.
Instead, it will expect the caller to supply an authenticated client.
Expand All @@ -16,60 +11,31 @@ More information on authentication can be found in the official [Google Cloud do
func main() {
... snip ...
start := time.Now().Add(-1 * time.Hour)
end := time.Now()
// create new request
request := tsplot.GCMTimeSeriesRequester{ListTimeSeriesRequest: monitoringpb.ListTimeSeriesRequest{
Name: fmt.Sprintf("projects/%s", project),
Filter: query,
Interval: &monitoringpb.TimeInterval{
EndTime: timestamppb.New(et),
StartTime: timestamppb.New(st),
},
Aggregation: nil,
SecondaryAggregation: nil,
View: monitoringpb.ListTimeSeriesRequest_FULL,
}}
// disable cross series reducer (MEAN reduction is default)
request.Set_REDUCE_NONE()
// set different alignment window. (Default is 1 minute)
request.SetAlignmentPeriod(time.Minute * 5)
tsi := request.Do(client) // client is provided by user
}
```
## Plotting
To plot the data, tsplot leverages the open source package [gonum/plot](github.com/gonum/plot) to create a graph and plot the data for a given time series.

The example below creates a new graph containing a singular time series, plots it, and saves the resulting plot to disk.
```
func main() {
... snip ...
ts := tsplot.TimeSeries{}
// create new request
request := monitoringpb.ListTimeSeriesRequest{
Name: fmt.Sprintf("projects/%s", project),
Filter: query,
Interval: &monitoringpb.TimeInterval{
EndTime: timestamppb.New(et),
StartTime: timestamppb.New(st),
},
Aggregation: nil,
SecondaryAggregation: nil,
View: monitoringpb.ListTimeSeriesRequest_FULL,
}
// optionally iterate over returned time series
timeSeries, _ := tsi.Next()
ts[metric] = ts.GetPoints()
// execute the request and get the response from Google APIs
tsi := GoogleCloudMonitoringClient.ListTimeSeries(context.Background(), request)
// create the plot with some formatting options
p, err := ts.Plot([]tsplot.PlotOption{
tsplot.WithXAxisName("UTC"),
tsplot.WIthGrid(colornames.Darkgrey),
tsplot.WithTitle(metric)}...)
if err != nil {
return err
}
// Create the plot from the GAPI TimeSeries
plot, _ := tsplot.NewPlotFromTimeSeriesIterator(tsi)
// optionally save the plot to disk
p.Save(8*vg.Inch, 4*vg.Inch, "./my-graph.png")
// Save the new plot to disk.
plot.Save(8*vg.Inch, 4*vg.Inch, "my_plot.png")
}
```

Expand Down
101 changes: 0 additions & 101 deletions scripts/codegen.go

This file was deleted.

0 comments on commit 2ee8f60

Please sign in to comment.