Sensu를 통해 스위치 트래픽 확보
8982 단어 Sensu
각각 SNMP가 지원되므로 Sensu를 사용하여 모니터링했습니다.
모니터링 스크립트
나는 루비
gem 'snmp'로 스크립트를 썼다.IP 주소를 쉼표로 구분하여 객체 스위치와 SNMP 커뮤니티에서 사용하도록 지정합니다.
여러 개의 스위치를 지정할 수 있는 것은 센스의 설정을 간소화하기 위해서다.
스위치에 따라 스레드를 만들어 다스레드로 처리한다.
MIB
1.3.6.1.2.1.2.2.1.10 이하는 포트별 부팅 후 누적 트래픽입니다.이번에 그것들을 합계하여 초간의 통신 총량을 얻었다.
snmp-traffic-metrics.rb
#!/usr/bin/env ruby
require 'sensu-plugin/metric/cli'
require 'snmp'
class SNMPTrafficMetrics < Sensu::Plugin::Metric::CLI::Graphite
option :hosts,
short: '-h HOSTS',
long: '--hosts HOSTS',
default: 'localhost,127.0.0.1'
option :community,
short: '-c COMMUNITY',
long: '--community COMMUNITY',
default: 'public'
option :sleep,
long: '--sleep SLEEP',
proc: proc {|a| a.to_f },
default: 1
def get_all_traffic(host, community)
manager = SNMP::Manager.new host: host, community: community
i = 1
traffic = 0
loop do
response = manager.get ["1.3.6.1.2.1.2.2.1.10.#{i}"]
begin
response.each_varbind { |vb| traffic += vb.value.to_i }
rescue NoMethodError
break
end
i += 1
end
traffic
end
def run
timestamp = Time.now.to_i
threads = []
config[:hosts].split(',').each do |host|
threads << Thread.new do
net_traffic_before = get_all_traffic(host, config[:community])
sleep config[:sleep]
net_traffic_after = get_all_traffic(host, config[:community])
all_traffic = net_traffic_after - net_traffic_before
output "#{host}.snmp.all.traffic", all_traffic, timestamp
end
end
threads.each do |thread|
thread.join
end
ok
end
end
sensu-server 설정스위치에 센스-client가 움직일 수 없어서 다른 호스트에서 감시합니다.
위에서 말한 바와 같이 여러 개의 스위치를 쉼표로 구분하여 감시할 수 있다.
스크립트는subscription
"snmp"의 호스트에서 실행됩니다.여기, 결과의 메트릭스를 Elasticsearch에 던졌다.
/etc/sensu/conf.d/metrics_snmp.json
{
"checks": {
"snmp-traffic-metrics": {
"type": "metric",
"handlers": [ "elasticsearch_metrics" ],
"command": "/etc/sensu/plugins/snmp-traffic-metrics.rb -h 192.168.1.1,192.168.11.254",
"interval": 60,
"subscribers": [ "snmp" ]
}
}
}
Kibana를 통한 시각화Elasticsearch+Kibana로 가시화 해봤어요.
시험 후에 매우 큰 통신이 있으니, 너는 곧 알게 될 것이다.
Reference
이 문제에 관하여(Sensu를 통해 스위치 트래픽 확보), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hiconyan/items/cd485146b4bced8b9eec텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)