public void Should_call_graphite_using_TCP()
 {
     var result = new Result("name", new DateTime(2012, 11, 10, 9, 8, 7), "path");
     result.SetValue(1);
     var graphiteClient = new GraphiteTcpClient("metrics.london.ttldev.local", 2003);
     graphiteClient.Send(result);
 }
Esempio n. 2
0
 public Graphite(ApplicationConfiguration config)
 {
     using (Profiler.Step("Graphite Init"))
     {
         _config = config;
         _client = new GraphiteTcpClient("192.168.10.34", 2003);
     }
 }
        public void Should_create_native_graphiteudp_client()
        {
            var client = new GraphiteTcpClient { Hostname = "hostname", Port = 8125, ClientName = "GraphiteUdpClient" };
            var o = clientFactory.Create(client);

            Assert.That(o, Is.Not.Null);
            Assert.That(o, Is.TypeOf<GraphiteUdpClient>());
        }
Esempio n. 4
0
        static int Main(string[] args)
        {
            string dkronUrl       = null;
            string graphiteHost   = null;
            string graphitePrefix = null;
            int    graphitePort   = 2003;
            bool   showHelp       = false;

            var options = new OptionSet()
                          .Add("url=", "Dkron URL", d => dkronUrl = d)
                          .Add("host=", "Graphite hostname", h => graphiteHost = h)
                          .Add("port:", "Graphite port, default to 2003", (int p) => graphitePort = p)
                          .Add("prefix=", "Graphite key prefix", k => graphitePrefix = k)
                          .Add("h|?|help", "Display help", v => showHelp             = v != null);

            options.Parse(args);

            if (showHelp ||
                String.IsNullOrEmpty(dkronUrl) ||
                String.IsNullOrEmpty(graphiteHost) ||
                String.IsNullOrEmpty(graphitePrefix))
            {
                DisplayHelp(options);
                return(0);
            }

            Console.WriteLine("Collecting metrics from dkron...");

            var dkron       = new RestClient(dkronUrl);
            var jobsRequest = new RestRequest("v1/jobs", Method.GET);
            var jobs        = dkron.Execute <List <DkronJob> >(jobsRequest).Data;

            foreach (var job in jobs)
            {
                var executionsRequest = new RestRequest($"v1/jobs/{job.Name}/executions", Method.GET);
                job.LastExecution =
                    dkron.Execute <List <DkronExecution> >(executionsRequest).Data.LastOrDefault(x => x.Success);
            }

            Console.WriteLine("Feeding metrics into graphite...");

            using (var graphite = new GraphiteTcpClient(graphiteHost, graphitePort, graphitePrefix))
            {
                foreach (var job in jobs)
                {
                    graphite.Send($"{job.Name}.state", job.CurrentState);
                    graphite.Send($"{job.Name}.success_count", job.SuccessCount);
                    graphite.Send($"{job.Name}.error_count", job.ErrorCount);
                    graphite.Send($"{job.Name}.last_duration", job.LastDuration);
                }
            }

            Console.WriteLine("Done!");

            return(0);
        }
 public void Should_run_task_sending_one_result_not_fail_on_exception()
 {
     var result = MockRepository.GenerateMock<IResult>();
     var resultList = new List<IResult> { result };
     var param = new WmiClient();
     var client = new GraphiteTcpClient();
     this.dataClientFactory.Expect(x => x.Create(param)).Return(this.sqlClient);
     this.sqlClient.Expect(x => x.Get()).Return(resultList);
     statsClient.Expect(x => x.Send(resultList)).Throw(new ApplicationException());
     this.graphiteClientFactory.Expect(x => x.Create(client)).Return(this.statsClient);
     IRunTask runTask = new RunableRunTask(param, this.dataClientFactory, this.graphiteClientFactory, this.log, client);
     //Test
     runTask.Process();
     //Assert
     this.sqlClient.VerifyAllExpectations();
     this.dataClientFactory.VerifyAllExpectations();
     this.graphiteClientFactory.VerifyAllExpectations();
     statsClient.VerifyAllExpectations();
 }
 private void AddTwoClientsToConfig()
 {
     var c1 = new GraphiteTcpClient { ClientName = "ClientName" };
     this.config.Clients.Add(c1);
     this.config.Clients.Add(new GraphiteUdpClient());
 }
 public void Should_validate_job_if_client_exist()
 {
     var name = "Name";
     var clientName = "SomeClient";
     var c = new GraphiteTcpClient { ClientName = clientName };
     this.config.Clients.Add(c);
     this.config.Jobs.Add(new WmiClient { ClientName = clientName, Name = name });
     //Test
     this.config.Validate();
 }
        public void Should_generate_test_config_file()
        {
            try
            {
                var log = LogManager.GetLogger("log");
                var encryption = new Encryption();
                var simpleCs = encryption.Encrypt("some Cs");

                log4net.Config.XmlConfigurator.Configure();

                var job1 = new WmiClient { ClientName = "GraphiteTcpClient", Name = "GetNumberOfTransactionsASecond", Hostname = simpleCs, Sql = "some sql" };
                var job2 = new WmiClient { ClientName = "GraphiteUdpClient", Name = "GetNumberOfDeliveryies", Hostname = simpleCs, Sql = "some sql1" };
                var client1 = new GraphiteTcpClient { ClientName = "GraphiteTcpClient", Port = 2003, Hostname = "metrics.london.ttldev.local" };
                var client2 = new GraphiteUdpClient { ClientName = "GraphiteUdpClient", Port = 2003, Hostname = "metrics.london.ttldev.local" };

                var config = new SqlToGraphiteConfig(new AssemblyResolver(new DirectoryImpl(), log), log);
                config.Jobs.Add(job1);
                config.Jobs.Add(job2);

                var host1 = new Host { Name = "TTL001121" };
                var host2 = new Host { Name = "Server1" };
                var role1 = new Role { Name = "ProductionTests" };
                var role2 = new Role { Name = "default" };
                var role3 = new Role { Name = "SqlTests" };

                host1.Roles.Add(role1);
                host1.Roles.Add(role2);
                host2.Roles.Add(role2);
                host2.Roles.Add(role3);
                config.Hosts.Add(host1);
                config.Hosts.Add(host2);

                var template = new Template();
                var wi = new WorkItems { RoleName = role1.Name, TaskSet = new List<TaskSet>() };
                var taskSet = new TaskSet { Frequency = 1000 };
                taskSet.Tasks.Add(new Task { JobName = job1.Name });
                wi.TaskSet.Add(taskSet);
                template.WorkItems.Add(wi);

                var wi1 = new WorkItems { RoleName = role2.Name, TaskSet = new List<TaskSet>() };
                var taskSet1 = new TaskSet { Frequency = 2000 };
                taskSet1.Tasks.Add(new Task { JobName = job2.Name });
                wi1.TaskSet.Add(taskSet1);
                template.WorkItems.Add(wi1);

                var wi2 = new WorkItems { RoleName = role3.Name, TaskSet = new List<TaskSet>() };
                var taskSet2 = new TaskSet { Frequency = 3000 };
                wi2.TaskSet.Add(taskSet2);
                template.WorkItems.Add(wi2);

                config.Templates.Add(template);
                config.Clients = new ListOfUniqueType<Client> { client1, client2 };
                //var genericSerializer = new GenericSerializer(Global.GetNameSpace());
                //string xml = genericSerializer.Serialize(config);
                //Console.WriteLine(xml);
                //var sqlToGraphiteConfig = genericSerializer.Deserialize<SqlToGraphiteConfig>(xml);
                //foreach (var job in sqlToGraphiteConfig.Jobs)
                //{
                    //Console.WriteLine(job.Type);
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
 public void Should_run_task_sending_two_results()
 {
     var job = new WmiClient();
     var client = new GraphiteTcpClient();
     var result1 = MockRepository.GenerateMock<IResult>();
     var result2 = MockRepository.GenerateMock<IResult>();
     var resultList = new List<IResult> { result1, result2 };
     this.dataClientFactory.Expect(x => x.Create(job)).Return(this.sqlClient);
     this.graphiteClientFactory.Expect(x => x.Create(client)).Return(this.statsClient);
     this.sqlClient.Expect(x => x.Get()).Return(resultList);
     statsClient.Expect(x => x.Send(resultList)).Repeat.Once();
     IRunTask runTask = new RunableRunTask(job, this.dataClientFactory, this.graphiteClientFactory, this.log, client);
     //Test
     runTask.Process();
     //Assert
     this.sqlClient.VerifyAllExpectations();
     this.dataClientFactory.VerifyAllExpectations();
     this.graphiteClientFactory.VerifyAllExpectations();
     statsClient.VerifyAllExpectations();
 }
        public void Should_validate_job_if_client_exist()
        {
            var clientName = "cName";
            var c = new GraphiteTcpClient();
            c.ClientName = clientName;

            var jobName = "jobName";
            var job = new WmiClient();
            job.Name = jobName;
            job.ClientName = clientName;

            var wi = CreateWorkItems(jobName, this.rolename1, 100);
            var t = new Template();
            t.WorkItems.Add(wi);
            this.config.Templates.Add(t);
            this.config.Jobs.Add(job);
            //var job = new SqlServer { Name = this.rolename1 };
            //job.ClientName = clientName;
            var h = new Host { Name = this.hostname1 };
            var r = new Role { Name = this.rolename1 };
            h.Roles.Add(r);
            this.config.Clients.Add(c);
            this.config.Hosts.Add(h);
            //config.Jobs.Add(job);
            //Test
            this.config.Validate();
        }
 public void Should_throw_exception_if_unknown_type()
 {
     var client = new GraphiteTcpClient { Hostname = "localhost", Port = 8125, ClientName = "unknown" };
     var ex = Assert.Throws<UnknownGraphiteClientTypeException>(() => clientFactory.Create(client));
     Assert.That(ex.Message, Is.EqualTo("Unknown Graphite Client Type: unknown"));
 }