public SubscriberStats(bool connected,
                        int reconnectCount,
                        int beatFailover,
                        long messageCount,
                        long beatCount,
                        long totalMessageCount,
                        string currentEndPoint,
                        string[] endPoints,
                        string topic,
                        string type,
                        string name,
                        SystemStats systemStats)
 {
     Connected         = connected;
     ReconnectCount    = reconnectCount;
     BeatFailover      = beatFailover;
     BeatCount         = beatCount;
     MessageCount      = messageCount;
     TotalMessageCount = totalMessageCount;
     CurrentEndPoint   = currentEndPoint;
     EndPoints         = endPoints;
     Topic             = topic;
     Type        = type;
     Name        = name;
     SystemStats = systemStats;
 }
        // TODO object caching where possible...
        // TODO read all from config file... (monitrc)
        public static monitServer GetMonitServerData()
        {
            var data = new monitServer();

            data.controlfile = "none"; // TODO
            data.startdelay  = 0;      // TODO

            data.localhostname = SystemStats.GetHostname();

            data.httpd = new monitServerHttpd()
            {
                address = ConfigMgr.Config.HttpdBindIp,
                port    = ConfigMgr.Config.HttpdPort,
                ssl     = (byte)(ConfigMgr.Config.HttpdSSL ? 1 : 0), // TODO
            };

            data.credentials = new monitServerCredentials()
            {
                password = ConfigMgr.Config.HttpdPassword,
                username = ConfigMgr.Config.HttpdUsername
            };

            data.poll = 120;  // TODO

            return(data);
        }
        public DateTime LoadCSV(string file)
        {
            mStats.Clear();

            bool skip = true;

            foreach (var line in File.ReadAllLines(file))
            {
                if (skip)
                {
                    skip = false;
                    string[] split = line.Split(',');
                    mSessionID = UUID.Parse(split[split.Length - 1]);
                    continue;
                }

                SystemStats s = new SystemStats(line, mConfig);
                mStats.Add(s);
            }

            string[] splitFilename = Path.GetFileNameWithoutExtension(file).Split(new char[] { '-' }, 2);
            mConfig.RunInfo = splitFilename[0];
            DateTime ret = DateTime.ParseExact(splitFilename[1], mConfig.TimestampFormat, new DateTimeFormatInfo());

            Logger.Info("Loaded pre recorded statistics from: " + file + ".");

            return(ret);
        }
Beispiel #4
0
        public ReturnModel <SystemStats> GetStats()
        {
            var stat = new SystemStats
            {
                AppDataFolderSize = GetAppDataFolderSize(),
                LogFolderSize     = GetLogFolderSize(),
                LogFileCount      = GetLogFileCount()
            };

            return(new ReturnModel <SystemStats>(stat));
        }
 void mCore_Tick()
 {
     mRecording = true;
     mLastStat  = new SystemStats(mConfig);
     lock (mStats) {
         if (!mConfig.OneSecMininum || mLastServerStatSec != mLastStat.TimeStamp.Second)
         {
             mStats.Add(mLastStat);
             mLastServerStatSec = mLastStat.TimeStamp.Second;
         }
     }
 }
        public static monitPlatform GetMonitPlatformData()
        {
            var data = new monitPlatform();

            data         = new monitPlatform();
            data.name    = Environment.OSVersion.Platform.ToString();
            data.version = Environment.OSVersion.Version.Build.ToString();
            data.machine = CPUAchitecture.IsOS64Bit() ? "x86_64" : "x86";
            data.release = Environment.OSVersion.Version.ToString(); // Environment.OSVersion.Version.Build.ToString();
            data.cpu     = SystemStats.GetCPUCoreCount();
            data.memory  = SystemStats.GetMemorySizeKB();

            // TODO
            data.swap = 0;

            return(data);
        }
        public void Init(Core coordinator)
        {
            SystemStats.InitialiseCounters();
            mCore         = coordinator;
            mTickListener = new Action(mCore_Tick);

            mConfig = ExperimentalConfig.Instance;

            /*
             * if (mCore.HasPlugin<AvatarMovementPlugin>()) {
             *  mMovementPlugin = mCore.GetPlugin<AvatarMovementPlugin>();
             *  mConfig = mMovementPlugin.Config as ExperimentalConfig;
             * } else
             *  mConfig = new ExperimentalConfig();
             */

            mCore.Tick += mTickListener;
        }
Beispiel #8
0
        /// <summary>
        /// Get "frame"-xml-data which is the same for different usecases
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private monitService GetNewServiceSkeleton(MonitServiceType type)
        {
            var serviceSekeleton = new monitService();

            serviceSekeleton.name = SystemStats.GetHostname();

            serviceSekeleton.type        = (int)type;
            serviceSekeleton.status      = 0;                                     // "error". Error flags bitmap, See MonitEventTable
            serviceSekeleton.status_hint = 0;                                     // "error_hint" See MonitEventTable
            serviceSekeleton.monitor     = (int)MonitMonitorStateType.MONITOR_YES;
            serviceSekeleton.monitormode = (int)MonitMonitorModeType.MODE_ACTIVE; // default

            var tf = Timing.GetTimingFraction();

            serviceSekeleton.collected_sec  = tf.Timestamp;
            serviceSekeleton.collected_usec = tf.Usec;

            return(serviceSekeleton);
        }
Beispiel #9
0
        private monitService GetSystemService()
        {
            var systemService = GetNewServiceSkeleton(MonitServiceType.TYPE_SYSTEM);

            systemService.system = new monitServiceSystem();

            systemService.name = SystemStats.GetHostname();

            // CPU
            systemService.system.cpu = new monitServiceSystemCpu
            {
                system = m_systemStats.GetCPULoadPercentage(),
                user   = 0,
            };

            // MEMORY
            var totalMem = PerformanceInfo.GetTotalMemoryInKiB();

            systemService.system.memory = new monitServiceSystemMemory()
            {
                kilobyte = totalMem,
                // calculating free mem, then substracting this from 100 to get used mem percentage
                percent = Math.Round(100 - ((decimal)PerformanceInfo.GetPhysicalAvailableMemoryInKiB() / (decimal)totalMem) * 100, 1),
            };

            // LOAD
            systemService.system.load = new monitServiceSystemLoad()
            {
                avg01 = 0.07,
                avg05 = 0.03,
                avg15 = 0.08,
            };

            // SWAP
            // Possible to use this on windows?
            systemService.system.swap = new monitServiceSystemSwap()
            {
                kilobyte = 0,
                percent  = 0,
            };

            return(systemService);
        }
Beispiel #10
0
        public SerializedInfo GetStatusXmlData()
        {
            var data = new monit();

            data.id          = UniqueWindowsId.GetOrCreateUniqueId();
            data.incarnation = SystemStats.ProcessRunningInSec();
            data.server      = MonitStatusGenericData.GetMonitServerData();
            data.platform    = MonitStatusGenericData.GetMonitPlatformData();
            data.version     = "5.6"; // TODO, decide how to use the correct version number here in the future

            var services = new List <monitService>();

            services.AddRange(GetFilesystemServices()); // TODO, should depend on config / controlfile
            services.Add(GetSystemService());           // TODO, should depend on config / controlfile
            // data.service.Add(GetHostService()); // TODO, depends on config / controlfile..

            data.services = services.ToArray();

            var status = SerializeMgr.Serialize(data);

            return(status);
        }
        public override void Run(bool autoCommit, SqlConnection cn, SqlTransaction tx)
        {
            Message   message    = null;
            ArrayList statsArray = new ArrayList();

            int  lastConnections = 0;
            long lastCpuBusy     = 0;
            long lastIdle        = 0;
            long lastIoBusy      = 0;
            int  lastPackErrors  = 0;
            int  lastPackRecd    = 0;
            int  lastPackSent    = 0;
            int  lastTotalErrors = 0;
            int  lastTotalRead   = 0;
            int  lastTotalWrite  = 0;

            Conversation conv;

            while ((conv = GetConversation(cn, tx)) != null)
            {
                while ((message = conv.Receive()) != null)
                {
                    if (message.Type == "http://schemas.apress.com/sqlassemblies/StatsRequestMessage")
                    {
                        XmlDocument msgDoc = new XmlDocument();
                        msgDoc.Load(message.Body);
                        SystemStats stats = new SystemStats();
                        stats.Connections = XmlConvert.ToInt32(msgDoc.SelectSingleNode("//connections").FirstChild.Value);
                        stats.CpuBusy     = XmlConvert.ToInt64(msgDoc.SelectSingleNode("//cpuBusy").FirstChild.Value);
                        stats.Idle        = XmlConvert.ToInt64(msgDoc.SelectSingleNode("//idle").FirstChild.Value);
                        stats.IoBusy      = XmlConvert.ToInt64(msgDoc.SelectSingleNode("//ioBusy").FirstChild.Value);
                        stats.PackErrs    = XmlConvert.ToInt32(msgDoc.SelectSingleNode("//packErrors").FirstChild.Value);
                        stats.PackRecd    = XmlConvert.ToInt32(msgDoc.SelectSingleNode("//packRecd").FirstChild.Value);
                        stats.PackSent    = XmlConvert.ToInt32(msgDoc.SelectSingleNode("//packSent").FirstChild.Value);
                        stats.TotalErrs   = XmlConvert.ToInt32(msgDoc.SelectSingleNode("//totalErrors").FirstChild.Value);
                        stats.TotalRead   = XmlConvert.ToInt32(msgDoc.SelectSingleNode("//totalRead").FirstChild.Value);
                        stats.TotalWrite  = XmlConvert.ToInt32(msgDoc.SelectSingleNode("//totalWrite").FirstChild.Value);
                        stats.Time        = XmlConvert.ToDateTime(msgDoc.SelectSingleNode("//time").FirstChild.Value, XmlDateTimeSerializationMode.Local);
                        statsArray.Add(stats);
                    }
                }
            }

            string     sql = @"SELECT TOP 1 TotalConnections, TotalCpuBusy, TotalIdle,
                                     TotalIoBusy, TotalPackErrors, TotalPackRecd,
                                     TotalPackSent, TotalErrors, TotalRead,
                                     TotalWrite
                        FROM SystemStats
                        ORDER BY Time DESC;";
            SqlCommand cmd = new SqlCommand(sql, cn);

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    lastConnections = (int)reader[0];
                    lastCpuBusy     = (long)reader[1];
                    lastIdle        = (long)reader[2];
                    lastIoBusy      = (long)reader[3];
                    lastPackErrors  = (int)reader[4];
                    lastPackRecd    = (int)reader[5];
                    lastPackSent    = (int)reader[6];
                    lastTotalErrors = (int)reader[7];
                    lastTotalRead   = (int)reader[8];
                    lastTotalWrite  = (int)reader[9];
                }
            }

            string     insertQuery = @"INSERT INTO SystemStats VALUES (@time, @connections,
                  @totalConnections, @cpuBusy, @totalCpuBusy, @idle, @totalIdle,
                  @ioBusy, @totalIoBusy, @packErrors, @totalPackErrors, @packRecd,
                  @totalPackRecd, @packSent, @totalPackSent, @numErrors,
                  @totalErrors, @numReads, @totalRead, @numWrites, @totalWrite)";
            SqlCommand insertCmd   = new SqlCommand(insertQuery, cn);

            SqlParameter timeParam          = new SqlParameter("@time", SqlDbType.DateTime);
            SqlParameter connParam          = new SqlParameter("@connections", SqlDbType.Int);
            SqlParameter totalConnParam     = new SqlParameter("@totalConnections", SqlDbType.Int);
            SqlParameter cpuParam           = new SqlParameter("@cpuBusy", SqlDbType.BigInt);
            SqlParameter totalCpuParam      = new SqlParameter("@totalCpuBusy", SqlDbType.BigInt);
            SqlParameter idleParam          = new SqlParameter("@idle", SqlDbType.BigInt);
            SqlParameter totalIdleParam     = new SqlParameter("@totalIdle", SqlDbType.BigInt);
            SqlParameter ioParam            = new SqlParameter("@ioBusy", SqlDbType.BigInt);
            SqlParameter totalIoParam       = new SqlParameter("@totalIoBusy", SqlDbType.BigInt);
            SqlParameter packErrsParam      = new SqlParameter("@packErrors", SqlDbType.Int);
            SqlParameter totalPackErrsParam = new SqlParameter("@totalPackErrors", SqlDbType.Int);
            SqlParameter packRecdParam      = new SqlParameter("@packRecd", SqlDbType.Int);
            SqlParameter totalPackRecdParam = new SqlParameter("@totalPackRecd", SqlDbType.Int);
            SqlParameter packSentParam      = new SqlParameter("@packSent", SqlDbType.Int);
            SqlParameter totalPackSentParam = new SqlParameter("@totalPackSent", SqlDbType.Int);
            SqlParameter numErrsParam       = new SqlParameter("@numErrors", SqlDbType.Int);
            SqlParameter totErrsParam       = new SqlParameter("@totalErrors", SqlDbType.Int);
            SqlParameter numReadsParam      = new SqlParameter("@numReads", SqlDbType.Int);
            SqlParameter totReadParam       = new SqlParameter("@totalRead", SqlDbType.Int);
            SqlParameter numWritesParam     = new SqlParameter("@numWrites", SqlDbType.Int);
            SqlParameter totWriteParam      = new SqlParameter("@totalWrite", SqlDbType.Int);

            insertCmd.Parameters.AddRange(new SqlParameter[] { timeParam, connParam,
                                                               totalConnParam, cpuParam, totalCpuParam, idleParam, totalIdleParam,
                                                               ioParam, totalIoParam, packErrsParam, totalPackErrsParam,
                                                               packRecdParam, totalPackRecdParam, packSentParam, totalPackSentParam,
                                                               numErrsParam, totErrsParam, numReadsParam, totReadParam,
                                                               numWritesParam, totWriteParam });
            insertCmd.Prepare();

            foreach (SystemStats statsElement in statsArray)
            {
                timeParam.Value          = statsElement.Time;
                connParam.Value          = statsElement.Connections - lastConnections;
                totalConnParam.Value     = statsElement.Connections;
                cpuParam.Value           = statsElement.CpuBusy - lastCpuBusy;
                totalCpuParam.Value      = statsElement.CpuBusy;
                idleParam.Value          = statsElement.Idle - lastIdle;
                totalIdleParam.Value     = statsElement.Idle;
                ioParam.Value            = statsElement.IoBusy - lastIoBusy;
                totalIoParam.Value       = statsElement.IoBusy;
                packErrsParam.Value      = statsElement.PackErrs - lastPackErrors;
                totalPackErrsParam.Value = statsElement.PackErrs;
                packRecdParam.Value      = statsElement.PackRecd - lastPackRecd;
                totalPackRecdParam.Value = statsElement.PackRecd;
                packSentParam.Value      = statsElement.PackSent - lastPackSent;
                totalPackSentParam.Value = statsElement.PackSent;
                numErrsParam.Value       = statsElement.TotalErrs - lastTotalErrors;
                totErrsParam.Value       = statsElement.TotalErrs;
                numReadsParam.Value      = statsElement.TotalRead - lastTotalRead;
                totReadParam.Value       = statsElement.TotalRead;
                numWritesParam.Value     = statsElement.TotalWrite - lastTotalWrite;
                totWriteParam.Value      = statsElement.TotalWrite;

                lastConnections = statsElement.Connections;
                lastCpuBusy     = statsElement.CpuBusy;
                lastIdle        = statsElement.Idle;
                lastIoBusy      = statsElement.IoBusy;
                lastPackErrors  = statsElement.PackErrs;
                lastPackRecd    = statsElement.PackRecd;
                lastPackSent    = statsElement.PackSent;
                lastTotalErrors = statsElement.TotalErrs;
                lastTotalRead   = statsElement.TotalRead;
                lastTotalWrite  = statsElement.TotalWrite;
                insertCmd.ExecuteNonQuery();
            }
        }
Beispiel #12
0
        public MonitWindowsAgent()
        {
            Run                   = new Run_T();
            Run.id                = UniqueWindowsId.GetOrCreateUniqueId();
            Run.incarnation       = SystemStats.ProcessRunningInSec();
            Run.controlfile       = "none"; //TODO
            Run.startdelay        = 0;      //TODO
            Run.polltime          = 120;    //TODO
            Run.Env               = new myenvironment();
            Run.Env.user          = SystemStats.GetHostname();
            Run.httpd             = new Httpd_T();
            Run.httpd.port        = ConfigMgr.Config.Httpd.Port;
            Run.httpd.ssl         = ConfigMgr.Config.Httpd.SSL;
            Run.httpd.address     = ConfigMgr.Config.Httpd.BindIp;
            Run.httpd.credentials = new List <Auth_T>();
            Run.httpd.credentials.Add(new Auth_T
            {
                uname  = ConfigMgr.Config.Httpd.Username,
                passwd = ConfigMgr.Config.Httpd.Password
            });

            Run.mmonits = new List <Mmonit_T>();
            Run.mmonits.Add(new Mmonit_T
            {
                url = new URL_T
                {
                    url = ConfigMgr.Config.MMonits[0].Url,
                    //port = ConfigMgr.Config.MMonits[0].Port,
                    password = ConfigMgr.Config.MMonits[0].Password,
                    user     = ConfigMgr.Config.MMonits[0].Username
                }
            });

            servicelist      = new List <Service_T>();
            servicelist_conf = new List <Service_T>();
            ConfigMgr.Config.Services.ForEach(sc =>
            {
                var newS = ServiceHelper.CreateService(sc, sc.Name.ToLower());

                if (newS == null)
                {
                    Logger.Log.Error("Service could not be created!");
                }
                else
                {
                    if (sc is ProcessConfig)
                    {
                        ProcessHelper.AddProcess(newS);
                    }
                    else if (sc is FilesystemConfig)
                    {
                        FilesystemHelper.AddFilesystem(newS);
                    }
                }
            });

            servicegrouplist = new List <ServiceGroup_T>();
            systeminfo       = SystemInfoHelper.GetSystemInfo();

            m_timer           = new Timer(ConfigMgr.Config.Period);
            m_timer.Elapsed  += DoPeriodicCheck;
            m_timer.AutoReset = true;

            m_mMonitClient = new Collector();

            var service = ServiceHelper.GetSystemService();

            Run.system = new List <Service_T>();
            Run.system.Add(service);
        }