// checkHealth tries to contact an aspiring member through its advertised address
// and checks if its raft server is running.
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
}
1217298
func (a *availablePlugin) CheckHealth() {
	go func() {
		a.healthChan <- a.client.Ping()
	}()
	select {
	case err := <-a.healthChan:
		if err == nil {
			if a.failedHealthChecks > 0 {
				// only log on first ok health check
				log.WithFields(log.Fields{
					"_module":     "control-aplugin",
					"block":       "check-health",
					"plugin_name": a,
				}).Debug("health is ok")
			}
			a.failedHealthChecks = 0
		} else {
			a.healthCheckFailed()
		}
	case <-time.After(DefaultHealthCheckTimeout):
		a.healthCheckFailed()
	}
}
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
}
615555
func (s *Server) getHealthchecks() (*Checks, error) {
	engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
	if err != nil {
		return nil, fmt.Errorf("Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var checks Checks
	ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
	if err := engine.Call("SeesawEngine.Healthchecks", ctx, &checks); err != nil {
		return nil, fmt.Errorf("SeesawEngine.Healthchecks failed: %v", err)
	}

	return &checks, nil
}
977061
func (elasticsearch *HealthCheckClient) Healthcheck() (string, error) {

	logData := log.Data{"url": elasticsearch.path}

	URL, err := url.Parse(elasticsearch.path)
	if err != nil {
		log.ErrorC("failed to create url for elasticsearch healthcheck", err, logData)
		return elasticsearch.serviceName, err
	}

	path := URL.String()
	logData["url"] = path

	req, err := http.NewRequest("GET", path, nil)
	if err != nil {
		log.ErrorC("failed to create request for healthcheck call to elasticsearch", err, logData)
		return elasticsearch.serviceName, err
	}

	if elasticsearch.signRequests {
		awsauth.Sign(req)
	}

	resp, err := elasticsearch.cli.Do(req)
	if err != nil {
		log.ErrorC("failed to call elasticsearch", err, logData)
		return elasticsearch.serviceName, err
	}
	defer resp.Body.Close()

	logData["http_code"] = resp.StatusCode
	if resp.StatusCode < http.StatusOK || resp.StatusCode >= 300 {
		log.Error(ErrorUnexpectedStatusCode, logData)
		return elasticsearch.serviceName, ErrorUnexpectedStatusCode
	}

	jsonBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.ErrorC("failed to read response body from call to elastic", err, logData)
		return elasticsearch.serviceName, ErrorUnexpectedStatusCode
	}

	var clusterHealth ClusterHealth
	err = json.Unmarshal(jsonBody, &clusterHealth)
	if err != nil {
		log.Error(ErrorParsingBody, logData)
		return elasticsearch.serviceName, ErrorParsingBody
	}

	logData["cluster_health"] = clusterHealth.Status
	if clusterHealth.Status == unhealthy {
		log.Error(ErrorUnhealthyClusterStatus, logData)
		return elasticsearch.serviceName, ErrorUnhealthyClusterStatus
	}

	return elasticsearch.serviceName, nil
}
9365
func checkHealth(serverURL *url.URL, backend *BackendConfig) error {
	req, err := backend.newRequest(serverURL)
	if err != nil {
		return fmt.Errorf("failed to create HTTP request: %s", err)
	}

	req = backend.addHeadersAndHost(req)

	client := http.Client{
		Timeout:   backend.Options.Timeout,
		Transport: backend.Options.Transport,
	}

	resp, err := client.Do(req)
	if err != nil {
		return fmt.Errorf("HTTP request failed: %s", err)
	}

	defer resp.Body.Close()

	if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusBadRequest {
		return fmt.Errorf("received error status code: %v", resp.StatusCode)
	}

	return nil
}
1215108
func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
	reply *structs.IndexedHealthChecks) error {
	if done, err := h.srv.forward("Health.ChecksInState", args, args, reply); done {
		return err
	}

	filter, err := bexpr.CreateFilter(args.Filter, nil, reply.HealthChecks)
	if err != nil {
		return err
	}

	return h.srv.blockingQuery(
		&args.QueryOptions,
		&reply.QueryMeta,
		func(ws memdb.WatchSet, state *state.Store) error {
			var index uint64
			var checks structs.HealthChecks
			var err error
			if len(args.NodeMetaFilters) > 0 {
				index, checks, err = state.ChecksInStateByNodeMeta(ws, args.State, args.NodeMetaFilters)
			} else {
				index, checks, err = state.ChecksInState(ws, args.State)
			}
			if err != nil {
				return err
			}
			reply.Index, reply.HealthChecks = index, checks
			if err := h.srv.filterACL(args.Token, reply); err != nil {
				return err
			}

			raw, err := filter.Execute(reply.HealthChecks)
			if err != nil {
				return err
			}
			reply.HealthChecks = raw.(structs.HealthChecks)

			return h.srv.sortNodesByDistanceFrom(args.Source, reply.HealthChecks)
		})
}
906834
func (r *Renderer) Healthcheck() (string, error) {
	resp, err := r.client.Get(r.url + "/healthcheck")
	if err != nil {
		return service, err
	}

	if resp.StatusCode != http.StatusOK {
		return service, ErrInvalidRendererResponse{resp.StatusCode}
	}

	return service, nil
}
232759
func (c *Check) AddHealthCheck(check Checker) {
	if nc, ok := check.(NamedChecker); ok {
		c.healthChecks = append(c.healthChecks, Named(nc.CheckName(), nc))
	} else {
		c.healthChecks = append(c.healthChecks, check)
	}
}
175839
func (c *Check) CheckHealth(ctx context.Context) Response {
	response := Response{
		Name:   "Health",
		Status: StatusPass,
		Checks: make(Responses, len(c.healthChecks)),
	}
	override := c.manualOverride.Load().(bool)
	if override {
		if c.manualHealthState.Load().(bool) {
			response.Status = StatusPass
		} else {
			response.Status = StatusFail
		}
		overrideResponse := Response{
			Name:    "manual-override",
			Message: "health manually overridden",
		}
		response.Checks = append(response.Checks, overrideResponse)
	}
	for i, ch := range c.healthChecks {
		resp := ch.Check(ctx)
		if resp.Status != StatusPass && !override {
			response.Status = resp.Status
		}
		response.Checks[i] = resp
	}
	sort.Sort(response.Checks)
	return response
}
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
}
1079619
func (s *ContainerDefinition) SetHealthCheck(v *HealthCheck) *ContainerDefinition {
	s.HealthCheck = v
	return s
}
1082676
func (provider *VersionedDBProvider) HealthCheck(ctx context.Context) error {
	return provider.couchInstance.HealthCheck(ctx)
}
1180464
func (c *healthCheck) Check() (warnings, errors []error) {
	if err := c.f(c.client); err != nil {
		return nil, []error{err}
	}
	return nil, nil
}
172129
func (c *VaultClient) Healthcheck() (string, error) {
	resp, err := c.client.Sys().Health()
	if err != nil {
		return "vault", err
	}

	if !resp.Initialized {
		return "vault", errors.New("vault not initialised")
	}

	return "", nil
}
1295125
func (api *SimpleMonitorAPI) Health(id int64) (*sacloud.SimpleMonitorHealthCheckStatus, error) {
	var (
		method = "GET"
		uri    = fmt.Sprintf("%s/%d/health", api.getResourceURL(), id)
	)
	res := struct {
		SimpleMonitor *sacloud.SimpleMonitorHealthCheckStatus `json:",omitempty"`
	}{}

	err := api.baseAPI.request(method, uri, nil, &res)
	if err != nil {
		return nil, err
	}
	return res.SimpleMonitor, nil
}
200996
func (h *dnsHc) Check(p *Proxy) error {
	err := h.send(p.addr)
	if err != nil {
		HealthcheckFailureCount.WithLabelValues(p.addr).Add(1)
		atomic.AddUint32(&p.fails, 1)
		return err
	}

	atomic.StoreUint32(&p.fails, 0)
	return nil
}