Skip to content

Commit

Permalink
Update README to reflect recent code changes. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jharshman committed May 7, 2021
1 parent be9744d commit c71b862
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
42 changes: 17 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ More information on authentication can be found in the offical [Google Cloud doc

## Query
tsplot helps to facilitate easy querying of the Google Cloud Monitoring API for time series matching the supplied criteria.
In addition it provides methods of overriding certain aspects of the query.

For example, the following code snippet will return a single time series for the following metric descriptor: `custom.googleapis.com/opencensus/fishnet/queuereader_fishnet/messages_total`.
```
Expand All @@ -27,50 +28,43 @@ func main() {
EndTime: now
}
if err := mq.BuildRequest(); err != nil {
fmt.Printf("error building request: %v\n", err)
os.Exit(1)
}
tsi, err := mq.Perform(client)
// enable cross series reducer
query.SetReduce(true)
tsi, err := mq.PerformWithClient(client)
if err != nil {
fmt.Printf("error performing query: %v\n", err)
os.Exit(1)
}
```

## Plotting
To plot the data, tsplot leverages the opensource package [gonum/plot](github.com/gonum/plot) to create a graph and plot the data for a given time series.
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() {
var tsGroup tsplot.TimeSeries
metric := messages_total
... snip ...
// Assuming the request returned a singular time series in the time series iterator.
// grab the first time series from the iterator.
timeSeries := tsi.Next()
ts := tsplot.TimeSeries{}
timeSeries, _ := tsi.Next()
ts[metric] = ts.GetPoints()
plot := tsplot.TimeSeriesPlot{
Name: timeSeries.GetMetric().GetType(),
XAxisName: "", // if empty, defaults to "UTC"
YAxisName: "", // optional label for Y axis
Description: "", // optional description
TimeSeries: ts,
}
timeSeriesPlot, err := plot.Create()
// 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 {
fmt.Printf("err creating plot: %v\n", err)
os.Exit(1)
return err
}
// optionally save the plot to disk
timeSeriesPlot.Save(8*vg.Inch, 4*vg.Inch, "./my-graph.png")
p.Save(8*vg.Inch, 4*vg.Inch, "./my-graph.png")
}
```

Expand All @@ -79,5 +73,3 @@ I'm not a UX designer, but I have selected colors that I find higher contrast
and easier to see. I am basing this completely off my colorblindness which is
unique to me. Improvements to the color palette used are welcome.

#### Limitations
Although `tsplot` allows multiple time series to be plotted on a singular graph the limit is currently four lines. This is because the current color palette for the lines only contains four colors.
20 changes: 12 additions & 8 deletions tscli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ Usage:
tscli [flags]
Flags:
-a, --app string The (Bitly) application. Usually top level directory
--end string 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. (default "now")
-h, --help help for tscli
-m, --metric string The metric.
--print-raw Only print time series data and exit.
-p, --project string GCP Project.
-s, --service string The (Bitly) service. Service directory found under application directory.
--start string Start time of window for which the query returns time series data for. Hours or minutes accepted, i.e: -5h or -5m.
-a, --app string The (Bitly) application. Usually top level directory
--end string 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. (default "now")
-h, --help help for tscli
-m, --metric string The metric.
-o, --output string Specify output directory for resulting plot. Defaults to current working directory.
--print-raw Only print time series data and exit.
-p, --project string GCP Project.
--query-override string Override the default query. Must be a full valid query. Metric flag is not used.
--reduce Use a time series reducer to return a single averaged result.
-s, --service string The (Bitly) service. Service directory found under application directory.
--start string Start time of window for which the query returns time series data for. Hours or minutes accepted, i.e: -5h or -5m.
```

## Authentication
Expand Down

0 comments on commit c71b862

Please sign in to comment.