コード例 #1
0
ファイル: DataStore.cs プロジェクト: gaybro8777/common
        public SystemDevice(SystemConfiguration config, DataStorage storage)
            : base("System", storage)
        {
            m_log = LogManager.GetLogger(typeof(SystemDevice));

            Devices = new List <Device>();

            config.devices.ForEach(m => { if (m.type != EDeviceType.System)
                                          {
                                              Devices.Add(new Device(m, this, Storage));
                                          }
                                   });

            DeviceInfo    system = config.devices.Find(d => d.type == EDeviceType.System);
            CollectorInfo ping   = null;

            if (system != null)
            {
                ping = system.collectors.Find(c => c.collectorType == ECollectorType.Ping);
            }

            if (ping != null && ping.isEnabled)
            {
                Collect(new PingCollector(new CollectorID(ping.id, Name)));
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the list of DataIDs that should go away
        /// </summary>
        /// <param name="collector">Which collector is being pruned</param>
        /// <param name="span">The desired span between data that is retained</param>
        /// <param name="saved_count">How many data records will be saved</param>
        /// <param name="conn">The DB connection</param>
        /// <returns>The list of DataIDs</returns>
        private static List <long> GatherDoomedData(CollectorInfo collector, TimeSpan span, out long saved_count, SQLiteConnection conn)
        {
            List <long> doomed = new List <long>();

            string sql = $"SELECT DataID, TimeStamp FROM Data WHERE CollectorID = {collector.id} ORDER BY TimeStamp DESC;";

            saved_count = 0;
            using (SQLiteCommand command = new SQLiteCommand(sql, conn))
                using (SQLiteDataReader reader = command.ExecuteReader())
                {
                    DateTimeOffset?next_time = null;

                    while (reader.Read())
                    {
                        DateTimeOffset timestamp = DateTimeOffset.Parse(reader.GetString(1));
                        if (next_time.HasValue == false)
                        {
                            next_time = timestamp - span;
                            ++saved_count;
                        }
                        else if (timestamp < next_time.Value)
                        {
                            next_time -= span;
                            ++saved_count;
                        }
                        else
                        {
                            long data_id = reader.GetInt64(0);
                            doomed.Add(data_id);
                        }
                    }
                }

            return(doomed);
        }
コード例 #3
0
        public List <CollectorInfo> GetAllCollectors()
        {
            List <CollectorInfo> collectors = new List <CollectorInfo>();
            CollectorInfo        info       = new CollectorInfo(ECollectorType.CPUUsage);

            info.CID = new CollectorID(1, "Device1.CPU");
            info.DID = new DeviceID(1, "Device1");
            collectors.Add(info);
            return(collectors);
        }
コード例 #4
0
        private CollectorInfo CollectNow(int collectorID)
        {
            Database db = new Database();

            using (SQLiteConnection conn = db.Connection)
            {
                conn.Open();
                CollectionTime ct             = new CollectionTime(conn);
                CollectorInfo  collector_info = ct.CollectNow(collectorID);
                return(collector_info);
            }
        }
コード例 #5
0
        public string Edit(FormDataCollection form)
        {
            string        retVal    = string.Empty;
            string        operation = form.Get("oper");
            int           id        = ConvertHelper.ToInt32(form.Get("CollectorId"));
            CollectorInfo info      = null;

            if (!string.IsNullOrEmpty(operation))
            {
                switch (operation)
                {
                case "edit":
                    info = CollectorRepository.GetInfo(id);
                    if (info != null)
                    {
                        info.Code = form.Get("Code");

                        info.Name = form.Get("Name");

                        info.Description = form.Get("Description");

                        info.ChangedBy = UserRepository.GetCurrentUserInfo().UserID;

                        CollectorRepository.Update(info);
                    }
                    break;

                case "add":
                    info = new CollectorInfo();

                    info.Code = form.Get("Code");

                    info.Name = form.Get("Name");

                    info.Description = form.Get("Description");

                    info.CreatedBy = UserRepository.GetCurrentUserInfo().UserID;

                    CollectorRepository.Create(info);
                    break;

                case "del":
                    CollectorRepository.Delete(id, UserRepository.GetCurrentUserInfo().UserID);
                    break;

                default:
                    break;
                }
            }
            return(retVal);
        }
コード例 #6
0
        private static void PruneCollector(CollectorInfo collector, SQLiteConnection conn)
        {
            Console.WriteLine($">>> Starting prune for {collector.name}");
            ECollectorType type = collector.collectorType;
            int            default_frequency = type.GetFrequencyInMinutes();
            TimeSpan       span = TimeSpan.FromMinutes(default_frequency);

            Stopwatch watch = Stopwatch.StartNew();

            List <long> doomed = GatherDoomedData(collector, span, out long saved_count, conn);

            Console.WriteLine($"Found {doomed.Count} records to delete, {saved_count} will be retained");
            Console.WriteLine($"Search took {watch.ElapsedMilliseconds} ms");

            watch.Restart();

            MeetTheirDemise(doomed, conn);

            Console.WriteLine($"<<< Completed prune for {collector.name}, it took {watch.ElapsedMilliseconds} ms");
        }
コード例 #7
0
        public void CollectNowProperly()
        {
            using (FileDeleter fd = new FileDeleter(Extensions.GetTempDBFile()))
            {
                Database db = new Database(new Context(fd.Fi));
                using (SQLiteConnection conn = db.Connection)
                {
                    conn.Open();
                    Initializer init = new Initializer(null);
                    init.Initialize(db);

                    Tuple <List <DeviceInfo>, DateTimeOffset> devices = LoadDevices(db, conn);
                    DBCollectionTimeRetriever retriever = new DBCollectionTimeRetriever(conn);
                    List <long> collector_ids           = retriever.AllIDs;

                    // At first, all of the collectors will have a NULL value, so we need to
                    // get them to a non-NULL value.
                    collector_ids.ForEach(c => new BeingCollected(c, conn).Dispose());

                    // Now lets go through each of them and make sure that when we collect now
                    // the next time changes to NULL, and re-appears
                    CollectionTime ct = new CollectionTime(conn);
                    foreach (long collector_id in collector_ids)
                    {
                        retriever = new DBCollectionTimeRetriever(conn);
                        Assert.DoesNotContain(collector_id, retriever.AllIDs);

                        CollectorInfo collector_info = ct.CollectNow(collector_id);
                        Assert.Equal(collector_id, collector_info.id);

                        retriever = new DBCollectionTimeRetriever(conn);
                        Assert.Contains(collector_id, retriever.AllIDs);

                        Assert.Null(collector_info.nextCollectionTime);
                    }
                }
            }
        }
コード例 #8
0
ファイル: CollectorRepository.cs プロジェクト: HungNV88/CRM
 public static void Update(CollectorInfo info)
 {
     DataProvider.Instance().Collectors_Update(info.CollectorId, info.Code, info.Name, info.Description, info.ChangedBy);
 }
コード例 #9
0
ファイル: CollectorRepository.cs プロジェクト: HungNV88/CRM
 public static int Create(CollectorInfo info)
 {
     return(DataProvider.Instance().Collectors_Insert(info.Code, info.Name, info.Description, info.CreatedBy));
 }
コード例 #10
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                try
                {
                    //fill business object
                    var info = new CollectorInfo();

                    /*
                     *
                     *
                     * info.CollectorId = collection["CollectorId"];
                     *
                     *
                     *
                     * info.Code = collection["Code"];
                     *
                     *
                     *
                     *
                     * info.Name = collection["Name"];
                     *
                     *
                     *
                     *
                     * info.Description = collection["Description"];
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     * info.CreatedBy = collection["CreatedBy"];
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     * info.ChangedBy = collection["ChangedBy"];
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     *
                     */
                    CollectorRepository.Create(info);
                }
                catch (Exception ex)
                {
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #11
0
 //修改回收员
 public int UpdCollector(CollectorInfo collector)
 {
     return(GetBll <CollectorInfo> .createDal().Upd(collector));
 }
コード例 #12
0
ファイル: DataStore.cs プロジェクト: gaybro8777/common
        private void CreateDataCollectors()
        {
            if (m_device_info.type.IsWindowsMachine())
            {
                Remote ri = new Remote(m_device_info.ipAddress, m_device_info.username, m_device_info.password);

                CollectorInfo ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.Memory);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new MemoryUsageCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.Disk);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new DiskUsageCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.CPUUsage);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new CPUUsageCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.NICUsage);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new NICUsageCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.Uptime);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new UptimeCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.LastBootTime);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new LastBootTimeCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.Processes);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new ProcessesCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.InstalledApplications);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new ApplicationsCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.Services);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new ServicesCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.SystemErrors);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new SystemErrorLogCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.ApplicationErrors);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new ApplicationErrorLogCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.UPS);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new UPSCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.DatabaseSize);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new DatabaseSizeCollector(new CollectorID(ci.id, Name), m_device_info.type == EDeviceType.Server, new DatabaseCollectorFactory()));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.DiskSpeed);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new DiskSpeedCollector(new CollectorID(ci.id, Name), ri));
                }

                ci = m_device_info.collectors.Find(c => c.collectorType == ECollectorType.SMART);
                if (ci != null && ci.isEnabled)
                {
                    Collect(new SMARTCollector(new CollectorID(ci.id, Name), ri));
                }

                //ci = m_device_info.collectors.Find(c => c.collectorType == CollectorType.AntiVirus);
                //if (ci != null && ci.isEnabled)
                //    Collect(new AntiVirusCollector(new CollectorID(ci.id, Name), ri));

                //ci = m_device_info.collectors.Find(c => c.collectorType == CollectorType.Firewall);
                //if (ci != null && ci.isEnabled)
                //    Collect(new FirewallCollector(new CollectorID(ci.id, Name), ri));
            }
        }