예제 #1
0
 public void Enqueue(string queueID, IList <T> items)
 {
     ParamterUtil.CheckEmptyString("queueID", queueID);
     ParamterUtil.CheckNull("items", items);
     try
     {
         if (items.Count > 0)
         {
             WorkerQueue <T> workerQueue = this.PickupQueue(queueID);
             if (workerQueue == null)
             {
                 DebugUtil.Log(string.Format("WorkerQueueGroup: failed to pick up queue with id '{0}'.", queueID));
             }
             else
             {
                 foreach (T item in items)
                 {
                     workerQueue.Enqueue(item);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         DebugUtil.LogException(exception);
     }
 }
예제 #2
0
 public static void WritePoint(string metric, IDictionary <string, string> fields, IDictionary <string, string> tags, DateTime timestampInUTC, string db, string rp)
 {
     ParamterUtil.CheckEmptyString("metric", metric);
     ParamterUtil.CheckEmptyString("db", db);
     ParamterUtil.CheckEmptyString("rp", rp);
     if (AppContext.MeasurementEnabled)
     {
         if ((fields == null ? false : fields.Count > 0))
         {
             MetricPoint metricPoint = new MetricPoint(metric, db, rp);
             foreach (KeyValuePair <string, string> field in fields)
             {
                 BuildFields(metricPoint.Fields, field.Key, field.Value);
             }
             if ((tags == null ? false : tags.Count > 0))
             {
                 foreach (KeyValuePair <string, string> tag in tags)
                 {
                     BuildTags(metricPoint.Tags, tag.Key, tag.Value);
                 }
             }
             metricPoint.TimeStamp = timestampInUTC.ToString("yyyy/MM/dd HH:mm:ss.ffffff");
             MeasurementHost.Instance.Submit(metricPoint);
         }
     }
 }
예제 #3
0
        public static List <MetricSerie> ReadPoints(string query)
        {
            ParamterUtil.CheckEmptyString("query", query);
            string measurementDB = AppContext.MeasurementDB;

            if (string.IsNullOrEmpty(measurementDB))
            {
                throw new ArgumentException("MeasurementDB missing from config file.");
            }
            return(ReadPoints(measurementDB, query));
        }
예제 #4
0
        public List <MetricSerie> PerformQuery(string db, string query)
        {
            List <MetricSerie> metricSeries;

            ParamterUtil.CheckEmptyString("db", db);
            ParamterUtil.CheckEmptyString("query", query);
            List <MetricSerie> metricSeries1 = new List <MetricSerie>();

            try
            {
                DebugUtil.Log(string.Format("MeasurementHost: performing query '{0}' on db '{1}'.", query, db));
                string appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.MeasurementApi);
                if (string.IsNullOrEmpty(appUri))
                {
                    DebugUtil.Log("MeasurementHost: failed to fetch measurementServerInfo.Uri from location.");
                }
                else
                {
                    string  str     = string.Format("{0}api/measurement/run", appUri);
                    Command command = new Command()
                    {
                        Type = CommandType.Read
                    };
                    command.Parameters.Add("dbname", db);
                    command.Parameters.Add("query", query);
                    FoundationResponse <string> result = ProxyBase.Call <FoundationResponse <string>, Command>(str, command, ApiHttpMethod.POST, 180000, null).Result;
                    if ((result == null ? true : string.IsNullOrEmpty(result.Data)))
                    {
                        DebugUtil.Log(string.Format("MeasurementHost: query '{0}' on db '{1}' return empty.", query, db));
                    }
                    else
                    {
                        metricSeries1 = JsonSerializerUtil.Deserialize <List <MetricSerie> >(result.Data);
                    }
                    metricSeries = metricSeries1;
                    return(metricSeries);
                }
            }
            catch (Exception exception)
            {
                DebugUtil.LogException(exception);
            }
            metricSeries = metricSeries1;
            return(metricSeries);
        }
예제 #5
0
        public static List <MetricSerie> ReadPoints(string db, string query)
        {
            ParamterUtil.CheckEmptyString("db", db);
            ParamterUtil.CheckEmptyString("query", query);
            List <MetricSerie> metricSeries = null;

            try
            {
                metricSeries = MeasurementHost.Instance.PerformQuery(db, query);
                if (metricSeries == null)
                {
                    metricSeries = new List <MetricSerie>();
                }
            }
            catch (Exception exception)
            {
                DebugUtil.LogException(exception);
            }
            return(metricSeries);
        }
예제 #6
0
 public MeasurementScope(string scopeName, IDictionary <string, string> userTags = null)
 {
     ParamterUtil.CheckEmptyString("scopeName", scopeName);
     try
     {
         this._scopeName = scopeName;
         this._userTags  = new Dictionary <string, string>();
         if (userTags != null)
         {
             foreach (string key in userTags.Keys)
             {
                 this._userTags.Add(key, userTags[key]);
             }
         }
         this._scopeExecTime = (long)-1;
         this._sw            = Stopwatch.StartNew();
         this.BeginTrace();
     }
     catch (Exception exception)
     {
         DebugUtil.LogException(exception);
     }
 }
예제 #7
0
 public MeasurementHelper(string metric, string db, string rp = "default")
 {
     ParamterUtil.CheckEmptyString("metric", metric);
     ParamterUtil.CheckEmptyString("db", db);
     this.Init(metric, db, rp);
 }
예제 #8
0
 public MeasurementHelper(string metric)
 {
     ParamterUtil.CheckEmptyString("metric", metric);
     this.Init(metric, AppContext.MeasurementDB, AppContext.MeasurementDBRetentionPolicy);
 }