Beispiel #1
0
        public void Can_Report_Pitaya_Metrics()
        {
            var cm = new CustomMetricsSpec();

            cm.Counters.Add(new CustomCounter()
            {
                Subsystem = "subsystem", Name = "nameC", Help = "help"
            });
            cm.Gauges.Add(new CustomGauge()
            {
                Subsystem = "subsystem", Name = "nameG", Help = "help"
            });
            cm.Summaries.Add(new CustomSummary()
            {
                Subsystem = "subsystem", Name = "nameS", Help = "help", Objectives = null
            });
            var prometheusMR = new PrometheusMetricsReporter("default", "game", 9090, null, null, cm);

            MetricsReporters.AddMetricReporter(prometheusMR);

            for (var i = 0; i < 5; ++i)
            {
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;

                    MetricsReporters.ReportTimer("success", "game.remoteGame.test", "rpc", "", Stopwatch.StartNew());
                    MetricsReporters.ReportMessageProccessDelay("game.remoteGame.test", "rpc", Stopwatch.StartNew());
                    MetricsReporters.ReportNumberOfConnectedClients(1);
                    MetricsReporters.ReportSummary("nameS", new Dictionary <string, string>(), 1);
                    MetricsReporters.ReportGauge("nameG", new Dictionary <string, string>(), 1);
                    MetricsReporters.ReportCount("nameC", new Dictionary <string, string>(), 1);
                }).Start();
            }
        }
Beispiel #2
0
        public void Can_Report_Pitaya_Metrics()
        {
            var statsdMR = new StatsdMetricsReporter("localhost", 5000, "game");

            MetricsReporters.AddMetricReporter(statsdMR);

            for (var i = 0; i < 5; ++i)
            {
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;

                    MetricsReporters.ReportTimer("success", "game.remoteGame.test", "rpc", "", Stopwatch.StartNew());
                    MetricsReporters.ReportMessageProccessDelay("game.remoteGame.test", "rpc", Stopwatch.StartNew());
                    MetricsReporters.ReportNumberOfConnectedClients(1);
                    MetricsReporters.ReportSummary("nameS", new Dictionary <string, string>(), 1);
                    MetricsReporters.ReportGauge("nameG", new Dictionary <string, string>(), 1);
                    MetricsReporters.ReportCount("nameC", new Dictionary <string, string>(), 1);
                }).Start();
            }
        }
        internal static async Task <Response> HandleRpc(Protos.Request req, RPCType type, Stopwatch sw)
        {
            byte[] data  = req.Msg.Data.ToByteArray();
            Route  route = Route.FromString(req.Msg.Route);

            string handlerName = $"{route.service}.{route.method}";

            PitayaSession s        = null;
            var           response = new Response();

            RemoteMethod handler;

            if (type == RPCType.Sys)
            {
                s = new Models.PitayaSession(req.Session, req.FrontendID);
                if (!HandlersDict.ContainsKey(handlerName))
                {
                    response = GetErrorResponse("PIT-404",
                                                $"remote/handler not found! remote/handler name: {handlerName}");
                    return(response);
                }

                handler = HandlersDict[handlerName];
                MetricsReporters.ReportMessageProccessDelay(req.Msg.Route, "local", sw);
            }
            else
            {
                if (!RemotesDict.ContainsKey(handlerName))
                {
                    response = GetErrorResponse("PIT-404",
                                                $"remote/handler not found! remote/handler name: {handlerName}");
                    return(response);
                }

                handler = RemotesDict[handlerName];
                MetricsReporters.ReportMessageProccessDelay(req.Msg.Route, "remote", sw);
            }

            Task ans;

            if (handler.ArgType != null)
            {
                var arg = _serializer.Unmarshal(data, handler.ArgType);
                if (type == RPCType.Sys)
                {
                    ans = handler.Method.Invoke(handler.Obj, new[] { s, arg }) as Task;
                }
                else
                {
                    ans = handler.Method.Invoke(handler.Obj, new[] { arg }) as Task;
                }
            }
            else
            {
                if (type == RPCType.Sys)
                {
                    ans = handler.Method.Invoke(handler.Obj, new object[] { s }) as Task;
                }
                else
                {
                    ans = handler.Method.Invoke(handler.Obj, new object[] { }) as Task;
                }
            }

            await ans;

            byte[] ansBytes;

            if (handler.ReturnType != typeof(void))
            {
                ansBytes = SerializerUtils.SerializeOrRaw(ans.GetType().
                                                          GetProperty("Result")
                                                          ?.GetValue(ans), _serializer);
            }
            else
            {
                ansBytes = new byte[] {};
            }
            response.Data = ByteString.CopyFrom(ansBytes);
            return(response);
        }