Exemplo n.º 1
0
        public MessageProcessor(IMonikServiceSettings settings, IRepository repository, 
            ICacheLog cacheLog, ICacheKeepAlive cacheKeepAlive, ICacheMetric cacheMetric,
            IMonik monik)
        {
            _settings = settings;
            _repository = repository;
            _cacheLog = cacheLog;
            _cacheKeepAlive = cacheKeepAlive;
            _cacheMetric = cacheMetric;
            _monik = monik;

            _cleaner = Scheduler.CreatePerHour(_monik, CleanerTask, "cleaner");
            _statist = Scheduler.CreatePerHour(_monik, StatistTask, "statist");
        }
Exemplo n.º 2
0
        public MainNancyModule(IRepository repo, ICacheLog cacheLog, ICacheKeepAlive cacheKeepAlive,
                               ICacheMetric cacheMetric, ICacheSourceInstance sourceInstanceCache, IMonik monik)
        {
            _repo                = repo;
            _cacheLog            = cacheLog;
            _cacheKeepAlive      = cacheKeepAlive;
            _cacheMetric         = cacheMetric;
            _sourceInstanceCache = sourceInstanceCache;
            _monik               = monik;

            Get("/sources", args =>
            {
                try
                {
                    List <Source> result = sourceInstanceCache.GetAllSources();
                    return(Response.AsJson <Source[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /sources : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/instances", args =>
            {
                try
                {
                    List <Instance> result = sourceInstanceCache.GetAllInstances();
                    return(Response.AsJson <Instance[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /instances : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/groups", args =>
            {
                try
                {
                    List <Group> result = sourceInstanceCache.GetAllGroups();
                    return(Response.AsJson <Group[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /groups : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/logs5", args =>
            {
                try
                {
                    var filter = this.Bind <LogRequest>();

                    List <Log_> result = cacheLog.GetLogs5(filter);
                    return(Response.AsJson <Log_[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /logs5 : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/keepalive2", args =>
            {
                var filter = this.Bind <KeepAliveRequest>();

                try
                {
                    List <KeepAlive_> result = cacheKeepAlive.GetKeepAlive2(filter);
                    return(Response.AsJson <KeepAlive_[]>(result.ToArray()));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /keepalive : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/keepalive-status", args =>
            {
                var filter = new KeepAliveRequest();
                return(GetKeepAliveStatuses(filter));
            });

            Post("/keepalive-status", args =>
            {
                var filter = this.Bind <KeepAliveRequest>();
                return(GetKeepAliveStatuses(filter));
            });

            Get("/metrics", args =>
            {
                try
                {
                    var result = cacheMetric.GetMetricsDescriptions();
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/currents", args =>
            {
                try
                {
                    var result = cacheMetric.GetAllCurrentMeasures();
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/currents : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/metrics/currents", args =>
            {
                try
                {
                    var filter = this.Bind <MetricRequest>();

                    var result = cacheMetric.GetCurrentMeasures(filter);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method POST /metrics/currents : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/{id:int}/current", args =>
            {
                try
                {
                    int metricId = args.id;

                    var result = cacheMetric.GetCurrentMeasure(metricId);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/id/current : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/windows", args =>
            {
                try
                {
                    var result = cacheMetric.GetAllWindowsMeasures();
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/windows : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Post("/metrics/windows", args =>
            {
                try
                {
                    var filter = this.Bind <MetricRequest>();

                    var result = cacheMetric.GetWindowMeasures(filter);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method POST /metrics/windows : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/{id:int}/window", args =>
            {
                try
                {
                    int metricId = args.id;

                    var result = cacheMetric.GetWindowMeasure(metricId);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/id/window : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });

            Get("/metrics/{id:int}/history", args =>
            {
                try
                {
                    int metricId = args.id;
                    var p        = this.Bind <MetricHistoryRequestParameters>();
                    var result   = cacheMetric.GetMetricHistory(metricId, p.Amount, p.Skip);
                    return(Response.AsJson(result));
                }
                catch (Exception ex)
                {
                    monik.ApplicationError($"Method /metrics/id/history : {ex.Message}");
                    return(HttpStatusCode.InternalServerError);
                }
            });
        }