コード例 #1
0
        private static LauncherErrorCode RunSingleInstance(bool shouldStartHidden)
        {
            try
            {
                // Only needed for Stride up to 2.x (and possibly 3.0): setup the StrideDir to make sure that it is passed to the underlying process (msbuild...etc.)
                Environment.SetEnvironmentVariable("SiliconStudioStrideDir", AppDomain.CurrentDomain.BaseDirectory);
                Environment.SetEnvironmentVariable("StrideDir", AppDomain.CurrentDomain.BaseDirectory);

                // We need to do that before starting recording metrics
                // TODO: we do not display Privacy Policy anymore from launcher, because it's either accepted from installer or shown again when a new version of GS with new Privacy Policy starts. Might want to reconsider that after the 2.0 free period
                PrivacyPolicyHelper.RestartApplication = SelfUpdater.RestartApplication;
                PrivacyPolicyHelper.EnsurePrivacyPolicyStride40();

                // Install Metrics for the launcher
                using (Metrics = new MetricsClient(CommonApps.StrideLauncherAppId))
                {
                    // HACK: force resolve the presentation assembly prior to initializing the app. This is to fix an issue with XAML themes.
                    // see issue PDX-2899
                    var txt = new Core.Presentation.Controls.TextBox();
                    GC.KeepAlive(txt); // prevent aggressive optimization from removing the line where we create the dummy TextBox.

                    var instance = new LauncherInstance();
                    return(instance.Run(shouldStartHidden));
                }
            }
            catch (Exception exception)
            {
                CrashReportHelper.HandleException(Dispatcher.CurrentDispatcher, exception);
                return(LauncherErrorCode.ErrorWhileRunningServer);
            }
        }
コード例 #2
0
        public async Task Can_Send_A_Metric_With_No_Filter2()
        {
            var metric = GenerateTestMetric();

            metric.SetFilter2(null);
            await MetricsClient.SendAsync(metric).ConfigureAwait(false);
        }
コード例 #3
0
        private static void Main(string[] args)
        {
            _subscriptionId    = args[0];
            _thumbprint        = args[1];
            _alertEmailAddress = args[2];
            _cloudServiceName  = args[3];
            _deploymentName    = args[4];

            SubscriptionCloudCredentials credentials = new CertificateCloudCredentials(_subscriptionId,
                                                                                       GetStoreCertificate(_thumbprint));

            var metricsClient = new MetricsClient(credentials);

            var resourceId = ResourceIdBuilder.BuildCloudServiceResourceId(_cloudServiceName, _deploymentName);

            Console.WriteLine("Resource Id: {0}", resourceId);

            GetMetricDefinitions(metricsClient, resourceId);

            var alertsClient = new AlertsClient(credentials);

            DisplayAzureAlertRules(alertsClient);

            var response = CreateAzureAlert(resourceId, alertsClient);

            Console.WriteLine("Create alert rule response: " + response.Result.StatusCode);
            Console.ReadLine();
        }
コード例 #4
0
        public async Task QueryMetrics()
        {
            #region Snippet:QueryMetrics

#if SNIPPET
            Uri    endpoint   = new Uri("https://management.azure.com");
            string resourceId =
                "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.OperationalInsights/workspaces/<workspace_name>";
#else
            Uri    endpoint   = TestEnvironment.LogsEndpoint;
            string resourceId = TestEnvironment.MetricsResource;
#endif

            var metricsClient = new MetricsClient(endpoint, new DefaultAzureCredential());

            Response <MetricQueryResult> results = await metricsClient.QueryAsync(
                resourceId,
                new[] { "Microsoft.OperationalInsights/workspaces" }
                );

            foreach (var metric in results.Value.Metrics)
            {
                Console.WriteLine(metric.Name);
                foreach (var element in metric.TimeSeries)
                {
                    Console.WriteLine("Dimensions: " + string.Join(",", element.Metadata));

                    foreach (var metricValue in element.Data)
                    {
                        Console.WriteLine(metricValue);
                    }
                }
            }
            #endregion
        }
コード例 #5
0
        public void Cannot_Create_A_Metrics_Client_With_A_Blank_App_Key()
        {
            var ex = Assert.Throws <SematextValidationException>(() =>
            {
                var client = new MetricsClient("  ");
            });

            Assert.Equal("You must provide a valid app token.", ex.Message);
        }
コード例 #6
0
        public async Task Can_Send_More_Than_100_Metrics_At_A_Time()
        {
            var metrics = new List <Metric>();

            for (var i = 0; i < 150; i++)
            {
                metrics.Add(GenerateTestMetric());
            }

            await MetricsClient.SendAsync(metrics.ToArray()).ConfigureAwait(false);
        }
コード例 #7
0
        public async Task Can_Send_A_Group_Of_Metrics()
        {
            var metrics = new[]
            {
                GenerateTestMetric(),
                GenerateTestMetric(),
                GenerateTestMetric()
            };

            await MetricsClient.SendAsync(metrics).ConfigureAwait(false);
        }
コード例 #8
0
        public async Task StartStudio(string argument)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(nameof(argument));
            }
            if (ActiveVersion == null)
            {
                return;
            }

            if (AutoCloseLauncher)
            {
                argument = $"/LauncherWindowHandle {WindowHandle} {argument}";
            }

            MetricsClient metricsForEditorBefore120 = null;

            try
            {
                Dispatcher.Invoke(() => StartStudioCommand.IsEnabled = false);
                var packagePath    = ActiveVersion.InstallPath;
                var mainExecutable = store.LocateMainExecutable(packagePath);

                // If version is older than 1.2.0, than we need to log the usage of older version
                var activeStoreVersion = ActiveVersion as XenkoStoreVersionViewModel;
                if (activeStoreVersion != null && activeStoreVersion.Version.Version < new Version(1, 2, 0, 0))
                {
                    metricsForEditorBefore120 = new MetricsClient(CommonApps.XenkoEditorAppId, versionOverride: activeStoreVersion.Version.ToString());
                }

                Process.Start(mainExecutable, argument);
            }
            catch (Exception e)
            {
                var message = string.Format(Strings.ErrorStartingProcess, e.FormatSummary(true));
                await ServiceProvider.Get <IDialogService>().MessageBox(message, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                metricsForEditorBefore120?.Dispose();
            }
            await Task.Delay(5000);

            Dispatcher.Invoke(() =>
            {
                StartStudioCommand.IsEnabled = ActiveVersion != null;
                //Save settings because launcher maybe have not been closed
                LauncherSettings.ActiveVersion = ActiveVersion != null ? ActiveVersion.Name : "";
                LauncherSettings.Save();
            });
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: badokun/lightning-metrics
        private async Task OnExecuteAsync(CancellationToken ct)
        {
            MetricsConfiguration config = null;

            try
            {
                config = new MetricsConfiguration()
                {
                    InfluxDbUri       = InfluxDbUri,
                    Network           = Network,
                    LndRestApiUri     = LndRestApiUri,
                    MacaroonHex       = MacaroonHex,
                    CertThumbprintHex = CertThumbprintHex,
                    IntervalSeconds   = IntervalSeconds,
                    InfluxDbName      = InfluxDbName,
                    MetricPrefix      = MetricPrefix,
                    UseMempoolBackend = UseMempoolBackend,
                    MempoolApiUri     = MempoolApiUri
                };

                config.Validate();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }

            try
            {
                var client = new MetricsClient(config);
                if (this.TestInfluxDb)
                {
                    client.TestInfluxDb();
                }
                else if (this.TestLndApi)
                {
                    client.TestLndApi();
                }
                else
                {
                    var version = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion;
                    await client.Start(version, ct).ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
コード例 #10
0
        public async Task InitializeAsync()
        {
            if (_testEnvironment.Mode == RecordedTestMode.Playback || _initialized)
            {
                return;
            }

            _initialized = true;
            var metricClient = new MetricsClient(_testEnvironment.MetricsEndpoint, _testEnvironment.Credential);

            while (!await MetricsPropagated(metricClient))
            {
                await SendData();

                await Task.Delay(TimeSpan.FromSeconds(5));
            }
        }
コード例 #11
0
        public CloudServiceAutoscalerHelper()
        {
            // Read configuration settings.
            var subscriptionId = ConfigurationManager.AppSettings["SubscriptionId"];
            var certThumbprint = ConfigurationManager.AppSettings["CertThumbprint"];

            this.cloudServiceName = ConfigurationManager.AppSettings["CloudServiceName"];
            this.roleName         = ConfigurationManager.AppSettings["RoleName"];
            this.deploymentName   = ConfigurationManager.AppSettings["DeploymentName"];
            this.isProduction     = bool.Parse(ConfigurationManager.AppSettings["IsProduction"]);

            // Get the certificate from the local store.
            var cert = CertificateHelper.GetCertificate(StoreName.My, StoreLocation.CurrentUser, certThumbprint);

            // Create the autoscale client.
            this.autoscaleClient = new AutoscaleClient(new CertificateCloudCredentials(subscriptionId, cert));

            // Create the metrics client.
            this.metricsClient = new MetricsClient(new CertificateCloudCredentials(subscriptionId, cert));
        }
コード例 #12
0
        public List <TweetMetricModel> GetTweetMetrics(List <string> tweetIds)
        {
            MetricsClient           metricsClient = new MetricsClient(_oAuthInfo);
            List <TweetMetricModel> metricModels  = new List <TweetMetricModel>();

            string response = metricsClient.GetTweetMetrics(tweetIds);

            TweetMetricDTO tweetMetrics = JsonConvert.DeserializeObject <TweetMetricDTO>(response);

            foreach (Data metricData in tweetMetrics.data)
            {
                metricModels.Add(new TweetMetricModel
                {
                    tweet_id         = metricData.tweet_id,
                    impression_count = metricData.tweet.impression_count,
                    like_count       = metricData.tweet.like_count,
                    quote_count      = metricData.tweet.quote_count,
                    reply_count      = metricData.tweet.reply_count,
                    retweet_count    = metricData.tweet.retweet_count
                });
            }
            return(metricModels);
        }
コード例 #13
0
        private static void GetMetricDefinitions(MetricsClient metricsClient, string resourceId)
        {
            //Get the metric definitions.
            var retrieveMetricsTask =
                metricsClient.MetricDefinitions.List(resourceId, null, "");
            var metricListResponse = retrieveMetricsTask;

            var metricDefinitions = metricListResponse.MetricDefinitionCollection.Value;

            // Display the metric definitions.
            var count = 0;

            foreach (var metricDefinition in metricDefinitions)
            {
                Console.WriteLine("MetricDefinitio: " + count++);
                Console.WriteLine("Display Name: " + metricDefinition.DisplayName);
                Console.WriteLine("Metric Name: " + metricDefinition.Name);
                Console.WriteLine("Metric ResourceId Suffix: " + metricDefinition.ResourceIdSuffix);
                Console.WriteLine("Metric Namespace: " + metricDefinition.Namespace);
                Console.WriteLine("Is Altertable: " + metricDefinition.IsAlertable);
                Console.WriteLine("Min. Altertable Time Window: " + metricDefinition.MinimumAlertableTimeWindow);
                Console.WriteLine();
            }
        }
コード例 #14
0
 public async Task Can_Send_A_Single_Metric()
 {
     await MetricsClient.SendAsync(GenerateTestMetric()).ConfigureAwait(false);
 }