/// <summary>
        /// Create and start a new metric tracker with the given period in seconds
        /// </summary>
        /// <param name="dataInterval"></param>
        public MetricsTracker(int dataInterval = 10, InfluxDBLineClient influxDbClient = null)
        {
            this.MetricCollectors = new List<IMetricCollector>();
            this._Metrics = new Dictionary<string, List<double>>();
            this._Counters = new Dictionary<string, double>();
            this.DataInterval = dataInterval;
            this._Timer = new Timer(this.TimerCallback, null, dataInterval * 1000, dataInterval * 1000);

            if (influxDbClient == null)
            {
                // Load the configuration data
                string serverUrl = ConfigurationManager.AppSettings["BunnyMetrics.InfluxDB.ServerUrl"];
                string databaseName = ConfigurationManager.AppSettings["BunnyMetrics.InfluxDB.DatabaseName"];
                string username = ConfigurationManager.AppSettings["BunnyMetrics.InfluxDB.Username"];
                string password = ConfigurationManager.AppSettings["BunnyMetrics.InfluxDB.Password"];

                // Load the a client with the default credentials
                influxDbClient = new InfluxDBLineClient(
                    serverUrl,
                    databaseName,
                    string.IsNullOrWhiteSpace(username) ? null : username,
                    string.IsNullOrWhiteSpace(password) ? null : password);
            }


            this.InfluxDBClient = influxDbClient;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new InfluxDBWriter object
 /// </summary>
 public InfluxDBWriter(InfluxDBLineClient client)
 {
     this.Client                 = client;
     this._StringBuilder         = new StringBuilder(2048);
     this._Buffer                = new byte[4096];
     this._HttpRequest           = this.GetServiceRequest();
     this._BufferedRequestStream = new BufferedStream(this._HttpRequest.GetRequestStream(), 4096);
 }
 /// <summary>
 /// Create a new InfluxDBWriter object
 /// </summary>
 public InfluxDBWriter(InfluxDBLineClient client)
 {
     this.Client = client;
     this._StringBuilder = new StringBuilder(2048);
     this._Buffer = new byte[4096];
     this._HttpRequest = this.GetServiceRequest();
     this._BufferedRequestStream = new BufferedStream(this._HttpRequest.GetRequestStream(), 4096);
 }
 /// <summary>
 /// Initialize the default metrics tracker with config loaded from the config file
 /// </summary>
 public static void InitializeDefault(int dataInterval = 10, InfluxDBLineClient influxDbClient = null)
 {
     if (MetricsTracker.Default == null)
     {
         MetricsTracker.Default = new MetricsTracker(dataInterval, influxDbClient);
     }
 }