예제 #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);
        }
예제 #2
0
        public static int Main(string[] args)
        {
            // Read projectId from args
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: Project ID must be passed as first argument.");
                Console.WriteLine();
                return(1);
            }
            string projectId = args[0];

            // Create client
            MetricServiceClient client = MetricServiceClient.Create();

            // Initialize request argument(s)
            ProjectName name = ProjectName.FromProject(projectId);

            // Call API method
            var pagedResponse = client.ListMonitoredResourceDescriptors(name);

            // Show the result
            foreach (var item in pagedResponse)
            {
                Console.WriteLine(item);
            }

            // Success
            Console.WriteLine("Smoke test passed OK");
            return(0);
        }
예제 #3
0
    public GooglePubSubGapMeasure(PubSubSubscriptionOptions options)
    {
        _subscriptionId = options.SubscriptionId;

        var emulationEnabled =
            !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("PUBSUB_EMULATOR_HOST"));

        _monitoringEnabled = !emulationEnabled && options.EnableMonitoring;

        if (_monitoringEnabled)
        {
            _metricClient = MetricServiceClient.Create();
        }

        _undeliveredCountRequest = GetFilteredRequest(PubSubMetricUndeliveredMessagesCount);
        _oldestAgeRequest        = GetFilteredRequest(PubSubMetricOldestUnackedMessageAge);

        ListTimeSeriesRequest GetFilteredRequest(string metric)
        => new()
        {
            Name   = $"projects/{options.ProjectId}",
            Filter = $"metric.type = \"pubsub.googleapis.com/subscription/{metric}\" "
                     + $"AND resource.label.subscription_id = \"{options.SubscriptionId}\""
        };
    }
예제 #4
0
        public async Task ListMetricDescriptorsAsync()
        {
            // Snippet: ListMetricDescriptorsAsync(string,string,int?,CallSettings)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            string formattedName = MetricServiceClient.FormatProjectName("[PROJECT]");
            // Make the request
            IPagedAsyncEnumerable <ListMetricDescriptorsResponse, MetricDescriptor> response =
                metricServiceClient.ListMetricDescriptorsAsync(formattedName);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((MetricDescriptor item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over fixed-sized pages, lazily performing RPCs as required
            int pageSize = 10;
            IAsyncEnumerable <FixedSizePage <MetricDescriptor> > fixedSizePages = response.AsPages().WithFixedSize(pageSize);
            await fixedSizePages.ForEachAsync((FixedSizePage <MetricDescriptor> page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (MetricDescriptor item in page)
                {
                    Console.WriteLine(item);
                }
            });

            // End snippet
        }
예제 #5
0
        public void ListMonitoredResourceDescriptors()
        {
            // Snippet: ListMonitoredResourceDescriptors(string,string,int?,CallSettings)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            string formattedName = MetricServiceClient.FormatProjectName("[PROJECT]");
            // Make the request
            IPagedEnumerable <ListMonitoredResourceDescriptorsResponse, MonitoredResourceDescriptor> response =
                metricServiceClient.ListMonitoredResourceDescriptors(formattedName);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (MonitoredResourceDescriptor item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over fixed-sized pages, lazily performing RPCs as required
            int pageSize = 10;

            foreach (FixedSizePage <MonitoredResourceDescriptor> page in response.AsPages().WithFixedSize(pageSize))
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (MonitoredResourceDescriptor item in page)
                {
                    Console.WriteLine(item);
                }
            }
            // End snippet
        }
        // [END monitoring_read_timeseries_fields]

        // [START monitoring_read_timeseries_align]
        public static object ReadTimeSeriesAggregate(string projectId,
                                                     string metricType = "compute.googleapis.com/instance/cpu/utilization")
        {
            // Create client.
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s).
            string filter = $"metric.type=\"{metricType}\"";
            ListTimeSeriesRequest request = new ListTimeSeriesRequest
            {
                ProjectName = new ProjectName(projectId),
                Filter      = filter,
                Interval    = new TimeInterval(),
            };
            // Create timestamp for current time formatted in seconds.
            long      timeStamp      = (long)(DateTime.UtcNow - s_unixEpoch).TotalSeconds;
            Timestamp startTimeStamp = new Timestamp();

            // Set startTime to limit results to the last 20 minutes.
            startTimeStamp.Seconds = timeStamp - (60 * 20);
            Timestamp endTimeStamp = new Timestamp();

            // Set endTime to current time.
            endTimeStamp.Seconds = timeStamp;
            TimeInterval interval = new TimeInterval();

            interval.StartTime = startTimeStamp;
            interval.EndTime   = endTimeStamp;
            request.Interval   = interval;
            // Aggregate results per matching instance
            Aggregation aggregation     = new Aggregation();
            Duration    alignmentPeriod = new Duration();

            alignmentPeriod.Seconds      = 600;
            aggregation.AlignmentPeriod  = alignmentPeriod;
            aggregation.PerSeriesAligner = Aggregation.Types.Aligner.AlignMean;
            // Add the aggregation to the request.
            request.Aggregation = aggregation;
            // Make the request.
            PagedEnumerable <ListTimeSeriesResponse, TimeSeries> response =
                metricServiceClient.ListTimeSeries(request);

            // Iterate over all response items, lazily performing RPCs as required.
            Console.WriteLine($"{projectId} CPU utilization:");
            foreach (var item in response)
            {
                var points = item.Points;
                var labels = item.Metric.Labels;
                Console.WriteLine($"{labels.Values.FirstOrDefault()}");
                if (points.Count > 0)
                {
                    Console.WriteLine($"  Now: {points[0].Value.DoubleValue}");
                }
                if (points.Count > 1)
                {
                    Console.WriteLine($"  10 min ago: {points[1].Value.DoubleValue}");
                }
            }
            return(0);
        }
예제 #7
0
        // [END monitoring_list_resources]

        // [START monitoring_get_resource]
        public static object GetMonitoredResource(string projectId, string resourceId)
        {
            MetricServiceClient             client = MetricServiceClient.Create();
            MonitoredResourceDescriptorName name   = new MonitoredResourceDescriptorName(projectId, resourceId);
            var    response = client.GetMonitoredResourceDescriptor(name);
            string resource = JObject.Parse($"{response}").ToString();

            Console.WriteLine($"{ resource }");
            return(0);
        }
예제 #8
0
        public static void Main(string[] args)
        {
            // Your Google Cloud Platform project ID.
            string projectId = "YOUR-PROJECT-ID";

            // Create client.
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();

            // Initialize request argument(s).
            ProjectName name = new ProjectName(projectId);

            // Prepare a data point.
            Point      dataPoint  = new Point();
            TypedValue salesTotal = new TypedValue();

            salesTotal.DoubleValue = 123.45;
            dataPoint.Value        = salesTotal;
            // Sets data point's interval end time to current time.
            Timestamp timeStamp = new Timestamp();
            DateTime  UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            timeStamp.Seconds = (long)(DateTime.UtcNow - UnixEpoch).TotalSeconds;
            TimeInterval interval = new TimeInterval();

            interval.EndTime   = timeStamp;
            dataPoint.Interval = interval;

            // Prepare custom metric.
            Metric metric = new Metric();

            metric.Type = "custom.googleapis.com/stores/daily_sales";
            metric.Labels.Add("store_id", "Pittsburgh");

            // Prepare monitored resource.
            MonitoredResource resource = new MonitoredResource();

            resource.Type = "global";
            resource.Labels.Add("project_id", projectId);

            // Create a new time series using inputs.
            TimeSeries timeSeriesData = new TimeSeries();

            timeSeriesData.Metric   = metric;
            timeSeriesData.Resource = resource;
            timeSeriesData.Points.Add(dataPoint);

            // Add newly created time series to list of time series to be written.
            IEnumerable <TimeSeries> timeSeries = new List <TimeSeries> {
                timeSeriesData
            };

            // Write time series data.
            metricServiceClient.CreateTimeSeries(name, timeSeries);
            Console.WriteLine("Done writing time series data.");
        }
예제 #9
0
 /// <summary>Snippet for GetMonitoredResourceDescriptor</summary>
 public void GetMonitoredResourceDescriptor()
 {
     // Snippet: GetMonitoredResourceDescriptor(MonitoredResourceDescriptorName,CallSettings)
     // Create client
     MetricServiceClient metricServiceClient = MetricServiceClient.Create();
     // Initialize request argument(s)
     MonitoredResourceDescriptorName name = new MonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
     // Make the request
     MonitoredResourceDescriptor response = metricServiceClient.GetMonitoredResourceDescriptor(name);
     // End snippet
 }
예제 #10
0
 /// <summary>Snippet for GetMetricDescriptor</summary>
 public void GetMetricDescriptor()
 {
     // Snippet: GetMetricDescriptor(MetricDescriptorName,CallSettings)
     // Create client
     MetricServiceClient metricServiceClient = MetricServiceClient.Create();
     // Initialize request argument(s)
     MetricDescriptorName name = new MetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
     // Make the request
     MetricDescriptor response = metricServiceClient.GetMetricDescriptor(name);
     // End snippet
 }
예제 #11
0
        public void DeleteMetricDescriptor()
        {
            // Snippet: DeleteMetricDescriptor(string,CallSettings)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            string formattedName = MetricServiceClient.FormatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");

            // Make the request
            metricServiceClient.DeleteMetricDescriptor(formattedName);
            // End snippet
        }
예제 #12
0
        // [END monitoring_create_metric]


        // [START monitoring_delete_metric]
        public static object DeleteMetric(string projectId, string metricType)
        {
            // Create client.
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s).
            MetricDescriptorName name = new MetricDescriptorName(projectId, metricType);

            // Make the request.
            metricServiceClient.DeleteMetricDescriptor(name);
            Console.WriteLine($"Done deleting metric descriptor: {name}");
            return(0);
        }
예제 #13
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
 }
예제 #14
0
        // [END monitoring_delete_metric]

        // [START monitoring_list_descriptors]
        public static object ListMetrics(string projectId)
        {
            MetricServiceClient client      = MetricServiceClient.Create();
            ProjectName         projectName = new ProjectName(projectId);
            PagedEnumerable <ListMetricDescriptorsResponse, MetricDescriptor> metrics = client.ListMetricDescriptors(projectName);

            foreach (MetricDescriptor metric in metrics)
            {
                Console.WriteLine($"{metric.Name}: {metric.DisplayName}");
            }
            return(0);
        }
예제 #15
0
        public async Task DeleteMetricDescriptorAsync()
        {
            // Snippet: DeleteMetricDescriptorAsync(string,CallSettings)
            // Additional: DeleteMetricDescriptorAsync(string,CancellationToken)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            string formattedName = MetricServiceClient.FormatMetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
            // Make the request
            await metricServiceClient.DeleteMetricDescriptorAsync(formattedName);

            // End snippet
        }
예제 #16
0
        /// <summary>Snippet for CreateTimeSeries</summary>
        public void CreateTimeSeries()
        {
            // Snippet: CreateTimeSeries(ProjectName,IEnumerable<TimeSeries>,CallSettings)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            ProjectName name = new ProjectName("[PROJECT]");
            IEnumerable <TimeSeries> timeSeries = new List <TimeSeries>();

            // Make the request
            metricServiceClient.CreateTimeSeries(name, timeSeries);
            // End snippet
        }
예제 #17
0
        public async Task GetMonitoredResourceDescriptorAsync()
        {
            // Snippet: GetMonitoredResourceDescriptorAsync(string,CallSettings)
            // Additional: GetMonitoredResourceDescriptorAsync(string,CancellationToken)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            string formattedName = MetricServiceClient.FormatMonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
            // Make the request
            MonitoredResourceDescriptor response = await metricServiceClient.GetMonitoredResourceDescriptorAsync(formattedName);

            // End snippet
        }
예제 #18
0
        /// <summary>Snippet for GetMetricDescriptorAsync</summary>
        public async Task GetMetricDescriptorAsync()
        {
            // Snippet: GetMetricDescriptorAsync(MetricDescriptorName,CallSettings)
            // Additional: GetMetricDescriptorAsync(MetricDescriptorName,CancellationToken)
            // Create client
            MetricServiceClient metricServiceClient = await MetricServiceClient.CreateAsync();

            // Initialize request argument(s)
            MetricDescriptorName name = new MetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]");
            // Make the request
            MetricDescriptor response = await metricServiceClient.GetMetricDescriptorAsync(name);

            // End snippet
        }
예제 #19
0
        public async Task CreateTimeSeriesAsync()
        {
            // Snippet: CreateTimeSeriesAsync(string,IEnumerable<TimeSeries>,CallSettings)
            // Additional: CreateTimeSeriesAsync(string,IEnumerable<TimeSeries>,CancellationToken)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            string formattedName = MetricServiceClient.FormatProjectName("[PROJECT]");
            IEnumerable <TimeSeries> timeSeries = new List <TimeSeries>();
            // Make the request
            await metricServiceClient.CreateTimeSeriesAsync(formattedName, timeSeries);

            // End snippet
        }
예제 #20
0
        // [END monitoring_get_descriptor]

        // [START monitoring_write_timeseries]
        public static object WriteTimeSeriesData(string projectId)
        {
            // Create client.
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s).
            ProjectName name = new ProjectName(projectId);
            // Prepare a data point.
            Point      dataPoint  = new Point();
            TypedValue salesTotal = new TypedValue();

            salesTotal.DoubleValue = 123.45;
            dataPoint.Value        = salesTotal;
            Timestamp timeStamp = new Timestamp();

            timeStamp.Seconds = (long)(DateTime.UtcNow - s_unixEpoch).TotalSeconds;
            TimeInterval interval = new TimeInterval();

            interval.EndTime   = timeStamp;
            dataPoint.Interval = interval;

            // Prepare custom metric.
            Metric metric = new Metric();

            metric.Type = "custom.googleapis.com/stores/daily_sales";
            metric.Labels.Add("store_id", "Pittsburgh");

            // Prepare monitored resource.
            MonitoredResource resource = new MonitoredResource();

            resource.Type = "global";
            resource.Labels.Add("project_id", projectId);

            // Create a new time series using inputs.
            TimeSeries timeSeriesData = new TimeSeries();

            timeSeriesData.Metric   = metric;
            timeSeriesData.Resource = resource;
            timeSeriesData.Points.Add(dataPoint);

            // Add newly created time series to list of time series to be written.
            IEnumerable <TimeSeries> timeSeries = new List <TimeSeries> {
                timeSeriesData
            };

            // Write time series data.
            metricServiceClient.CreateTimeSeries(name, timeSeries);
            Console.WriteLine("Done writing time series data:");
            Console.WriteLine(JObject.Parse($"{timeSeriesData}").ToString());
            return(0);
        }
예제 #21
0
        public CloudMonitoringServices(IConfiguration configuration)
        {
            this.configuration = configuration;
            var helper = new CloudMonitoringHelper(configuration);

            googleCredential = helper.GetGoogleCredential();
            channel          = new Channel(
                MetricServiceClient.DefaultEndpoint.Host,
                MetricServiceClient.DefaultEndpoint.Port,
                googleCredential.ToChannelCredentials()
                );
            client    = MetricServiceClient.Create(channel);
            projectId = helper.GetProjectId();
        }
예제 #22
0
 /// <summary>Snippet for GetMetricDescriptor</summary>
 public void GetMetricDescriptor_RequestObject()
 {
     // Snippet: GetMetricDescriptor(GetMetricDescriptorRequest,CallSettings)
     // Create client
     MetricServiceClient metricServiceClient = MetricServiceClient.Create();
     // Initialize request argument(s)
     GetMetricDescriptorRequest request = new GetMetricDescriptorRequest
     {
         MetricDescriptorName = new MetricDescriptorName("[PROJECT]", "[METRIC_DESCRIPTOR]"),
     };
     // Make the request
     MetricDescriptor response = metricServiceClient.GetMetricDescriptor(request);
     // End snippet
 }
예제 #23
0
        public async Task CreateMetricDescriptorAsync()
        {
            // Snippet: CreateMetricDescriptorAsync(string,MetricDescriptor,CallSettings)
            // Additional: CreateMetricDescriptorAsync(string,MetricDescriptor,CancellationToken)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            string           formattedName    = MetricServiceClient.FormatProjectName("[PROJECT]");
            MetricDescriptor metricDescriptor = new MetricDescriptor();
            // Make the request
            MetricDescriptor response = await metricServiceClient.CreateMetricDescriptorAsync(formattedName, metricDescriptor);

            // End snippet
        }
예제 #24
0
        /// <summary>Snippet for ListTimeSeriesAsync</summary>
        public async Task ListTimeSeriesAsync_RequestObject()
        {
            // Snippet: ListTimeSeriesAsync(ListTimeSeriesRequest,CallSettings)
            // Create client
            MetricServiceClient metricServiceClient = await MetricServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListTimeSeriesRequest request = new ListTimeSeriesRequest
            {
                ProjectName = new ProjectName("[PROJECT]"),
                Filter      = "",
                Interval    = new TimeInterval(),
                View        = ListTimeSeriesRequest.Types.TimeSeriesView.Full,
            };
            // Make the request
            PagedAsyncEnumerable <ListTimeSeriesResponse, TimeSeries> response =
                metricServiceClient.ListTimeSeriesAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((TimeSeries item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListTimeSeriesResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (TimeSeries item in page)
                {
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int pageSize = 10;
            Page <TimeSeries> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (TimeSeries item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
        public void Start()
        {
            lock (locker)
            {
                if (!isStarted)
                {
                    tokenSource         = new CancellationTokenSource();
                    metricServiceClient = CreateMetricServiceClient(credential, tokenSource);

                    Task.Factory.StartNew(DoWork, tokenSource.Token);

                    isStarted = true;
                }
            }
        }
예제 #26
0
        public void Start()
        {
            lock (this.locker)
            {
                if (!this.isStarted)
                {
                    this.tokenSource         = new CancellationTokenSource();
                    this.metricServiceClient = CreateMetricServiceClient(this.credential, this.tokenSource);

                    Task.Factory.StartNew(this.DoWork, this.tokenSource.Token);

                    this.isStarted = true;
                }
            }
        }
예제 #27
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
 }
예제 #28
0
        protected override async Task <EventSubscription> Subscribe(
            Checkpoint checkpoint,
            CancellationToken cancellationToken
            )
        {
            await CreateSubscription(_subscriptionName, _topicName, _options?.PushConfig, _options?.AckDeadline ?? 60)
            .Ignore();

            _client = await CreateAsync(
                _subscriptionName,
                _options?.ClientCreationSettings,
                _options?.Settings
                ).Ignore();

            _metricClient = await MetricServiceClient.CreateAsync(cancellationToken).Ignore();

            _subscriberTask = _client.StartAsync(Handle);
            return(new EventSubscription(SubscriptionId, this));

            async Task <Reply> Handle(PubsubMessage msg, CancellationToken ct)
            {
                var eventType   = msg.Attributes["eventType"];
                var contentType = msg.Attributes["contentType"];

                var evt = DeserializeData(contentType, eventType, msg.Data.ToByteArray(), _topicName.TopicId);

                var receivedEvent = new ReceivedEvent(
                    msg.MessageId,
                    eventType,
                    contentType,
                    0,
                    0,
                    _topicName.TopicId,
                    0,
                    msg.PublishTime.ToDateTime(),
                    evt
                    );

                try {
                    await Handler(receivedEvent, ct).Ignore();

                    return(Reply.Ack);
                }
                catch (Exception ex) {
                    return(await _failureHandler(_client, msg, ex).Ignore());
                }
            }
        }
예제 #29
0
        public void ListMetricDescriptors()
        {
            string projectId = _fixture.ProjectId;

            // Sample: ListMetricDescriptors
            // Additional: ListMetricDescriptors(*,*,*,*)
            MetricServiceClient client      = MetricServiceClient.Create();
            ProjectName         projectName = new ProjectName(projectId);
            PagedEnumerable <ListMetricDescriptorsResponse, MetricDescriptor> metrics = client.ListMetricDescriptors(projectName);

            foreach (MetricDescriptor metric in metrics.Take(10))
            {
                Console.WriteLine($"{metric.Name}: {metric.DisplayName}");
            }
            // End sample
        }
예제 #30
0
        /// <summary>Snippet for CreateTimeSeries</summary>
        public void CreateTimeSeries_RequestObject()
        {
            // Snippet: CreateTimeSeries(CreateTimeSeriesRequest,CallSettings)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            CreateTimeSeriesRequest request = new CreateTimeSeriesRequest
            {
                ProjectName = new ProjectName("[PROJECT]"),
                TimeSeries  = { },
            };

            // Make the request
            metricServiceClient.CreateTimeSeries(request);
            // End snippet
        }