1
0

GraphiteTest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. using (var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: false))
  13. using (var client = new HttpClient())
  14. {
  15. await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
  16. // wait for carbon to sync to disk
  17. Thread.Sleep(TimeSpan.FromSeconds(4));
  18. {
  19. var resp = await client.GetAsync("http://graphite/render?format=csv&target=ohm.my-pc.intelcpu.0.temperature.cpucore.1");
  20. var content = await resp.Content.ReadAsStringAsync();
  21. Assert.Contains("ohm.my-pc.intelcpu.0.temperature.cpucore.1", content);
  22. }
  23. }
  24. }
  25. [Fact, Trait("Category", "integration")]
  26. public async void InsertTagGraphiteTest()
  27. {
  28. // Let the tag engine time to breathe
  29. Thread.Sleep(TimeSpan.FromSeconds(2));
  30. using (var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: true))
  31. using (var client = new HttpClient())
  32. {
  33. await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
  34. // wait for carbon to sync to disk
  35. Thread.Sleep(TimeSpan.FromSeconds(4));
  36. {
  37. var resp = await client.GetAsync("http://graphite/render?format=csv&target=seriesByTag('sensor_type=Temperature','hardware_type=CPU')");
  38. var content = await resp.Content.ReadAsStringAsync();
  39. Assert.Contains("host=my-pc", content);
  40. Assert.Contains("app=ohm", content);
  41. Assert.Contains("sensor_type=Temperature", content);
  42. }
  43. }
  44. }
  45. }
  46. }