Exemplo n.º 1
0
        private void ProcQueue(Object oIndex)
        {
            Int32 index = (Int32)oIndex;

            SendText("ProcQueue " + index, "Start, _running = " + _running);
            Debug.WriteLine("ProcQueue " + index + "Start, _running = " + _running);

            String sIndex = String.Format("{0:00000}", index);

            DataTable zabbixTable        = null;
            DataTable zabbixNetworkTable = null;

            if (OnBulkEvent != null)
            {
                zabbixTable = new DataTable();
                zabbixTable.Columns.Add(new DataColumn("date", typeof(DateTime)));
                zabbixTable.Columns.Add(new DataColumn("dateg", typeof(DateTime)));
                zabbixTable.Columns.Add(new DataColumn("pID", typeof(Int64)));
                zabbixTable.Columns.Add(new DataColumn("testID", typeof(String)));
                zabbixTable.Columns.Add(new DataColumn("host", typeof(String)));
                zabbixTable.Columns.Add(new DataColumn("key", typeof(String)));
                zabbixTable.Columns.Add(new DataColumn("selector", typeof(String)));
                zabbixTable.Columns.Add(new DataColumn("total_value", typeof(Int64)));
                zabbixTable.Columns.Add(new DataColumn("value", typeof(Int64)));

                zabbixNetworkTable = new DataTable();
                zabbixNetworkTable.Columns.Add(new DataColumn("date", typeof(DateTime)));
                zabbixNetworkTable.Columns.Add(new DataColumn("dateg", typeof(DateTime)));
                zabbixNetworkTable.Columns.Add(new DataColumn("pID", typeof(Int64)));
                zabbixNetworkTable.Columns.Add(new DataColumn("testID", typeof(String)));
                zabbixNetworkTable.Columns.Add(new DataColumn("host", typeof(String)));
                zabbixNetworkTable.Columns.Add(new DataColumn("interface", typeof(String)));
                zabbixNetworkTable.Columns.Add(new DataColumn("in_value", typeof(Int64)));
                zabbixNetworkTable.Columns.Add(new DataColumn("out_value", typeof(Int64)));
            }

            Int32 regCount = 0;

            while (_running)
            {
                try
                {
                    QueueItem queueItem = null;

                    while ((queueItem = _queue[index].nextItem) != null)
                    {
                        regCount++;

                        try
                        {
                            //Insere os registros nas tebelas locais temporárias
                            if (queueItem.Zabbix != null)
                            {
                                if (zabbixTable != null)
                                {
                                    zabbixTable.Rows.Add(new Object[] {
                                        queueItem.Zabbix.date,
                                        DateGroup(queueItem.Zabbix.date),
                                        i_pid,
                                        environment.TestName,
                                        queueItem.Zabbix.host,
                                        queueItem.Zabbix.key,
                                        queueItem.Zabbix.selector,
                                        queueItem.Zabbix.totalValue,
                                        queueItem.Zabbix.value
                                    });
                                }
                            }//if (queueItem.Zabbix != null)

                            //Insere os registros nas tebelas locais temporárias
                            if (queueItem.ZabbixNetwork != null)
                            {
                                if (zabbixNetworkTable != null)
                                {
                                    zabbixNetworkTable.Rows.Add(new Object[] {
                                        queueItem.ZabbixNetwork.date,
                                        DateGroup(queueItem.ZabbixNetwork.date),
                                        i_pid,
                                        environment.TestName,
                                        queueItem.ZabbixNetwork.host,
                                        queueItem.ZabbixNetwork.networkInterface,
                                        queueItem.ZabbixNetwork.inValue,
                                        queueItem.ZabbixNetwork.outValue
                                    });
                                }
                            }//if (queueItem.Zabbix != null)

                            queueItem.Dispose();
                        }
                        catch (Exception ex)
                        {
                            SendText("ProcQueue", "[" + index + "] Error 2: " + ex.Message + ex.StackTrace, true);
                        }

                        if (!_running)
                        {
                            break;
                        }

                        //Grava no banco a cada 500 ciclos do while
                        if (regCount > 100)
                        {
                            regCount = 0;
                            break; //Sai do while p/ gravar no db
                        }
                    }//While


                    //Quando sai do while verifica se há registros p/ gerar evento de bulk
                    if (OnBulkEvent != null)
                    {
                        Int32 itensCount = zabbixTable.Rows.Count;
                        if (((itensCount > 0) && (_running)) || (itensCount >= 100))
                        {
                            try
                            {
                                if (OnBulkEvent != null)
                                {
                                    if (zabbixTable.Rows.Count > 0)
                                    {
                                        OnBulkEvent(zabbixTable, "ZabbixMonitor");
                                    }

                                    if (zabbixNetworkTable.Rows.Count > 0)
                                    {
                                        OnBulkEvent(zabbixNetworkTable, "ZabbixMonitorNetwork");
                                    }
                                }

                                zabbixTable.Rows.Clear();
                            }
                            catch (Exception ex)
                            {
                                SendText("ProcQueue", "[" + index + "] Error 4: " + ex.Message + ex.StackTrace, true);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SendText("ProcQueue", "[" + index + "] Error 0: " + ex.Message + ex.StackTrace, true);
                }


                Thread.Sleep(300);
            }
            SendText("ProcQueue", "[" + index + "] Exit: ", true);
            Debug.WriteLine("ProcQueue" + "[" + index + "] Exit: ");
        }
Exemplo n.º 2
0
        private void ProcQueue(Object oIndex)
        {
            Int32 index = (Int32)oIndex;

            SendText("ProcQueue " + index, "Start, _running = " + _running);
            Debug.WriteLine("ProcQueue " + index + "Start, _running = " + _running);

            String sIndex = String.Format("{0:00000}", index);

            DataTable vuCountTable   = null;
            DataTable webResultTable = null;

            if (OnBulkEvent != null)
            {
                vuCountTable = new DataTable();
                vuCountTable.Columns.Add(new DataColumn("date", typeof(DateTime)));
                vuCountTable.Columns.Add(new DataColumn("dateg", typeof(DateTime)));
                vuCountTable.Columns.Add(new DataColumn("pID", typeof(Int64)));
                vuCountTable.Columns.Add(new DataColumn("testID", typeof(String)));
                vuCountTable.Columns.Add(new DataColumn("virtualUsers", typeof(Int64)));
                vuCountTable.Columns.Add(new DataColumn("connections", typeof(Int64)));

                webResultTable = new DataTable();
                webResultTable.Columns.Add(new DataColumn("date", typeof(DateTime)));
                webResultTable.Columns.Add(new DataColumn("dateg", typeof(DateTime)));
                webResultTable.Columns.Add(new DataColumn("pID", typeof(Int64)));
                webResultTable.Columns.Add(new DataColumn("testID", typeof(String)));
                webResultTable.Columns.Add(new DataColumn("uri", typeof(String)));
                webResultTable.Columns.Add(new DataColumn("statusCode", typeof(Int32)));
                webResultTable.Columns.Add(new DataColumn("contentType", typeof(String)));
                webResultTable.Columns.Add(new DataColumn("bytesReceived", typeof(Int64)));
                webResultTable.Columns.Add(new DataColumn("time", typeof(Double)));
                webResultTable.Columns.Add(new DataColumn("errorMessage", typeof(String)));
            }

            Int32 regCount = 0;

            while (_running)
            {
                try
                {
                    QueueItem queueItem = null;

                    while ((queueItem = _queue[index].nextItem) != null)
                    {
                        regCount++;

                        try
                        {
                            //Insere os registros nas tebelas locais temporárias
                            if (queueItem.VUCount != null)
                            {
                                if (vuCountTable != null)
                                {
                                    vuCountTable.Rows.Add(new Object[] {
                                        queueItem.VUCount.date,
                                        DateGroup(queueItem.VUCount.date),
                                        i_pid,
                                        environment.TestName,
                                        queueItem.VUCount.virtualUsersCount,
                                        queueItem.VUCount.connectionsCount
                                    });
                                }
                            }//if (queueItem.VUCount != null)

                            if (queueItem.Result != null)
                            {
                                if (webResultTable != null)
                                {
                                    webResultTable.Rows.Add(new Object[] {
                                        queueItem.Result.date,
                                        DateGroup(queueItem.Result.date),
                                        i_pid,
                                        environment.TestName,
                                        queueItem.Result.result.RequestUri,
                                        queueItem.Result.result.Code,
                                        queueItem.Result.result.ContentType,
                                        queueItem.Result.result.DataLength,
                                        queueItem.Result.result.Time.TotalMilliseconds,
                                        (queueItem.Result.result.ErrorMessage != null ? queueItem.Result.result.ErrorMessage : "")
                                    });
                                }
                            }//if (queueItem.Result != null)

                            queueItem.Dispose();
                        }
                        catch (Exception ex)
                        {
                            SendText("ProcQueue", "[" + index + "] Error 2: " + ex.Message + ex.StackTrace, true);
                        }

                        if (!_running)
                        {
                            break;
                        }

                        //Grava no banco a cada 500 ciclos do while
                        if (regCount > 100)
                        {
                            regCount = 0;
                            break; //Sai do while p/ gravar no db
                        }
                    }//While


                    //Quando sai do while verifica se há registros p/ gerar evento de bulk
                    if (OnBulkEvent != null)
                    {
                        Int32 itensCount = vuCountTable.Rows.Count + webResultTable.Rows.Count;
                        if (((itensCount > 0) && (_running)) || (itensCount >= 100))
                        {
                            try
                            {
                                if (OnBulkEvent != null)
                                {
                                    if (vuCountTable.Rows.Count > 0)
                                    {
                                        OnBulkEvent(vuCountTable, "VU");
                                    }

                                    if (webResultTable.Rows.Count > 0)
                                    {
                                        OnBulkEvent(webResultTable, "WebResult");
                                    }
                                }

                                vuCountTable.Rows.Clear();
                                webResultTable.Rows.Clear();
                            }
                            catch (Exception ex)
                            {
                                SendText("ProcQueue", "[" + index + "] Error 4: " + ex.Message + ex.StackTrace, true);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SendText("ProcQueue", "[" + index + "] Error 0: " + ex.Message + ex.StackTrace, true);
                }


                Thread.Sleep(300);
            }
            SendText("ProcQueue", "[" + index + "] Exit: ", true);
            Debug.WriteLine("ProcQueue" + "[" + index + "] Exit: ");
        }