소스 검색

graphite: remove squirrely braces from nic guids

Nick Babcock 6 년 전
부모
커밋
02a7814df0
2개의 변경된 파일11개의 추가작업 그리고 1개의 파일을 삭제
  1. 10 0
      OhmGraphite.Test/FormatMetricsTest.cs
  2. 1 1
      OhmGraphite/GraphiteWriter.cs

+ 10 - 0
OhmGraphite.Test/FormatMetricsTest.cs

@@ -18,6 +18,16 @@ namespace OhmGraphite.Test
             Assert.Equal("ohm.MY-PC.my.cpu.identifier.voltage 1.06 979344000", actual);
         }
 
+        [Fact]
+        public void FormatGraphiteWithSpecialCharacters()
+        {
+            var writer = new GraphiteWriter("localhost", 2003, "MY-PC", false);
+            var epoch = new DateTimeOffset(new DateTime(2001, 1, 13), TimeSpan.Zero).ToUnixTimeSeconds();
+            var sensor = new ReportedValue("/nic/{my-guid}/throughput/7", "Bluetooth Network Connection 2", 1.06f, SensorType.Throughput, "cpu", HardwareType.NIC, 7);
+            string actual = writer.FormatGraphiteData(epoch, sensor);
+            Assert.Equal("ohm.MY-PC.nic.my-guid.throughput.bluetoothnetworkconnection2 1.06 979344000", actual);
+        }
+
         [Fact]
         public void FormatCultureInvariant()
         {

+ 1 - 1
OhmGraphite/GraphiteWriter.cs

@@ -81,7 +81,7 @@ namespace OhmGraphite
             // since some names are like "cpucore#2", turn them into
             // separate metrics by replacing "#" with "."
             string identifier = sensor.Identifier.Replace('/', '.').Substring(1);
-            identifier = identifier.Remove(identifier.LastIndexOf('.'));
+            identifier = identifier.Remove(identifier.LastIndexOf('.')).Replace("{", null).Replace("}", null);
             string name = sensor.Sensor.ToLower().Replace(" ", null).Replace('#', '.');
             return $"ohm.{host}.{identifier}.{name}";
         }