GraphiteTest.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Net.Http;
  3. using System.Threading;
  4. using Xunit;
  5. namespace OhmGraphite.Test
  6. {
  7. public class GraphiteTest
  8. {
  9. [Fact, Trait("Category", "integration")]
  10. public async void InsertGraphiteTest()
  11. {
  12. var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: false);
  13. await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
  14. // wait for carbon to sync to disk
  15. Thread.Sleep(TimeSpan.FromSeconds(4));
  16. using (var client = new HttpClient())
  17. {
  18. var resp = await client.GetAsync("http://graphite/render?format=csv&target=ohm.my-pc.intelcpu.0.temperature.cpucore.1");
  19. var content = await resp.Content.ReadAsStringAsync();
  20. Assert.Contains("ohm.my-pc.intelcpu.0.temperature.cpucore.1", content);
  21. }
  22. }
  23. [Fact, Trait("Category", "integration")]
  24. public async void InsertTagGraphiteTest()
  25. {
  26. // Let the tag engine time to breathe
  27. Thread.Sleep(TimeSpan.FromSeconds(2));
  28. var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: true);
  29. await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
  30. // wait for carbon to sync to disk
  31. Thread.Sleep(TimeSpan.FromSeconds(4));
  32. using (var client = new HttpClient())
  33. {
  34. var resp = await client.GetAsync("http://graphite/render?format=csv&target=seriesByTag('sensor_type=Temperature','hardware_type=CPU')");
  35. var content = await resp.Content.ReadAsStringAsync();
  36. Assert.Contains("host=my-pc", content);
  37. Assert.Contains("app=ohm", content);
  38. Assert.Contains("sensor_type=Temperature", content);
  39. }
  40. }
  41. }
  42. }