// checkClientHealth returns the health of a client
517494
func (c *AgentCheckCommand) checkClientHealth(clientStats map[string]string, minServers int) int {
	knownServers, err := strconv.Atoi(clientStats["known_servers"])
	if err != nil {
		c.Ui.Output(fmt.Sprintf("unable to get known servers: %v", err))
		return HealthCritical
	}

	heartbeatTTL, err := time.ParseDuration(clientStats["heartbeat_ttl"])
	if err != nil {
		c.Ui.Output(fmt.Sprintf("unable to parse heartbeat TTL: %v", err))
		return HealthCritical
	}

	lastHeartbeat, err := time.ParseDuration(clientStats["last_heartbeat"])
	if err != nil {
		c.Ui.Output(fmt.Sprintf("unable to parse last heartbeat: %v", err))
		return HealthCritical
	}

	if lastHeartbeat > heartbeatTTL {
		c.Ui.Output(fmt.Sprintf("last heartbeat was %q time ago, expected heartbeat ttl: %q", lastHeartbeat, heartbeatTTL))
		return HealthCritical
	}

	if knownServers < minServers {
		c.Ui.Output(fmt.Sprintf("known servers: %v, is less than expected number of servers: %v", knownServers, minServers))
		return HealthCritical
	}

	return HealthPass
}
1217115
func (s *Instance) SetHealthStatus(v string) *Instance {
	s.HealthStatus = &v
	return s
}
98550
func MonitorExternal(clients ...Client) {
	hs := make(HealthState)

	type externalError struct {
		name string
		err  error
	}
	errs := make(chan externalError)
	done := make(chan bool)

	go func() {
		for extErr := range errs {
			hs[extErr.name] = extErr.err
		}
		close(done)
	}()

	var wg sync.WaitGroup
	wg.Add(len(clients))
	for _, client := range clients {
		go func(client Client) {
			if name, err := client.Healthcheck(); err != nil {
				log.ErrorC("unsuccessful healthcheck", err, log.Data{"external_service": name})
				errs <- externalError{name, err}
			}
			wg.Done()
		}(client)
	}

	wg.Wait()
	close(errs)
	<-done

	mutex.Lock()
	healthState = hs
	healthLastChecked = time.Now()
	if len(hs) == 0 {
		healthLastSuccess = healthLastChecked
	}
	mutex.Unlock()
}
858758
func (c *Client) startupHealthcheck(timeout time.Duration) error {
	c.mu.Lock()
	urls := c.urls
	c.mu.Unlock()

	// If we don't get a connection after "timeout", we bail.
	start := time.Now()
	for {
		// Make a copy of the HTTP client provided via options to respect
		// settings like Basic Auth or a user-specified http.Transport.
		cl := new(http.Client)
		*cl = *c.c
		cl.Timeout = timeout

		for _, url := range urls {
			res, err := cl.Head(url)
			if err == nil && res != nil && res.StatusCode >= 200 && res.StatusCode < 300 {
				return nil
			}
		}
		time.Sleep(1 * time.Second)
		if time.Now().Sub(start) > timeout {
			break
		}
	}
	return ErrNoClient
}
1236380
func (v *vserver) healthchecks() vserverChecks {
	vc := vserverChecks{vserverName: v.config.Name}
	if v.enabled {
		vc.checks = v.checks
	}
	return vc
}
267150
func (p *Proxy) Healthcheck() {
	if p.health == nil {
		log.Warning("No healthchecker")
		return
	}

	p.probe.Do(func() error {
		return p.health.Check(p)
	})
}
1350820
func (t *Transport) HealthCheck(ctx context.Context, id uint64) error {
	t.mu.Lock()
	p, ok := t.peers[id]
	t.mu.Unlock()
	if !ok {
		return ErrIsNotFound
	}
	ctx, cancel := t.withContext(ctx)
	defer cancel()
	return p.healthCheck(ctx)
}
200978
func (s *Container) SetHealthStatus(v string) *Container {
	s.HealthStatus = &v
	return s
}
543349
func (n *Node) checkHealth(ctx context.Context, addr string, timeout time.Duration) error {
	conn, err := dial(addr, "tcp", n.opts.TLSCredentials, timeout)
	if err != nil {
		return err
	}

	defer conn.Close()

	if timeout != 0 {
		tctx, cancel := context.WithTimeout(ctx, timeout)
		defer cancel()
		ctx = tctx
	}

	healthClient := api.NewHealthClient(conn)
	resp, err := healthClient.Check(ctx, &api.HealthCheckRequest{Service: "Raft"})
	if err != nil {
		return errors.Wrap(err, "could not connect to prospective new cluster member using its advertised address")
	}
	if resp.Status != api.HealthCheckResponse_SERVING {
		return fmt.Errorf("health check returned status %s", resp.Status.String())
	}

	return nil
}
384786
func (c *Client) VerifyClient() error {
	// If we don't have a client yet, we should try to create one
	if c.client == nil {
		err := c.Connect()
		if err != nil {
			return err
		}
	}

	return nil
}
228163
func (m *MockClient) Healthcheck() (string, error) {
	ret := m.ctrl.Call(m, "Healthcheck")
	ret0, _ := ret[0].(string)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
291303
func (c *ZebedeeClient) Healthcheck() (string, error) {
	resp, err := c.client.Get(c.zebedeeURL + "/healthcheck")
	if err != nil {
		return "zebedee", err
	}

	if resp.StatusCode != http.StatusOK {
		return "zebedee", ErrInvalidZebedeeResponse{resp.StatusCode, "/healthcheck"}
	}

	return "", nil
}
1257576
func (c *AgentCheckCommand) checkServerHealth(info map[string]map[string]string, minPeers int) int {
	raft := info["raft"]
	knownPeers, err := strconv.Atoi(raft["num_peers"])
	if err != nil {
		c.Ui.Output(fmt.Sprintf("unable to get known peers: %v", err))
		return HealthCritical
	}

	if knownPeers < minPeers {
		c.Ui.Output(fmt.Sprintf("known peers: %v, is less than expected number of peers: %v", knownPeers, minPeers))
		return HealthCritical
	}
	return HealthPass
}
87455
func (c *healthcheckClient) Healthcheck() (string, error) {
	resp, err := c.client.Get(context.Background(), c.url)
	if err != nil {
		return c.service, err
	}

	if resp.StatusCode != http.StatusOK {
		return c.service, &errorResponse{c.service, http.StatusOK, resp.StatusCode, c.url}
	}

	return c.service, nil
}
1334794
func (s *CreateEndpointGroupInput) SetHealthCheckPort(v int64) *CreateEndpointGroupInput {
	s.HealthCheckPort = &v
	return s
}
988198
func (m *HealthCheckClient) Healthcheck() (res string, err error) {
	s := m.mongo.Copy()
	defer s.Close()
	res = m.serviceName
	err = s.Ping()
	if err != nil {
		log.ErrorC("Ping mongo", err, nil)
	}

	return
}
273967
func (probe *GrpcHealthProbe) Check() error {
	ctx, cancel := context.WithTimeout(context.Background(), probe.timeout)
	defer cancel()

	connection, err := grpc.DialContext(ctx, probe.server, probe.dialOptions...)
	if err != nil {
		return err
	}
	defer connection.Close()

	client := hv1.NewHealthClient(connection)
	response, err := client.Check(ctx, probe.request)
	if err != nil {
		return err
	}
	if response == nil || (response != nil && response.Status != hv1.HealthCheckResponse_SERVING) {
		return ErrGRPCUnhealthy
	}

	return nil
}