...

Source file src/cloud.google.com/go/monitoring/apiv3/metric_client_example_test.go

Documentation: cloud.google.com/go/monitoring/apiv3

     1  // Copyright 2020 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
    16  
    17  package monitoring_test
    18  
    19  import (
    20  	"context"
    21  
    22  	monitoring "cloud.google.com/go/monitoring/apiv3"
    23  	"cloud.google.com/go/monitoring/apiv3/v2/monitoringpb"
    24  	"google.golang.org/api/iterator"
    25  )
    26  
    27  func ExampleNewMetricClient() {
    28  	ctx := context.Background()
    29  	c, err := monitoring.NewMetricClient(ctx)
    30  	if err != nil {
    31  		// TODO: Handle error.
    32  	}
    33  	// TODO: Use client.
    34  	_ = c
    35  }
    36  
    37  func ExampleMetricClient_ListMonitoredResourceDescriptors() {
    38  	// import monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
    39  	// import "google.golang.org/api/iterator"
    40  
    41  	ctx := context.Background()
    42  	c, err := monitoring.NewMetricClient(ctx)
    43  	if err != nil {
    44  		// TODO: Handle error.
    45  	}
    46  
    47  	req := &monitoringpb.ListMonitoredResourceDescriptorsRequest{
    48  		// TODO: Fill request struct fields.
    49  	}
    50  	it := c.ListMonitoredResourceDescriptors(ctx, req)
    51  	for {
    52  		resp, err := it.Next()
    53  		if err == iterator.Done {
    54  			break
    55  		}
    56  		if err != nil {
    57  			// TODO: Handle error.
    58  		}
    59  		// TODO: Use resp.
    60  		_ = resp
    61  	}
    62  }
    63  
    64  func ExampleMetricClient_GetMonitoredResourceDescriptor() {
    65  	// import monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
    66  
    67  	ctx := context.Background()
    68  	c, err := monitoring.NewMetricClient(ctx)
    69  	if err != nil {
    70  		// TODO: Handle error.
    71  	}
    72  
    73  	req := &monitoringpb.GetMonitoredResourceDescriptorRequest{
    74  		// TODO: Fill request struct fields.
    75  	}
    76  	resp, err := c.GetMonitoredResourceDescriptor(ctx, req)
    77  	if err != nil {
    78  		// TODO: Handle error.
    79  	}
    80  	// TODO: Use resp.
    81  	_ = resp
    82  }
    83  
    84  func ExampleMetricClient_ListMetricDescriptors() {
    85  	// import monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
    86  	// import "google.golang.org/api/iterator"
    87  
    88  	ctx := context.Background()
    89  	c, err := monitoring.NewMetricClient(ctx)
    90  	if err != nil {
    91  		// TODO: Handle error.
    92  	}
    93  
    94  	req := &monitoringpb.ListMetricDescriptorsRequest{
    95  		// TODO: Fill request struct fields.
    96  	}
    97  	it := c.ListMetricDescriptors(ctx, req)
    98  	for {
    99  		resp, err := it.Next()
   100  		if err == iterator.Done {
   101  			break
   102  		}
   103  		if err != nil {
   104  			// TODO: Handle error.
   105  		}
   106  		// TODO: Use resp.
   107  		_ = resp
   108  	}
   109  }
   110  
   111  func ExampleMetricClient_GetMetricDescriptor() {
   112  	// import monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
   113  
   114  	ctx := context.Background()
   115  	c, err := monitoring.NewMetricClient(ctx)
   116  	if err != nil {
   117  		// TODO: Handle error.
   118  	}
   119  
   120  	req := &monitoringpb.GetMetricDescriptorRequest{
   121  		// TODO: Fill request struct fields.
   122  	}
   123  	resp, err := c.GetMetricDescriptor(ctx, req)
   124  	if err != nil {
   125  		// TODO: Handle error.
   126  	}
   127  	// TODO: Use resp.
   128  	_ = resp
   129  }
   130  
   131  func ExampleMetricClient_CreateMetricDescriptor() {
   132  	// import monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
   133  
   134  	ctx := context.Background()
   135  	c, err := monitoring.NewMetricClient(ctx)
   136  	if err != nil {
   137  		// TODO: Handle error.
   138  	}
   139  
   140  	req := &monitoringpb.CreateMetricDescriptorRequest{
   141  		// TODO: Fill request struct fields.
   142  	}
   143  	resp, err := c.CreateMetricDescriptor(ctx, req)
   144  	if err != nil {
   145  		// TODO: Handle error.
   146  	}
   147  	// TODO: Use resp.
   148  	_ = resp
   149  }
   150  
   151  func ExampleMetricClient_DeleteMetricDescriptor() {
   152  	ctx := context.Background()
   153  	c, err := monitoring.NewMetricClient(ctx)
   154  	if err != nil {
   155  		// TODO: Handle error.
   156  	}
   157  
   158  	req := &monitoringpb.DeleteMetricDescriptorRequest{
   159  		// TODO: Fill request struct fields.
   160  	}
   161  	err = c.DeleteMetricDescriptor(ctx, req)
   162  	if err != nil {
   163  		// TODO: Handle error.
   164  	}
   165  }
   166  
   167  func ExampleMetricClient_ListTimeSeries() {
   168  	// import monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
   169  	// import "google.golang.org/api/iterator"
   170  
   171  	ctx := context.Background()
   172  	c, err := monitoring.NewMetricClient(ctx)
   173  	if err != nil {
   174  		// TODO: Handle error.
   175  	}
   176  
   177  	req := &monitoringpb.ListTimeSeriesRequest{
   178  		// TODO: Fill request struct fields.
   179  	}
   180  	it := c.ListTimeSeries(ctx, req)
   181  	for {
   182  		resp, err := it.Next()
   183  		if err == iterator.Done {
   184  			break
   185  		}
   186  		if err != nil {
   187  			// TODO: Handle error.
   188  		}
   189  		// TODO: Use resp.
   190  		_ = resp
   191  	}
   192  }
   193  
   194  func ExampleMetricClient_CreateTimeSeries() {
   195  	ctx := context.Background()
   196  	c, err := monitoring.NewMetricClient(ctx)
   197  	if err != nil {
   198  		// TODO: Handle error.
   199  	}
   200  
   201  	req := &monitoringpb.CreateTimeSeriesRequest{
   202  		// TODO: Fill request struct fields.
   203  	}
   204  	err = c.CreateTimeSeries(ctx, req)
   205  	if err != nil {
   206  		// TODO: Handle error.
   207  	}
   208  }
   209  

View as plain text