Exemplo n.º 1
0
        // ---------------- Constructor ----------------

        public CryptometheusRunner(Settings settings)
        {
            this.settings = settings;
            this.client   = new HttpClient();
            this.client.DefaultRequestHeaders.Add("User-Agent", userAgent);

            this.apiReader = new ApiReader(this.client, this.settings);
            this.apiReader.OnSuccessfulRead += this.ApiReader_OnSuccessfulRead;
            this.apiReader.OnError          += this.ApiReader_OnError;

            this.gagues = new Dictionary <string, IGauge>();
            foreach (string ticker in settings.Tickers)
            {
                GaugeConfiguration config = new GaugeConfiguration
                {
                    SuppressInitialValue = true
                };

                this.gagues[ticker] = Metrics.CreateGauge(
                    ticker.Replace('-', '_'),
                    $"Price of {ticker}",
                    config
                    );
            }

            this.exceptionCount = Metrics.CreateCounter(
                "error_count",
                $"How many exceptions has {nameof( Cryptometheus )} reported since the process started?"
                );

            this.started = false;
        }
Exemplo n.º 2
0
        public Gauge CreateGauge(string name, string help, GaugeConfiguration configuration)
        {
            configuration = configuration ?? GaugeConfiguration.Default;

            var metric = new Gauge(name, help, configuration.LabelNames, configuration.SuppressInitialValue);

            return((Gauge)_registry.GetOrAdd(metric));
        }
Exemplo n.º 3
0
        static void CreateMetricProviders(string metricDefinitionFile)
        {
            // Read metric definition and create array of MetricDefinition objects.
            string definition = File.ReadAllText(metricDefinitionFile);

            MetricDefinition[] metricDefinitions = MetricDefinition.FromJson(definition);

            foreach (MetricDefinition def in metricDefinitions)
            {
                string service_name = def.ServiceName;
                string url          = def.Url;
                foreach (Metric metric in def.Metrics)
                {
                    string                            api_endpoint            = metric.ApiEndpoint != null ? url + metric.ApiEndpoint : null;
                    string                            metric_name             = def.ServiceName + "_" + metric.MetricName;
                    string                            reponse_body_identifier = metric.DesiredResponseField;
                    AuthCredentials                   auth_credentials        = def.AuthCredentials;
                    Dictionary <string, double>       string_value_mapping    = metric.StringValueMapping;
                    SortedDictionary <string, string> labels        = metric.Labels;
                    ResponseType                      responseType  = metric.ResponseType;
                    ExecutionType                     executionType = metric.ExecutionType;

                    // Create MetricEndpoint which executes API calls or executes a program/script
                    MetricProvider metricEndpoint = null;
                    if (executionType == ExecutionType.SCRIPT && metric.Program != null && metric.Argument != null)
                    {
                        metricEndpoint = new MetricProvider(metric_name, metric.Program, metric.Argument, labels, executionType);
                    }
                    else if (executionType == ExecutionType.API_CALL && api_endpoint != null)
                    {
                        metricEndpoint = new MetricProvider(api_endpoint, metric_name, reponse_body_identifier, auth_credentials, string_value_mapping, labels, responseType, executionType);
                    }

                    // Create Prometheus Gauges
                    GaugeConfiguration config = new GaugeConfiguration();
                    if (labels != null)
                    {
                        config.LabelNames = labels.Keys.ToArray();
                    }
                    Gauge metricGauge = Metrics.CreateGauge(name: metric_name, help: metric_name, config);
                    mPrometheusMetricManager.AddMetricStruct(metricEndpoint, metricGauge);
                }
            }
        }
Exemplo n.º 4
0
        protected virtual ICollector <IGauge> CreateRequestsInProgressGauge()
        {
            string[] defaultLabels = new[] { "operation" };

            var configuration = new GaugeConfiguration
            {
                SuppressInitialValue = true,
                LabelNames           = defaultLabels
            };

            _options.ConfigureRequestsInProgressGauge?.Invoke(configuration);

            if (configuration.LabelNames != defaultLabels)
            {
                throw new ArgumentException("The requests in progress gauge configuration is missing the required default labels");
            }

            return(_metrics.CreateGauge("http_server_requests_in_progress", "The number of HTTP requests currently being processed by the application", configuration));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Gauges can have any numeric value and change arbitrarily.
 /// </summary>
 public static Gauge CreateGauge(string name, string help, GaugeConfiguration configuration = null) =>
 _defaultFactory.CreateGauge(name, help, configuration);
Exemplo n.º 6
0
 public Gauge GetOrAddGauge(string name, string description, GaugeConfiguration config = null)
 {
     return(Gauges.GetOrAdd(name, Prometheus.Metrics.CreateGauge(name, description, config)));
 }
Exemplo n.º 7
0
 /// <inheritdoc/>
 public Gauge Gauge(string name, string help, GaugeConfiguration configuration = null)
 {
     return(_innerMetricFactory.CreateGauge(name, help, configuration));
 }