예제 #1
0
 private void SendLine(GraphiteLine line)
 {
   byte[] data = Encoding.ASCII.GetBytes(line.ToString());
   try
   {
     _client.Send(data, data.Length);
     _systemMetrics.LogCount("backends.graphite.lines");
     _systemMetrics.LogCount("backends.graphite.bytes", data.Length);
   }
   catch (SocketException ex)
   {
     _log.Error("Failed to send packet to Graphite: " + ex.SocketErrorCode.ToString());
   }
 }
예제 #2
0
 private void PostMetrics(GraphiteLine[][] lineArrays)
 {
   var lines = new List<GraphiteLine>();
   foreach(var graphiteLineArray in lineArrays)
   {
     foreach (var line in graphiteLineArray)
     {
       lines.Add(line);
     }
   }
   var rawText = String.Join(Environment.NewLine,
     lines.Select(line => line.ToString()).ToArray());
   var bytes = Encoding.UTF8.GetBytes(rawText);
   if (_client.Send(bytes))
   {
     _systemMetrics.LogCount("backends.statsdnet.lines", lines.Count);
     _systemMetrics.LogGauge("backends.statsdnet.bytes", bytes.Length);
   }
 }
예제 #3
0
 public bool Equals(GraphiteLine line)
 {
     return(line.Name == this.Name &&
            line._quantity == this._quantity &&
            line._epoc == this._epoc);
 }
예제 #4
0
 public static GraphiteLine[] CloneMany(GraphiteLine[] line)
 {
     return(line.Select(p => GraphiteLine.Clone(p)).ToArray());
 }
예제 #5
0
 public static GraphiteLine Clone(GraphiteLine line)
 {
     return(new GraphiteLine(line.Name, line._quantity, line._epoc));
 }
예제 #6
0
 public bool Equals(GraphiteLine line)
 {
   return line.Name == this.Name &&
     line._quantity == this._quantity &&
     line._epoc == this._epoc;
 }
예제 #7
0
 public static GraphiteLine[] CloneMany(GraphiteLine[] line)
 {
   return line.Select(p => GraphiteLine.Clone(p)).ToArray();
 }
예제 #8
0
 public static GraphiteLine Clone(GraphiteLine line)
 {
   return new GraphiteLine(line.Name, line._quantity, line._epoc);
 }
예제 #9
0
    private void SendToDB(GraphiteLine[] lines)
    {
      try
      {
        DataRow row;
        DataTable tableData = CreateEmptyTable();
        foreach (var line in lines)
        {
          row = tableData.NewRow();
          row["rowid"] = System.DBNull.Value;
          row["source"] = this._collectorName;
          row["metric"] = line.ToString();
          tableData.Rows.Add(row);
        }
        _log.DebugFormat("Attempting to send {0} lines to tb_Metrics.", tableData.Rows.Count);

        _retryPolicy.ExecuteAction(() =>
          {
            using (var bulk = new SqlBulkCopy(_connectionString))
            {
              bulk.DestinationTableName = "tb_Metrics";
              bulk.WriteToServer(tableData);
            }
            _systemMetrics.LogCount("backends.sqlserver.lines", tableData.Rows.Count);
            _log.DebugFormat("Wrote {0} lines to tb_Metrics.", tableData.Rows.Count);
          });
      }
      catch (Exception ex)
      {
        _log.Error("SqlServerBackend: All retries failed.", ex);
        _systemMetrics.LogCount("backends.sqlserver.droppedData");
      }
    }