Example #1
0
        // [START monitoring_create_metric]
        public static object CreateMetric(string projectId,
                                          string metricType = "custom.googleapis.com/stores/daily_sales")
        {
            // Create client.
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();

            // Prepare custom metric descriptor.
            MetricDescriptor metricDescriptor = new MetricDescriptor();

            metricDescriptor.DisplayName = "Daily Sales";
            metricDescriptor.Description = "Daily sales records from all branch stores.";
            metricDescriptor.MetricKind  = MetricKind.Gauge;
            metricDescriptor.ValueType   = MetricDescriptor.Types.ValueType.Double;
            metricDescriptor.Type        = metricType;
            metricDescriptor.Unit        = "{USD}";
            LabelDescriptor labels = new LabelDescriptor();

            labels.Key         = "store_id";
            labels.ValueType   = LabelDescriptor.Types.ValueType.String;
            labels.Description = "The ID of the store.";
            metricDescriptor.Labels.Add(labels);
            CreateMetricDescriptorRequest request = new CreateMetricDescriptorRequest
            {
                ProjectName = new ProjectName(projectId),
            };

            request.MetricDescriptor = metricDescriptor;
            // Make the request.
            MetricDescriptor response = metricServiceClient.CreateMetricDescriptor(request);

            Console.WriteLine("Done creating metric descriptor:");
            Console.WriteLine(JObject.Parse($"{response}").ToString());
            return(0);
        }
Example #2
0
 /// <summary>Snippet for CreateMetricDescriptor</summary>
 public void CreateMetricDescriptor()
 {
     // Snippet: CreateMetricDescriptor(ProjectName,MetricDescriptor,CallSettings)
     // Create client
     MetricServiceClient metricServiceClient = MetricServiceClient.Create();
     // Initialize request argument(s)
     ProjectName      name             = new ProjectName("[PROJECT]");
     MetricDescriptor metricDescriptor = new MetricDescriptor();
     // Make the request
     MetricDescriptor response = metricServiceClient.CreateMetricDescriptor(name, metricDescriptor);
     // End snippet
 }
Example #3
0
 /// <summary>Snippet for CreateMetricDescriptor</summary>
 public void CreateMetricDescriptor_RequestObject()
 {
     // Snippet: CreateMetricDescriptor(CreateMetricDescriptorRequest,CallSettings)
     // Create client
     MetricServiceClient metricServiceClient = MetricServiceClient.Create();
     // Initialize request argument(s)
     CreateMetricDescriptorRequest request = new CreateMetricDescriptorRequest
     {
         ProjectName      = new ProjectName("[PROJECT]"),
         MetricDescriptor = new MetricDescriptor(),
     };
     // Make the request
     MetricDescriptor response = metricServiceClient.CreateMetricDescriptor(request);
     // End snippet
 }