예제 #1
0
 public void Gauge()
 {
     using (var stats = new UdpStatsifyClient("127.0.0.1", Port, "Telemetry.tests."))
     {
         AssertDatagram(Port, "Telemetry.tests.sample_gauge:300.05|g", () => stats.Gauge("sample_gauge", 300.05));
         AssertDatagram(Port, "Telemetry.tests.sample_gauge:1|g", () => stats.Gauge(".sample_gauge.", 1));
     } // using
 }
예제 #2
0
        public override int Execute(MetricCommandOptions options, Arguments args)
        {
            var server = Server;

            if (server.Port == 0)
            {
                server = new Endpoint(server.Address, UdpStatsifyClient.DefaultPort);
            }

            using (var statsifyClient = new UdpStatsifyClient(server.Address, server.Port))
            {
                var value = TryParseFloat(Value);

                switch (options.Type)
                {
                case MetricType.Counter:
                    if (!value.HasValue)
                    {
                        return(1);
                    }

                    statsifyClient.Counter(Name, value.Value);
                    break;

                case MetricType.Timer:
                    if (!value.HasValue)
                    {
                        return(1);
                    }

                    statsifyClient.Time(Name, value.Value);
                    break;

                case MetricType.Gauge:
                    if (!value.HasValue)
                    {
                        return(1);
                    }

                    statsifyClient.Gauge(Name, value.Value);
                    break;

                case MetricType.Set:
                    statsifyClient.Set(Name, Value);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                } // switch
            }     // using

            return(0);
        }