예제 #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public void LogResponse(IApiRequest pApiReq)
        {
            IOperationContext oc = pApiReq.OpCtx;
            long totalMs         = (long)GetTimerMilliseconds();
            long jsonLen         = (Json == null ? 0 : Json.Length);

            ThreadPool.QueueUserWorkItem(w => {
                try {
                    oc.Analytics.TrackRequest(pApiReq.Method, pApiReq.Path);
                }
                catch (Exception e) {
                    Log.Error("Analytics failure", e);
                }
            });

            ////

            IMetricsManager m   = oc.Metrics;
            string          key = BuildGraphiteKey(pApiReq);

            m.Counter(key, 1);
            m.Counter(key + ".requests", 1);
            m.Counter(key + ".errors", (IsError ? 1 : 0));
            m.Timer(key + ".total-ms", totalMs);
            m.Mean(key + ".json-len", jsonLen);

            if (oc.Data.DbQueryExecutionCount > 0)
            {
                m.Timer(key + ".db", oc.Data.DbQueryMillis);
                m.Mean(key + ".db.queries", oc.Data.DbQueryExecutionCount);
            }

            //ARv1: (ApiResponse log, version 1)
            // IP, QueryCount, TotalMs, JsonLen, Timestamp, HttpStatus, IsError, Method, Path, Exception

            const string name  = "ARv1";
            const string x     = " | ";
            string       ctxId = Logger.GuidToString(oc.ContextId);

            string v1 =
                pApiReq.IpAddress + x +
                oc.Data.DbQueryExecutionCount + x +
                totalMs + x +
                jsonLen + x +
                DateTime.UtcNow.Ticks + x +
                (int)Status + x +
                (IsError ? 1 : 0) + x +
                pApiReq.Method + x +
                pApiReq.Path;

            if (Unhandled == null)
            {
                Log.Info(ctxId, name, v1);
            }
            else
            {
                Log.Error(ctxId, name, v1, Unhandled);
            }
        }
예제 #2
0
        /*--------------------------------------------------------------------------------------------*/
        private bool IsCacheHit(string pName, string pKey)
        {
            bool hit = Contains(pKey);

            vMetrics.Counter("cache.mem." + pName + "." + (hit ? "hit" : "miss"), 1);
            return(hit);
        }
예제 #3
0
        /*--------------------------------------------------------------------------------------------*/
        protected virtual void OnDataPostExecute(IDataAccess pAccess, IResponseResult pResult)
        {
            DbQueryExecutionCount++;
            DbQueryMillis += (pResult.Response.Timer == null ? 0 : (int)pResult.Response.Timer);

            string key = "opdata." + pAccess.ExecuteName;

            vMetrics.Counter(key, 1);

            if (pResult.Response.Timer != null)
            {
                vMetrics.Timer(key + ".rc", (long)pResult.Response.Timer);
            }

            vMetrics.Timer(key + ".ex", (long)pResult.ExecutionMilliseconds);
            vMetrics.Mean(key + ".len", pResult.ResponseJson.Length);
            vMetrics.Counter(key + ".err", (pResult.IsError ? 1 : 0));

            //Log.Debug(ContextId, "Data", "PostExec timer: "+pResult.Response.Timer+"ms");
            //Log.Debug(ContextId.ToString("N"), "Data", "Request: "+pResult.RequestJson);
            //Log.Debug(ContextId.ToString("N"), "Data", "Response: "+pResult.ResponseJson);
        }