public async void InsertTagGraphiteTest() { // Let the tag engine time to breathe Thread.Sleep(TimeSpan.FromSeconds(2)); using (var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: true)) using (var client = new HttpClient()) { for (int attempts = 0; ; attempts++) { try { await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values()); var resp = await client.GetAsync("http://graphite/render?format=csv&target=seriesByTag('sensor_type=Temperature','hardware_type=CPU')"); var content = await resp.Content.ReadAsStringAsync(); Assert.Contains("host=my-pc", content); Assert.Contains("app=ohm", content); Assert.Contains("sensor_type=Temperature", content); break; } catch (Exception) { if (attempts >= 10) { throw; } Thread.Sleep(TimeSpan.FromSeconds(1)); } } } }
public async void InsertGraphiteTest() { using (var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: false)) using (var client = new HttpClient()) { for (int attempts = 0; ; attempts++) { try { await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values()); var resp = await client.GetAsync( "http://graphite/render?format=csv&target=ohm.my-pc.intelcpu.0.temperature.cpucore.1"); var content = await resp.Content.ReadAsStringAsync(); Assert.Contains("ohm.my-pc.intelcpu.0.temperature.cpucore.1", content); break; } catch (Exception) { if (attempts >= 10) { throw; } Thread.Sleep(TimeSpan.FromSeconds(1)); } } } }
public async void InsertTagGraphiteTest() { // Let the tag engine time to breathe Thread.Sleep(TimeSpan.FromSeconds(2)); using (var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: true)) using (var client = new HttpClient()) { await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values()); // wait for carbon to sync to disk Thread.Sleep(TimeSpan.FromSeconds(4)); { var resp = await client.GetAsync("http://graphite/render?format=csv&target=seriesByTag('sensor_type=Temperature','hardware_type=CPU')"); var content = await resp.Content.ReadAsStringAsync(); Assert.Contains("host=my-pc", content); Assert.Contains("app=ohm", content); Assert.Contains("sensor_type=Temperature", content); } } }
public void FormatGraphiteTags() { var writer = new GraphiteWriter("localhost", 2003, "MY-PC", true); var epoch = new DateTimeOffset(new DateTime(2001, 1, 13), TimeSpan.Zero).ToUnixTimeSeconds(); var sensor = new ReportedValue("/my/cpu/identifier/1", "voltage", 1.06f, SensorType.Voltage, "cpu", HardwareType.CPU, 1); string actual = writer.FormatGraphiteData(epoch, sensor); Assert.Equal("ohm.MY-PC.my.cpu.identifier.voltage;host=MY-PC;app=ohm;hardware=cpu;hardware_type=CPU;sensor_type=Voltage;sensor_index=1;raw_name=voltage 1.06 979344000", actual); }
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); }
public void FormatGraphiteIdentifier() { 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("/my/cpu/identifier/1", "voltage", 1.06f, SensorType.Voltage, "cpu", HardwareType.CPU, "identifier", 1); string actual = writer.FormatGraphiteData(epoch, sensor); Assert.Equal("ohm.MY-PC.my.cpu.identifier.voltage 1.06 979344000", actual); }
public async void InsertGraphiteTest() { var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: false); await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values()); // wait for carbon to sync to disk Thread.Sleep(TimeSpan.FromSeconds(4)); var client = new HttpClient(); var resp = await client.GetAsync("http://graphite/render?format=csv&target=ohm.my-pc.intelcpu.0.temperature.cpucore.1"); var content = await resp.Content.ReadAsStringAsync(); Assert.Contains("ohm.my-pc.intelcpu.0.temperature.cpucore.1", content); }
public async void InsertTagGraphiteTest() { var testContainersBuilder = new TestcontainersBuilder <TestcontainersContainer>() .WithDockerEndpoint(DockerUtils.DockerEndpoint()) .WithImage("graphiteapp/graphite-statsd") .WithEnvironment("REDIS_TAGDB", "y") .WithPortBinding(2003, assignRandomHostPort: true) .WithPortBinding(80, assignRandomHostPort: true) .WithPortBinding(8080, assignRandomHostPort: true) .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(8080)); await using var container = testContainersBuilder.Build(); await container.StartAsync(); var port = container.GetMappedPublicPort(2003); using var writer = new GraphiteWriter(container.Hostname, port, "my-pc", tags: true); using var client = new HttpClient(); for (int attempts = 0;; attempts++) { try { await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values()); var resp = await client.GetAsync( $"http://{container.Hostname}:{container.GetMappedPublicPort(80)}/render?format=csv&target=seriesByTag('sensor_type=Temperature','hardware_type=CPU')"); var content = await resp.Content.ReadAsStringAsync(); Assert.Contains("host=my-pc", content); Assert.Contains("app=ohm", content); Assert.Contains("sensor_type=Temperature", content); break; } catch (Exception) { if (attempts >= 10) { throw; } Thread.Sleep(TimeSpan.FromSeconds(1)); } } }
public void FormatTagsCultureInvariant() { var writer = new GraphiteWriter("localhost", 2003, "MY-PC", true); CultureInfo original = Thread.CurrentThread.CurrentCulture; try { // de-DE culture will format 1.06 as 1,06 which graphite doesn't like Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE"); var epoch = new DateTimeOffset(new DateTime(2001, 1, 13), TimeSpan.Zero).ToUnixTimeSeconds(); var sensor = new ReportedValue("/my/cpu/identifier/1", "voltage", 1.06f, SensorType.Voltage, "cpu", HardwareType.CPU, 1); string actual = writer.FormatGraphiteData(epoch, sensor); Assert.Contains("1.06", actual); } finally { Thread.CurrentThread.CurrentCulture = original; } }