Struct consul_rs::agent::Agent[][src]

pub struct Agent {
    pub c: Option<Client>,
    // some fields omitted
}
Expand description

Agent can be used to query the Agent endpoints

Fields

c: Option<Client>

Implementations

my_self is used to query the agent we are speaking to for information about itself

host is used to retrieve information about the host the agent is running on such as CPU, memory, and disk. Requires a operator:read ACL token.

metrics is used to query the agent we are speaking to for its current internal metric data

reload triggers a configuration reload for the agent we are connected to.

node_name is used to get the node name of the agent

checks returns the locally registered checks

use async_std::task::block_on;
use consul_rs::api;
use consul_rs::agent;
let lock = agent::AGENT.clone();
let agent = block_on(lock.read());
let res = block_on(agent.checks()).unwrap();
println!("{:?}",res);

checks_with_filter returns a subset of the locally registered checks that match the given filter expression

checks_with_filter_opts returns a subset of the locally registered checks that match the given filter expression and QueryOptions.

services returns the locally registered services

use async_std::task::block_on;
use consul_rs;
let lock = consul_rs::agent::AGENT.clone();
let agent = block_on(lock.read());
let res = block_on(agent.services()).unwrap();
println!("{:?}", res);

services_with_filter returns a subset of the locally registered services that match the given filter expression

services_with_filter_opts returns a subset of the locally registered services that match the given filter expression and QueryOptions.

service_register is used to register a new service with the local agent

use async_std::task::block_on;
use consul_rs;
let lock = consul_rs::agent::AGENT.clone();
let agent = block_on(lock.read());
let mut service = consul_rs::agent::AgentServiceRegistration::default();
service.ID = Some("10".to_string());
service.Name = Some("test".to_string());
service.Address = Some("tttt".to_string());
service.Port = Some(8080);
let mut opts = consul_rs::agent::ServiceRegisterOpts::default();
opts.ReplaceExistingChecks = true;
let status_code = block_on(agent.service_register_opts(service, opts)).unwrap();
assert_eq!(surf::StatusCode::Ok, status_code)

service_register_opts is used to register a new service with the local agent and can be passed additional options.

use async_std::task::block_on;
use consul_rs;
let lock = consul_rs::agent::AGENT.clone();
let agent = block_on(lock.read());
let mut service = consul_rs::agent::AgentServiceRegistration::default();
service.ID = Some("10".to_string());
service.Name = Some("test".to_string());
service.Address = Some("tttt".to_string());
service.Port = Some(8080);
let mut opts = consul_rs::agent::ServiceRegisterOpts::default();
opts.ReplaceExistingChecks = true;
let status_code = block_on(agent.service_register_opts(service, opts)).unwrap();
assert_eq!(surf::StatusCode::Ok, status_code)

service_deregister is used to deregister a service with the local agent

use async_std::task::block_on;
use consul_rs::api;
let lock = consul_rs::agent::AGENT.clone();
let agent = block_on(lock.read());
let status_code = block_on(agent.service_deregister("10".to_string())).unwrap();
assert_eq!(surf::StatusCode::Ok, status_code)

service_deregister_opts is used to deregister a service with the local agent with QueryOptions.

use async_std::task::block_on;
use consul_rs;
block_on(consul_rs::api::Client::set_config_address("http://0.0.0.0:8500"));
block_on(consul_rs::agent::Agent::reload_client());
let lock = consul_rs::agent::AGENT.clone();
let agent = block_on(lock.read());
let opts = consul_rs::api::QueryOptions::default();
let status_code = block_on(agent.service_deregister_opts("10".to_string(), opts)).unwrap();
assert_eq!(surf::StatusCode::Ok, status_code)

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more