Esempio n. 1
0
        public virtual void PutMetrics(MetricsRecord record)
        {
            writer.Write(record.Timestamp());
            writer.Write(" ");
            writer.Write(record.Context());
            writer.Write(".");
            writer.Write(record.Name());
            string separator = ": ";

            foreach (MetricsTag tag in record.Tags())
            {
                writer.Write(separator);
                separator = ", ";
                writer.Write(tag.Name());
                writer.Write("=");
                writer.Write(tag.Value());
            }
            foreach (AbstractMetric metric in record.Metrics())
            {
                writer.Write(separator);
                separator = ", ";
                writer.Write(metric.Name());
                writer.Write("=");
                writer.Write(metric.Value());
            }
            writer.WriteLine();
        }
Esempio n. 2
0
 public override bool Equals(object obj)
 {
     if (obj is MetricsRecord)
     {
         MetricsRecord other = (MetricsRecord)obj;
         return(Objects.Equal(Timestamp(), other.Timestamp()) && Objects.Equal(Name(), other
                                                                               .Name()) && Objects.Equal(Description(), other.Description()) && Objects.Equal(Tags
                                                                                                                                                                  (), other.Tags()) && Iterables.ElementsEqual(Metrics(), other.Metrics()));
     }
     return(false);
 }
Esempio n. 3
0
        public virtual void PutMetrics(MetricsRecord record)
        {
            StringBuilder lines             = new StringBuilder();
            StringBuilder metricsPathPrefix = new StringBuilder();

            // Configure the hierarchical place to display the graph.
            metricsPathPrefix.Append(metricsPrefix).Append(".").Append(record.Context()).Append
                (".").Append(record.Name());
            foreach (MetricsTag tag in record.Tags())
            {
                if (tag.Value() != null)
                {
                    metricsPathPrefix.Append(".");
                    metricsPathPrefix.Append(tag.Name());
                    metricsPathPrefix.Append("=");
                    metricsPathPrefix.Append(tag.Value());
                }
            }
            // The record timestamp is in milliseconds while Graphite expects an epoc time in seconds.
            long timestamp = record.Timestamp() / 1000L;

            // Collect datapoints.
            foreach (AbstractMetric metric in record.Metrics())
            {
                lines.Append(metricsPathPrefix.ToString() + "." + metric.Name().Replace(' ', '.')
                             ).Append(" ").Append(metric.Value()).Append(" ").Append(timestamp).Append("\n");
            }
            try
            {
                graphite.Write(lines.ToString());
            }
            catch (Exception e)
            {
                Log.Warn("Error sending metrics to Graphite", e);
                try
                {
                    graphite.Close();
                }
                catch (Exception e1)
                {
                    throw new MetricsException("Error closing connection to Graphite", e1);
                }
            }
        }