Expose /metrics endpoint on the same Sanic server.

        This may be useful if Sanic is launched from a container
        and you do not want to expose more than one port for some
        reason.
181886
def expose_endpoint(self):
        
        @self._app.route('/metrics', methods=['GET'])
        async def expose_metrics(request):
            return raw(self._get_metrics_data(),
                       content_type=CONTENT_TYPE_LATEST)
15923
def endpoint(params)
      params.each_pair do |param_name, param_value|
        case param_name
          when :summary
            endpoint_summary param_value
          when :description
            endpoint_description param_value
          when :tags
            endpoint_tags *param_value
          when :produces
            endpoint_produces *param_value
          when :path
            endpoint_path param_value
          when :parameters
            param_value.each do |param, args_param|
              endpoint_parameter param, *args_param
            end
          when :responses
            param_value.each do |code, args_response|
              endpoint_response code, *args_response
            end
          else
            raise SwaggerInvalidException.new("Invalid endpoint parameter [#{param_name}]")
        end
      end
    end
901644
def start_http_server(port, addr='', registry=REGISTRY):
    """"""
    CustomMetricsHandler = MetricsHandler.factory(registry)
    httpd = _ThreadingSimpleServer((addr, port), CustomMetricsHandler)
    t = threading.Thread(target=httpd.serve_forever)
    t.daemon = True
    t.start()
729740
def endpoint(url):
    """"""
    if not url:
        click.secho(dtool_config.utils.get_ecs_endpoint(CONFIG_PATH))
    else:
        click.secho(dtool_config.utils.set_ecs_endpoint(CONFIG_PATH, url))
554161
def SetupPrometheusExportsFromConfig():
    """"""
    port = getattr(settings, 'PROMETHEUS_METRICS_EXPORT_PORT', None)
    port_range = getattr(
        settings, 'PROMETHEUS_METRICS_EXPORT_PORT_RANGE', None)
    addr = getattr(settings, 'PROMETHEUS_METRICS_EXPORT_ADDRESS', '')
    if port_range:
        SetupPrometheusEndpointOnPortRange(port_range, addr)
    elif port:
        SetupPrometheusEndpointOnPort(port, addr)
887644
def _common(ret, name, service_name, kwargs):
    '''
    
    '''
    if 'interface' not in kwargs and 'public_url' not in kwargs:
        kwargs['interface'] = name
    service = __salt__['keystoneng.service_get'](name_or_id=service_name)

    if not service:
        ret['comment'] = 'Cannot find service'
        ret['result'] = False
        return (False, ret)

    filters = kwargs.copy()
    filters.pop('enabled', None)
    filters.pop('url', None)
    filters['service_id'] = service.id
    kwargs['service_name_or_id'] = service.id
    endpoints = __salt__['keystoneng.endpoint_search'](filters=filters)

    if len(endpoints) > 1:
        ret['comment'] = "Multiple endpoints match criteria"
        ret['result'] = False
        return ret
    endpoint = endpoints[0] if endpoints else None
    return (True, endpoint)
710223
def is_same_service(self, endpoint):
        # type: (EndpointDescription) -> bool
        
        return (
            self.get_framework_uuid() == endpoint.get_framework_uuid()
            and self.get_service_id() == endpoint.get_service_id()
        )
1098476
static OcAgentMetricsServiceExportRpcHandler create(MetricsServiceStub stub) {
    OcAgentMetricsServiceExportRpcHandler exportRpcHandler =
        new OcAgentMetricsServiceExportRpcHandler();
    ExportResponseObserver exportResponseObserver = new ExportResponseObserver(exportRpcHandler);
    try {
      StreamObserver<ExportMetricsServiceRequest> exportRequestObserver =
          stub.export(exportResponseObserver);
      exportRpcHandler.setExportRequestObserver(exportRequestObserver);
    } catch (StatusRuntimeException e) {
      exportRpcHandler.onComplete(e);
    }
    return exportRpcHandler;
  }
871659
def port_mapping(port)
      case port.to_s
      when /\A(\d+)(?:\/([a-z]+))?\z/
        port = $1.to_i
        {
          "hostPort" => port,
          "containerPort" => port,
          "protocol" => $2 || "tcp"
        }
      when /\A(\d+):(\d+)(?:\/([a-z]+))?\z/
        {
          "hostPort" => $1.to_i,
          "containerPort" => $2.to_i,
          "protocol" => $3 || "tcp"
        }
      else
        raise "Cannot parse port specification: #{port}"
      end
    end
626490
def format_endpoint(schema, addr, port, api_version):
    
    return '{}://{}:{}/{}/'.format(schema, addr, port,
                                   get_api_suffix(api_version))
365172
async def send(self, metric):
        
        message = json.dumps(metric).encode('utf-8')
        await self.loop.create_datagram_endpoint(
            lambda: UDPClientProtocol(message),
            remote_addr=(self.ip, self.port))
356019
def parse_endpoint(inputendpoint_xml)
      hash = Hash.new
      %w{LoadBalancedEndpointSetName LocalPort Name Port Protocol EnableDirectServerReturn LoadBalancerName IdleTimeoutInMinutes}.each do |key|
        hash[key] = xml_content(inputendpoint_xml, key, nil)
      end
      # Protocol could be in there twice... If we have two, pick the second one as the first is for the probe.
      if inputendpoint_xml.css("Protocol").count > 1
        hash["Protocol"] = inputendpoint_xml.css("Protocol")[1].content
      end
      probe = inputendpoint_xml.css("LoadBalancerProbe")
      if probe
        hash["LoadBalancerProbe"] = Hash.new
        %w{Path Port Protocol IntervalInSeconds TimeoutInSeconds}.each do |key|
          hash["LoadBalancerProbe"][key] = xml_content(probe, key, nil)
        end
      end
      hash
    end
867794
@Override
	public void open(MetricConfig config) {
		String portsConfig = config.getString(ARG_PORT, null);

		if (portsConfig != null) {
			Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);

			JMXServer server = new JMXServer();
			while (ports.hasNext()) {
				int port = ports.next();
				try {
					server.start(port);
					LOG.info("Started JMX server on port " + port + ".");
					// only set our field if the server was actually started
					jmxServer = server;
					break;
				} catch (IOException ioe) { //assume port conflict
					LOG.debug("Could not start JMX server on port " + port + ".", ioe);
					try {
						server.stop();
					} catch (Exception e) {
						LOG.debug("Could not stop JMX server.", e);
					}
				}
			}
			if (jmxServer == null) {
				throw new RuntimeException("Could not start JMX server on any configured port. Ports: " + portsConfig);
			}
		}
		LOG.info("Configured JMXReporter with {port:{}}", portsConfig);
	}
94814
function(obj, methodName, methodArgs, probeData) {
        // Start metrics
        that.metricsProbeStart(probeData);
        that.requestProbeStart(probeData);
        // End metrics
        aspect.aroundCallback(
          methodArgs,
          probeData,
          function(target, args, probeData) {
            // Get HTTP request method from options
            var ri = getRequestItems(methodArgs[0]);
            that.metricsProbeEnd(probeData, ri.requestMethod, ri.urlRequested, args[0], ri.headers);
            that.requestProbeEnd(probeData, ri.requestMethod, ri.urlRequested, args[0], ri.headers);
          },
          function(target, args, probeData, ret) {
            // Don't need to do anything after the callback
            return ret;
          }
        );
      }
363578
def endpoint_show(endpoint_id):
    
    client = get_client()

    res = client.get_endpoint(endpoint_id)

    formatted_print(
        res,
        text_format=FORMAT_TEXT_RECORD,
        fields=GCP_FIELDS if res["is_globus_connect"] else STANDARD_FIELDS,
    )
392339
private ServiceRegistration.EndpointHealthCheck endpointHealthCheck(String portName) {
    if (healthCheck() instanceof HttpHealthCheck) {
      final HttpHealthCheck httpHealthCheck = (HttpHealthCheck) healthCheck();
      if (portName.equals(httpHealthCheck.getPort())) {
        return ServiceRegistration.EndpointHealthCheck.newHttpCheck(httpHealthCheck.getPath());
      }
    } else if (healthCheck() instanceof TcpHealthCheck) {
      if (portName.equals(((TcpHealthCheck) healthCheck()).getPort())) {
        return ServiceRegistration.EndpointHealthCheck.newTcpCheck();
      }
    }
    return null;
  }
698194
private void registerEndpointMBean(String name, EndPointInfoImpl ep) {
        endpointMBeans.put(name, registerMBeanAsService(name, ep));
    }