Beispiel #1
0
        // nothing to do as we are not buffering data
        // Load the configurations for a conf type
        private void LoadGangliaConf(AbstractGangliaSink.GangliaConfType gtype)
        {
            string[] propertyarr = conf.GetStringArray(gtype.ToString());
            if (propertyarr != null && propertyarr.Length > 0)
            {
                foreach (string metricNValue in propertyarr)
                {
                    string[] metricNValueArr = metricNValue.Split(Equal);
                    if (metricNValueArr.Length != 2 || metricNValueArr[0].Length == 0)
                    {
                        Log.Error("Invalid propertylist for " + gtype.ToString());
                    }
                    string      metricName  = metricNValueArr[0].Trim();
                    string      metricValue = metricNValueArr[1].Trim();
                    GangliaConf gconf       = gangliaConfMap[metricName];
                    if (gconf == null)
                    {
                        gconf = new GangliaConf();
                        gangliaConfMap[metricName] = gconf;
                    }
                    switch (gtype)
                    {
                    case AbstractGangliaSink.GangliaConfType.units:
                    {
                        gconf.SetUnits(metricValue);
                        break;
                    }

                    case AbstractGangliaSink.GangliaConfType.dmax:
                    {
                        gconf.SetDmax(System.Convert.ToInt32(metricValue));
                        break;
                    }

                    case AbstractGangliaSink.GangliaConfType.tmax:
                    {
                        gconf.SetTmax(System.Convert.ToInt32(metricValue));
                        break;
                    }

                    case AbstractGangliaSink.GangliaConfType.slope:
                    {
                        gconf.SetSlope(AbstractGangliaSink.GangliaSlope.ValueOf(metricValue));
                        break;
                    }
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>The method sends metrics to Ganglia servers.</summary>
 /// <remarks>
 /// The method sends metrics to Ganglia servers. The method has been taken from
 /// org.apache.hadoop.metrics.ganglia.GangliaContext30 with minimal changes in
 /// order to keep it in sync.
 /// </remarks>
 /// <param name="groupName">The group name of the metric</param>
 /// <param name="name">The metric name</param>
 /// <param name="type">The type of the metric</param>
 /// <param name="value">The value of the metric</param>
 /// <param name="gConf">The GangliaConf for this metric</param>
 /// <param name="gSlope">The slope for this metric</param>
 /// <exception cref="System.IO.IOException"/>
 protected internal virtual void EmitMetric(string groupName, string name, string
                                            type, string value, GangliaConf gConf, AbstractGangliaSink.GangliaSlope gSlope)
 {
     if (name == null)
     {
         Log.Warn("Metric was emitted with no name.");
         return;
     }
     else
     {
         if (value == null)
         {
             Log.Warn("Metric name " + name + " was emitted with a null value.");
             return;
         }
         else
         {
             if (type == null)
             {
                 Log.Warn("Metric name " + name + ", value " + value + " has no type.");
                 return;
             }
         }
     }
     if (Log.IsDebugEnabled())
     {
         Log.Debug("Emitting metric " + name + ", type " + type + ", value " + value + ", slope "
                   + gSlope.ToString() + " from hostname " + GetHostName());
     }
     Xdr_int(0);
     // metric_user_defined
     Xdr_string(type);
     Xdr_string(name);
     Xdr_string(value);
     Xdr_string(gConf.GetUnits());
     Xdr_int((int)(gSlope));
     Xdr_int(gConf.GetTmax());
     Xdr_int(gConf.GetDmax());
     // send the metric to Ganglia hosts
     EmitToGangliaHosts();
 }
Beispiel #3
0
 // Calculate the slope from properties and metric
 private AbstractGangliaSink.GangliaSlope CalculateSlope(GangliaConf gConf, AbstractGangliaSink.GangliaSlope
                                                         slopeFromMetric)
 {
     if (gConf.GetSlope() != null)
     {
         // if slope has been specified in properties, use that
         return(gConf.GetSlope());
     }
     else
     {
         if (slopeFromMetric != null)
         {
             // slope not specified in properties, use derived from Metric
             return(slopeFromMetric);
         }
         else
         {
             return(DefaultSlope);
         }
     }
 }
Beispiel #4
0
 public override void PutMetrics(MetricsRecord record)
 {
     // The method handles both cases whether Ganglia support dense publish
     // of metrics of sparse (only on change) publish of metrics
     try
     {
         string        recordName  = record.Name();
         string        contextName = record.Context();
         StringBuilder sb          = new StringBuilder();
         sb.Append(contextName);
         sb.Append('.');
         sb.Append(recordName);
         AppendPrefix(record, sb);
         string groupName = sb.ToString();
         sb.Append('.');
         int    sbBaseLen = sb.Length;
         string type      = null;
         AbstractGangliaSink.GangliaSlope slopeFromMetric = null;
         AbstractGangliaSink.GangliaSlope calculatedSlope = null;
         MetricsCache.Record cachedMetrics = null;
         ResetBuffer();
         // reset the buffer to the beginning
         if (!IsSupportSparseMetrics())
         {
             // for sending dense metrics, update metrics cache
             // and get the updated data
             cachedMetrics = metricsCache.Update(record);
             if (cachedMetrics != null && cachedMetrics.MetricsEntrySet() != null)
             {
                 foreach (KeyValuePair <string, AbstractMetric> entry in cachedMetrics.MetricsEntrySet
                              ())
                 {
                     AbstractMetric metric = entry.Value;
                     sb.Append(metric.Name());
                     string name = sb.ToString();
                     // visit the metric to identify the Ganglia type and
                     // slope
                     metric.Visit(gangliaMetricVisitor);
                     type            = gangliaMetricVisitor.GetType();
                     slopeFromMetric = gangliaMetricVisitor.GetSlope();
                     GangliaConf gConf = GetGangliaConfForMetric(name);
                     calculatedSlope = CalculateSlope(gConf, slopeFromMetric);
                     // send metric to Ganglia
                     EmitMetric(groupName, name, type, metric.Value().ToString(), gConf, calculatedSlope
                                );
                     // reset the length of the buffer for next iteration
                     sb.Length = sbBaseLen;
                 }
             }
         }
         else
         {
             // we support sparse updates
             ICollection <AbstractMetric> metrics = (ICollection <AbstractMetric>)record.Metrics
                                                        ();
             if (metrics.Count > 0)
             {
                 // we got metrics. so send the latest
                 foreach (AbstractMetric metric in record.Metrics())
                 {
                     sb.Append(metric.Name());
                     string name = sb.ToString();
                     // visit the metric to identify the Ganglia type and
                     // slope
                     metric.Visit(gangliaMetricVisitor);
                     type            = gangliaMetricVisitor.GetType();
                     slopeFromMetric = gangliaMetricVisitor.GetSlope();
                     GangliaConf gConf = GetGangliaConfForMetric(name);
                     calculatedSlope = CalculateSlope(gConf, slopeFromMetric);
                     // send metric to Ganglia
                     EmitMetric(groupName, name, type, metric.Value().ToString(), gConf, calculatedSlope
                                );
                     // reset the length of the buffer for next iteration
                     sb.Length = sbBaseLen;
                 }
             }
         }
     }
     catch (IOException io)
     {
         throw new MetricsException("Failed to putMetrics", io);
     }
 }
Beispiel #5
0
        /// <summary>The method sends metrics to Ganglia servers.</summary>
        /// <remarks>
        /// The method sends metrics to Ganglia servers. The method has been taken from
        /// org.apache.hadoop.metrics.ganglia.GangliaContext31 with minimal changes in
        /// order to keep it in sync.
        /// </remarks>
        /// <param name="groupName">The group name of the metric</param>
        /// <param name="name">The metric name</param>
        /// <param name="type">The type of the metric</param>
        /// <param name="value">The value of the metric</param>
        /// <param name="gConf">The GangliaConf for this metric</param>
        /// <param name="gSlope">The slope for this metric</param>
        /// <exception cref="System.IO.IOException"/>
        protected internal override void EmitMetric(string groupName, string name, string
                                                    type, string value, GangliaConf gConf, AbstractGangliaSink.GangliaSlope gSlope)
        {
            if (name == null)
            {
                Log.Warn("Metric was emitted with no name.");
                return;
            }
            else
            {
                if (value == null)
                {
                    Log.Warn("Metric name " + name + " was emitted with a null value.");
                    return;
                }
                else
                {
                    if (type == null)
                    {
                        Log.Warn("Metric name " + name + ", value " + value + " has no type.");
                        return;
                    }
                }
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Emitting metric " + name + ", type " + type + ", value " + value + ", slope "
                          + gSlope.ToString() + " from hostname " + GetHostName());
            }
            // The following XDR recipe was done through a careful reading of
            // gm_protocol.x in Ganglia 3.1 and carefully examining the output of
            // the gmetric utility with strace.
            // First we send out a metadata message
            Xdr_int(128);
            // metric_id = metadata_msg
            Xdr_string(GetHostName());
            // hostname
            Xdr_string(name);
            // metric name
            Xdr_int(0);
            // spoof = False
            Xdr_string(type);
            // metric type
            Xdr_string(name);
            // metric name
            Xdr_string(gConf.GetUnits());
            // units
            Xdr_int((int)(gSlope));
            // slope
            Xdr_int(gConf.GetTmax());
            // tmax, the maximum time between metrics
            Xdr_int(gConf.GetDmax());
            // dmax, the maximum data value
            Xdr_int(1);

            /*Num of the entries in extra_value field for
             * Ganglia 3.1.x*/
            Xdr_string("GROUP");
            /*Group attribute*/
            Xdr_string(groupName);
            /*Group value*/
            // send the metric to Ganglia hosts
            EmitToGangliaHosts();
            // Now we send out a message with the actual value.
            // Technically, we only need to send out the metadata message once for
            // each metric, but I don't want to have to record which metrics we did and
            // did not send.
            Xdr_int(133);
            // we are sending a string value
            Xdr_string(GetHostName());
            // hostName
            Xdr_string(name);
            // metric name
            Xdr_int(0);
            // spoof = False
            Xdr_string("%s");
            // format field
            Xdr_string(value);
            // metric value
            // send the metric to Ganglia hosts
            EmitToGangliaHosts();
        }
Beispiel #6
0
        /// <summary>Lookup GangliaConf from cache.</summary>
        /// <remarks>Lookup GangliaConf from cache. If not found, return default values</remarks>
        /// <param name="metricName"/>
        /// <returns>looked up GangliaConf</returns>
        protected internal virtual GangliaConf GetGangliaConfForMetric(string metricName)
        {
            GangliaConf gconf = gangliaConfMap[metricName];

            return(gconf != null ? gconf : DefaultGangliaConf);
        }