private void Beat()
        {
            HeartbeatStateData hsb = config.HeartbeatStateData;

            var hb = new Heartbeat(config.AgentID)
            {
                Job      = hsb.Job,
                Index    = hsb.Index,
                JobState = hsb.JobState,
            };

            hb.Vitals = new Vitals
            {
                Load = new[] { 0.00F, 0.00F, 0.00F },
                Cpu  = new CpuStat {
                    Sys = 0.00F, User = 0.00F, Wait = 0.00F
                },
                Mem = new UsageStat {
                    Percent = 0.0F, KiloBytes = 1024
                },
                Swap = new UsageStat {
                    Percent = 0.0F, KiloBytes = 1024
                },
                Disk = new DiskStat
                {
                    Ephemeral  = new Percentage(0),
                    Persistent = new Percentage(0),
                    System     = new Percentage(0),
                },
            };

            hb.Ntp = new NtpStat();

            natsClient.Publish(hb);

            /*
             *       @nats.publish("hm.agent.heartbeat.#{@agent_id}", heartbeat_payload) do
             * raise HeartbeatError, "#{@pending} outstanding heartbeat(s)" if @pending > MAX_OUTSTANDING_HEARTBEATS
             * Heartbeat.new.send_via_mbus do
             * @pending -= 1
             * end
             * @pending += 1
             * rescue => e
             * Config.logger.warn("Error sending heartbeat: #{e}")
             * Config.logger.warn(e.backtrace.join("\n"))
             * raise e if @pending > MAX_OUTSTANDING_HEARTBEATS
             */
        }
Exemplo n.º 2
0
        public void Start()
        {
            if (natsClient.Start())
            {
                discoverMessage = new VcapComponentDiscover(
                    type: Resources.Agent_DEAComponentType,
                    uuid: natsClient.UniqueIdentifier,
                    host: config.MonitoringServiceHostStr,
                    credentials: config.MonitoringCredentials);

                varzProvider.Discover = discoverMessage;

                natsClient.Subscribe(NatsSubscription.VcapComponentDiscover,
                                     (msg, reply) =>
                {
                    discoverMessage.UpdateUptime();
                    natsClient.Publish(reply, discoverMessage);
                });

                natsClient.Publish(new VcapComponentAnnounce(discoverMessage));

                natsClient.Subscribe(NatsSubscription.DeaStatus, ProcessDeaStatus);
                natsClient.Subscribe(NatsSubscription.DropletStatus, ProcessDropletStatus);
                natsClient.Subscribe(NatsSubscription.DeaDiscover, ProcessDeaDiscover);
                natsClient.Subscribe(NatsSubscription.DeaFindDroplet, ProcessDeaFindDroplet);
                natsClient.Subscribe(NatsSubscription.DeaUpdate, ProcessDeaUpdate);
                natsClient.Subscribe(NatsSubscription.DeaStop, ProcessDeaStop);
                natsClient.Subscribe(NatsSubscription.GetDeaInstanceStartFor(natsClient.UniqueIdentifier), ProcessDeaStart);
                natsClient.Subscribe(NatsSubscription.RouterStart, ProcessRouterStart);
                natsClient.Subscribe(NatsSubscription.HealthManagerStart, ProcessHealthManagerStart);
                natsClient.Subscribe(NatsSubscription.DeaLocate, ProcessDeaLocate);

                natsClient.Publish(helloMessage);

                SendAdvertise();

                RecoverExistingDroplets();

                processTask.Start();
                heartbeatTask.Start();
                advertiseTask.Start();
                varzTask.Start();
                monitorAppsTask.Start();
            }
            else
            {
                log.Error(Resources.Agent_ErrorDetectedInNats_Message);
                Error = true;
            }
        }
Exemplo n.º 3
0
 private object DrainForShutdown()
 {
     nats.Publish(String.Format("hm.agent.shutdown.{0}", config.AgentID));
     return(0);
 }