Exemple #1
0
        public IEnumerable <IMetricDefinition> GetMetricDefinitions()
        {
            byte[] buffer;
            using (var webClient = new WebClient())
            {
                if (credentials != null)
                {
                    webClient.Credentials = credentials;
                }

                buffer = webClient.DownloadData(uri);
            } // using

            Overview overview;

            using (var memoryStream = new MemoryStream(buffer))
                overview = (Overview)jsonSerializer.ReadObject(memoryStream);

            Func <string, Func <double>, MetricDefinition> metricDefinition =
                (s, vp) => new MetricDefinition(MetricNameBuilder.BuildMetricName(name, s), vp, aggregationStrategy);

            yield return(metricDefinition("message_stats.ack", () => overview.MessageStats.Ack));

            yield return(metricDefinition("message_stats.ack_details.rate", () => overview.MessageStats.AckDetails.Rate));

            yield return(metricDefinition("message_stats.deliver", () => overview.MessageStats.Deliver));

            yield return(metricDefinition("message_stats.deliver_details.rate", () => overview.MessageStats.DeliverDetails.Rate));

            yield return(metricDefinition("message_stats.redeliver", () => overview.MessageStats.Redeliver));

            yield return(metricDefinition("message_stats.redeliver_details.rate", () => overview.MessageStats.RedeliverDetails.Rate));

            yield return(metricDefinition("queue_totals.messages", () => overview.QueueTotals.Messages));

            yield return(metricDefinition("queue_totals.messages_details.rate", () => overview.QueueTotals.MessagesDetails.Rate));

            yield return(metricDefinition("queue_totals.messages_ready", () => overview.QueueTotals.MessagesReady));

            yield return(metricDefinition("queue_totals.messages_ready_details.rate", () => overview.QueueTotals.MessagesReadyDetails.Rate));

            yield return(metricDefinition("queue_totals.messages_unacknowledged", () => overview.QueueTotals.MessagesUnacknowledged));

            yield return(metricDefinition("queue_totals.messages_unacknowledged_details.rate", () => overview.QueueTotals.MessagesUnacknowledgedDetails.Rate));

            yield return(metricDefinition("object_totals.consumers", () => overview.ObjectTotals.Consumers));

            yield return(metricDefinition("object_totals.queues", () => overview.ObjectTotals.Queues));

            yield return(metricDefinition("object_totals.exchanges", () => overview.ObjectTotals.Exchanges));

            yield return(metricDefinition("object_totals.connections", () => overview.ObjectTotals.Connections));

            yield return(metricDefinition("object_totals.channels", () => overview.ObjectTotals.Channels));
        }
Exemple #2
0
        public IEnumerable <IMetricDefinition> GetMetricDefinitions()
        {
            using (var tcpClient = new TcpClient())
            {
                tcpClient.Connect(uri.Host, uri.Port);

                using (var networkStream = tcpClient.GetStream())
                {
                    WriteString(networkStream, "stats\n");

                    var stats =
                        ReadStrings(networkStream).
                        TakeWhile(s => !s.Equals("END", StringComparison.InvariantCultureIgnoreCase)).
                        Where(s => s.StartsWith("STAT ")).
                        Select(s => s.SubstringAfter("STAT ")).
                        Select(s => s.Split(' '));

                    foreach (var stat in stats)
                    {
                        long value;
                        if (!long.TryParse(stat[1], out value))
                        {
                            continue;
                        }

                        var metric = stat[0];

                        yield return(new MetricDefinition(
                                         MetricNameBuilder.BuildMetricName(name, metric),
                                         () => value,
                                         aggregationStrategy));
                    } // foreach

                    WriteString(networkStream, "quit\n");
                } // using
            }     // using
        }
 public string BuildMetricName(string @namespace, string name)
 {
     return(MetricNameBuilder.BuildMetricName(@namespace, name));
 }