Debian Codegraph @

cloudapi/instrumentations.go

raw symbols SCIP
1 package cloudapi
2
3 import (
4 "net/http"
5
6 "github.com/joyent/gocommon/client"
7 "github.com/joyent/gocommon/errors"
8 )
9
10 // Analytics represents the available analytics
11 type Analytics struct {
12 Modules map[string]interface{} // Namespace to organize metrics
13 Fields map[string]interface{} // Fields represent metadata by which data points can be filtered or decomposed
14 Types map[string]interface{} // Types are used with both metrics and fields for two purposes: to hint to clients at how to best label values, and to distinguish between numeric and discrete quantities.
15 Metrics map[string]interface{} // Metrics describe quantities which can be measured by the system
16 Transformations map[string]interface{} // Transformations are post-processing functions that can be applied to data when it's retrieved.
17 }
18
19 // Instrumentation specify which metric to collect, how frequently to aggregate data (e.g., every second, every hour, etc.)
20 // how much data to keep (e.g., 10 minutes' worth, 6 months' worth, etc.) and other configuration options
21 type Instrumentation struct {
22 Module string `json:"module"`
23 Stat string `json:"stat"`
24 Predicate string `json:"predicate"`
25 Decomposition []string `json:"decomposition"`
26 ValueDimension int `json:"value-dimenstion"`
27 ValueArity string `json:"value-arity"`
28 RetentionTime int `json:"retention-time"`
29 Granularity int `json:"granularitiy"`
30 IdleMax int `json:"idle-max"`
31 Transformations []string `json:"transformations"`
32 PersistData bool `json:"persist-data"`
33 Crtime int `json:"crtime"`
34 ValueScope string `json:"value-scope"`
35 Id string `json:"id"`
36 Uris []Uri `json:"uris"`
37 }
38
39 // Uri represents a Universal Resource Identifier
40 type Uri struct {
41 Uri string // Resource identifier
42 Name string // URI name
43 }
44
45 // InstrumentationValue represents the data associated to an instrumentation for a point in time
46 type InstrumentationValue struct {
47 Value interface{}
48 Transformations map[string]interface{}
49 StartTime int
50 Duration int
51 }
52
53 // HeatmapOpts represent the option that can be specified
54 // when retrieving an instrumentation.'s heatmap
55 type HeatmapOpts struct {
56 Height int `json:"height"` // Height of the image in pixels
57 Width int `json:"width"` // Width of the image in pixels
58 Ymin int `json:"ymin"` // Y-Axis value for the bottom of the image (default: 0)
59 Ymax int `json:"ymax"` // Y-Axis value for the top of the image (default: auto)
60 Nbuckets int `json:"nbuckets"` // Number of buckets in the vertical dimension
61 Selected []string `json:"selected"` // Array of field values to highlight, isolate or exclude
62 Isolate bool `json:"isolate"` // If true, only draw selected values
63 Exclude bool `json:"exclude"` // If true, don't draw selected values at all
64 Hues []string `json:"hues"` // Array of colors for highlighting selected field values
65 DecomposeAll bool `json:"decompose_all"` // Highlight all field values
66 X int `json:"x"`
67 Y int `json:"y"`
68 }
69
70 // Heatmap represents an instrumentation's heatmap
71 type Heatmap struct {
72 BucketTime int `json:"bucket_time"` // Time corresponding to the bucket (Unix seconds)
73 BucketYmin int `json:"bucket_ymin"` // Minimum y-axis value for the bucket
74 BucketYmax int `json:"bucket_ymax"` // Maximum y-axis value for the bucket
75 Present map[string]interface{} `json:"present"` // If the instrumentation defines a discrete decomposition, this property's value is an object whose keys are values of that field and whose values are the number of data points in that bucket for that key
76 Total int `json:"total"` // The total number of data points in the bucket
77 }
78
79 // CreateInstrumentationOpts represent the option that can be specified
80 // when creating a new instrumentation.
81 type CreateInstrumentationOpts struct {
82 Clone int `json:"clone"` // An existing instrumentation ID to be cloned
83 Module string `json:"module"` // Analytics module
84 Stat string `json:"stat"` // Analytics stat
85 Predicate string `json:"predicate"` // Instrumentation predicate, must be JSON string
86 Decomposition string `json:"decomposition"`
87 Granularity int `json:"granularity"` // Number of seconds between data points (default is 1)
88 RetentionTime int `json:"retention-time"` // How long to keep this instrumentation data for
89 PersistData bool `json:"persist-data"` // Whether or not to store this for historical analysis
90 IdleMax int `json:"idle-max"` // Number of seconds after which if the instrumentation or its data has not been accessed via the API the service may delete the instrumentation and its data
91 }
92
93 // DescribeAnalytics retrieves the "schema" for instrumentations that can be created.
94 // See API docs: http://apidocs.joyent.com/cloudapi/#DescribeAnalytics
95 func (c *Client) DescribeAnalytics() (*Analytics, error) {
96 var resp Analytics
97 req := request{
98 method: client.GET,
99 url: apiAnalytics,
100 resp: &resp,
101 }
102 if _, err := c.sendRequest(req); err != nil {
103 return nil, errors.Newf(err, "failed to get analytics")
104 }
105 return &resp, nil
106 }
107
108 // ListInstrumentations retrieves all currently created instrumentations.
109 // See API docs: http://apidocs.joyent.com/cloudapi/#ListInstrumentations
110 func (c *Client) ListInstrumentations() ([]Instrumentation, error) {
111 var resp []Instrumentation
112 req := request{
113 method: client.GET,
114 url: makeURL(apiAnalytics, apiInstrumentations),
115 resp: &resp,
116 }
117 if _, err := c.sendRequest(req); err != nil {
118 return nil, errors.Newf(err, "failed to get instrumentations")
119 }
120 return resp, nil
121 }
122
123 // GetInstrumentation retrieves the configuration for the specified instrumentation.
124 // See API docs: http://apidocs.joyent.com/cloudapi/#GetInstrumentation
125 func (c *Client) GetInstrumentation(instrumentationID string) (*Instrumentation, error) {
126 var resp Instrumentation
127 req := request{
128 method: client.GET,
129 url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID),
130 resp: &resp,
131 }
132 if _, err := c.sendRequest(req); err != nil {
133 return nil, errors.Newf(err, "failed to get instrumentation with id %s", instrumentationID)
134 }
135 return &resp, nil
136 }
137
138 // GetInstrumentationValue retrieves the data associated to an instrumentation
139 // for a point in time.
140 // See API docs: http://apidocs.joyent.com/cloudapi/#GetInstrumentationValue
141 func (c *Client) GetInstrumentationValue(instrumentationID string) (*InstrumentationValue, error) {
142 var resp InstrumentationValue
143 req := request{
144 method: client.GET,
145 url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID, apiInstrumentationsValue, apiInstrumentationsRaw),
146 resp: &resp,
147 }
148 if _, err := c.sendRequest(req); err != nil {
149 return nil, errors.Newf(err, "failed to get value for instrumentation with id %s", instrumentationID)
150 }
151 return &resp, nil
152 }
153
154 // GetInstrumentationHeatmap retrieves the specified instrumentation's heatmap.
155 // See API docs: http://apidocs.joyent.com/cloudapi/#GetInstrumentationHeatmap
156 func (c *Client) GetInstrumentationHeatmap(instrumentationID string) (*Heatmap, error) {
157 var resp Heatmap
158 req := request{
159 method: client.GET,
160 url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID, apiInstrumentationsValue, apiInstrumentationsHeatmap, apiInstrumentationsImage),
161 resp: &resp,
162 }
163 if _, err := c.sendRequest(req); err != nil {
164 return nil, errors.Newf(err, "failed to get heatmap image for instrumentation with id %s", instrumentationID)
165 }
166 return &resp, nil
167 }
168
169 // GetInstrumentationHeatmapDetails allows you to retrieve the bucket details
170 // for a heatmap.
171 // See API docs: http://apidocs.joyent.com/cloudapi/#GetInstrumentationHeatmapDetails
172 func (c *Client) GetInstrumentationHeatmapDetails(instrumentationID string) (*Heatmap, error) {
173 var resp Heatmap
174 req := request{
175 method: client.GET,
176 url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID, apiInstrumentationsValue, apiInstrumentationsHeatmap, apiInstrumentationsDetails),
177 resp: &resp,
178 }
179 if _, err := c.sendRequest(req); err != nil {
180 return nil, errors.Newf(err, "failed to get heatmap details for instrumentation with id %s", instrumentationID)
181 }
182 return &resp, nil
183 }
184
185 // CreateInstrumentation Creates an instrumentation. You can clone an existing
186 // instrumentation by passing in the parameter clone, which should be a numeric id
187 // of an existing instrumentation.
188 // See API docs: http://apidocs.joyent.com/cloudapi/#CreateInstrumentation
189 func (c *Client) CreateInstrumentation(opts CreateInstrumentationOpts) (*Instrumentation, error) {
190 var resp Instrumentation
191 req := request{
192 method: client.POST,
193 url: makeURL(apiAnalytics, apiInstrumentations),
194 reqValue: opts,
195 resp: &resp,
196 expectedStatus: http.StatusCreated,
197 }
198 if _, err := c.sendRequest(req); err != nil {
199 return nil, errors.Newf(err, "failed to create instrumentation")
200 }
201 return &resp, nil
202 }
203
204 // DeleteInstrumentation destroys an instrumentation.
205 // See API docs: http://apidocs.joyent.com/cloudapi/#DeleteInstrumentation
206 func (c *Client) DeleteInstrumentation(instrumentationID string) error {
207 req := request{
208 method: client.DELETE,
209 url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID),
210 expectedStatus: http.StatusNoContent,
211 }
212 if _, err := c.sendRequest(req); err != nil {
213 return errors.Newf(err, "failed to delete instrumentation with id %s", instrumentationID)
214 }
215 return nil
216 }