public static void Run(string projectId)
        {
            // 5. Start Stackdriver Exporter for metrics collection
            var exporter = new StackdriverExporter(
                projectId,
                exportComponent: null,
                viewManager: Stats.ViewManager);

            exporter.Start();

            // 6. Define what will be exported (schema): a measure, how it's aggregated and how it will be tagged (metadata)
            var executionCountView = View.Create(
                ViewName.Create("sample_execution_count"),
                "Counts the number of method invocations over time",
                numberOfInvocations,
                Count.Create(),
                new List <ITagKey>()
            {
                tagEnv, tagMachine
            });

            // 7. Register the view to export
            Stats.ViewManager.RegisterView(executionCountView);

            // Run instrumented fragment on a separate thread
            Task.Run((Action)InstrumentedFragment);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var exporter = new StackdriverExporter(
                Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT"),
                Tracing.ExportComponent,
                Stats.ViewManager);

            var spanBuilder = Tracing.Tracer
                              .SpanBuilder("incoming request")
                              .SetRecordEvents(true)
                              .SetSampler(Samplers.AlwaysSample);

            exporter.Start();


            StorageClient storageClient = StorageClient.Create();
            var           storage       = StorageClient.Create();
            var           objectName    = "demo-image.jpg";
            var           localPath     = "../../downloads/demo-image.jpg";
            var           bucketName    = Environment.GetEnvironmentVariable("GOOGLE_CLOUD_STORAGE_BUCKET");


            using (var scopedSpan = spanBuilder.StartScopedSpan())
            {
                for (var i = 0; i < 10; i++)
                {
                    using (var outputFile = File.OpenWrite(localPath))
                    {
                        storage.DownloadObject(bucketName, objectName, outputFile);
                    }
                }
            }

            Thread.Sleep(TimeSpan.FromMilliseconds(5000));
        }
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Invalid number of arguments supplied");
                Environment.Exit(-1);
            }

            switch (args[0])
            {
            case "start":
                Parser.Default.ParseArguments <ServerOptions>(args).MapResult(
                    (ServerOptions options) =>
                {
                    Console.WriteLine($"Started as process with id {System.Diagnostics.Process.GetCurrentProcess().Id}");

                    // Set hostname/ip address
                    string hostname = ReadParameter("host address", options.Host, CART_SERVICE_ADDRESS, p => p, "0.0.0.0");

                    // Set the port
                    int port = ReadParameter("cart service port", options.Port, CART_SERVICE_PORT, int.Parse, 8080);

                    string projectId = ReadParameter("cloud service project id", options.ProjectId, PROJECT_ID, p => p, null);

                    // Initialize Stackdriver Exporter - currently for tracing only
                    if (!string.IsNullOrEmpty(projectId))
                    {
                        var exporter = new StackdriverExporter(
                            projectId,
                            Tracing.ExportComponent,
                            viewManager: null);
                        exporter.Start();
                    }

                    // Set redis cache host (hostname+port)
                    string redis = ReadParameter("redis cache address", options.Redis, REDIS_ADDRESS, p => p, null);

                    ICartStore cartStore = InstrumentedCartStore.Create(redis);
                    return(StartServer(hostname, port, cartStore));
                },
                    errs => 1);
                break;

            default:
                Console.WriteLine("Invalid command");
                break;
            }
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            // A little hacky, but at this point you need to add a file 'key.json to the root of the 'Http.Api' directory.
            // The key.json file contains the login details for a user/serivce account required to access GCP stackdriver.
            // It can be generated using a gcloud command.'
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Environment.CurrentDirectory + "/key.json");

            var projectId = "healthy-books";

            var exporter = new StackdriverExporter(
                projectId,
                Tracing.ExportComponent,
                Stats.ViewManager);

            exporter.Start();

            CreateWebHostBuilder(args).Build().Run();
        }
        internal static object Run(string projectId)
        {
            var exporter = new StackdriverExporter(
                projectId,
                Tracing.SpanExporter,
                Stats.ViewManager);

            exporter.Start();

            var tagContextBuilder = Tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5"));

            var spanBuilder = Tracer
                              .SpanBuilder("incoming request")
                              .SetRecordEvents(true)
                              .SetSampler(Samplers.AlwaysSample);

            Stats.ViewManager.RegisterView(VideoSizeView);

            using (tagContextBuilder.BuildScoped())
            {
                using (Tracer.WithSpan(spanBuilder.StartSpan()))
                {
                    Tracer.CurrentSpan.AddEvent("Processing video.");
                    Thread.Sleep(TimeSpan.FromMilliseconds(10));

                    StatsRecorder.NewMeasureMap()
                    .Put(VideoSize, 25 * MiB)
                    .Record();
                }
            }

            Thread.Sleep(TimeSpan.FromMilliseconds(5100));

            var viewData = Stats.ViewManager.GetView(VideoSizeViewName);

            Console.WriteLine(viewData);

            Console.WriteLine("Done... wait for events to arrive to backend!");
            Console.ReadLine();

            return(null);
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            var exporter = new StackdriverExporter(
                Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT"),
                Tracing.ExportComponent,
                Stats.ViewManager);

            var spanBuilder = Tracing.Tracer
                              .SpanBuilder("incoming request")
                              .SetRecordEvents(true)
                              .SetSampler(Samplers.AlwaysSample);

            exporter.Start();


            var client = ImageAnnotatorClient.Create();
            var image  = Image.FromFile("../../resources/demo-image.jpg");

            using (var scopedSpan = spanBuilder.StartScopedSpan())
            {
                var response = client.DetectLabels(image);
                for (var i = 0; i < 9; i++)
                {
                    response = client.DetectLabels(image);
                }

                foreach (var annotation in response)
                {
                    if (annotation.Description != null)
                    {
                        Console.WriteLine(annotation.Description);
                    }
                }
            }

            Thread.Sleep(TimeSpan.FromMilliseconds(5000));
        }