예제 #1
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);
        }
예제 #2
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
 }
예제 #3
0
        /// <summary>Snippet for GetMonitoredResourceDescriptorAsync</summary>
        public async Task GetMonitoredResourceDescriptorAsync()
        {
            // Snippet: GetMonitoredResourceDescriptorAsync(MonitoredResourceDescriptorName,CallSettings)
            // Additional: GetMonitoredResourceDescriptorAsync(MonitoredResourceDescriptorName,CancellationToken)
            // Create client
            MetricServiceClient metricServiceClient = await MetricServiceClient.CreateAsync();

            // Initialize request argument(s)
            MonitoredResourceDescriptorName name = new MonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
            // Make the request
            MonitoredResourceDescriptor response = await metricServiceClient.GetMonitoredResourceDescriptorAsync(name);

            // End snippet
        }
        public async Task GetMonitoredResourceDescriptorAsync()
        {
            Mock <MetricService.MetricServiceClient> mockGrpcClient  = new Mock <MetricService.MetricServiceClient>(MockBehavior.Strict);
            GetMonitoredResourceDescriptorRequest    expectedRequest = new GetMonitoredResourceDescriptorRequest
            {
                MonitoredResourceDescriptorName = new MonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]"),
            };
            MonitoredResourceDescriptor expectedResponse = new MonitoredResourceDescriptor
            {
                Name        = "name2-1052831874",
                Type        = "type3575610",
                DisplayName = "displayName1615086568",
                Description = "description-1724546052",
            };

            mockGrpcClient.Setup(x => x.GetMonitoredResourceDescriptorAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MonitoredResourceDescriptor>(Task.FromResult(expectedResponse), null, null, null, null));
            MetricServiceClient             client   = new MetricServiceClientImpl(mockGrpcClient.Object, null);
            MonitoredResourceDescriptorName name     = new MonitoredResourceDescriptorName("[PROJECT]", "[MONITORED_RESOURCE_DESCRIPTOR]");
            MonitoredResourceDescriptor     response = await client.GetMonitoredResourceDescriptorAsync(name);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }