Giám sát ứng dụng đơn lẻ không đủ để có bức tranh toàn diện về hệ thống. Thường xuyên, services chạy trong satellite apps (hoặc supporting apps) có tác động cấp thiết đến vận hành hàng ngày. Database servers là ví dụ nổi tiếng. Backup scripts và background jobs khác cũng làm chậm hệ thống và thường bị bỏ qua.
AppSignal APM cho Node.js, Ruby APM và Elixir APM tự động instrument ứng dụng chính. Nhưng AppSignal không giám sát các satellite processes mặc định. Để mở rộng monitoring khắp nơi và có tất cả data trong một app, bạn có thể cài đặt standalone agent của AppSignal.
Standalone Agent Của AppSignal
Standalone agent dựa trên cùng phần mềm dùng để instrument Ruby, Elixir, hoặc JavaScript applications. Phần mềm này cũng có thể chạy ở standalone mode.
Standalone agent có thể dùng để monitor:
- Infrastructure: machines là phần của hệ thống nhưng không chạy application code.
- Background jobs: như intensive cron jobs hoặc long-running data-processing scripts. Nếu background jobs viết bằng ngôn ngữ supported (Ruby, Elixir, Node.js) bạn dùng standard integration.
- Nhiều ngôn ngữ hơn: programs viết bằng ngôn ngữ khác ngoài những ngôn ngữ supported out of the box.
Ví dụ, với standalone agent, có thể track machine learning model viết bằng Python, instrument backup scripts, monitor Kafka brokers, hoặc collect host metrics trong web farms. Bạn xem tất cả thông tin này trên AppSignal để bổ sung metrics đã có cho main applications.
Cách Hoạt Động
Agent ship dưới dạng deb hoặc rpm package và không có language dependencies. Chạy trên bất kỳ Debian/Ubuntu hoặc Red Hat-based systems. Xem agent documentation cho hướng dẫn cài đặt chi tiết.
Sau khi cài, agent cấu hình trong vài phút và chạy mãi như daemon, im lặng monitoring infrastructure. Hơn nữa, agent bao gồm StatsD server relay bất kỳ custom data bạn log vào AppSignal dashboard.
StatsD Là Gì?
StatsD là standard để collect và aggregate arbitrary data. Nó focus trên logging metric và performance information. Sử dụng lightweight text protocol qua UDP connections có footprint nhỏ trên machine.
Một StatsD message trông như sau:
KEY:VALUE|TYPE
Nơi KEY là arbitrary string, và VALUE là number. Type value định nghĩa cách number được xử lý.
Chúng tôi support ba loại metrics:
- c: counter tăng mỗi lần gọi. Ví dụ,
active_users:1|ccộng 1 vào counteractive_users. - g: gauge lấy numeric value và giữ cho đến khi update. Hữu ích record values thay đổi theo thời gian, như throughput, số active users, hoặc số pending tasks trong queue.
- t: lưu giá trị timing. Loại này lý tưởng track durations. AppSignal tính means, count, và percentiles cho tất cả logged timings.
Các metric types không supported sẽ bị silently ignored.
Gửi Dữ Liệu Đến StatsD
Standalone agent lắng nghe UDP packets trên port 8125. Có thể gửi StatsD-formatted strings từ command line dùng netcat:
echo -n "myscript.myevent.counter:1|c" | nc -4u -w0 localhost 8125
Vì dùng UDP, không phải chờ response.
Socat cũng hoạt động:
echo -n "myscript.myevent.counter:1|c" | socat - udp:localhost:8125
Điều này dễ dàng instrument bất kỳ batch hoặc cron jobs. Ví dụ, các dòng sau dùng gauge log dung lượng backup job generate:
backup_size=$(du -m /backups | cut -f1)
echo -n "backup.data:$backup_size|g" | nc -4u -w0 localhost 8125
Không giới hạn integers. StatsD cũng hoạt động với floating-point numbers:
echo -n "network.latency:0.2|g" | nc -4u -w0 localhost 8125
Sử Dụng Tags
Có thể thêm tags vào metrics. StatsD server support optional tags ở cuối message:
KEY:VALUE|TYPE|#TAGS
Có thể apply nhiều tags trong cùng message và assign values để filter sau:
echo -n "backup.data:$backup_size|g|#backups,env:production" | nc -4u -w0 localhost 8125
Sẽ học cách xem data trong AppSignal ngay sau đây.
Instrumenting Languages
StatsD server compatible với bất kỳ language nào gửi UDP packets. Xem vài ví dụ.
Python phổ biến cho data mining và machine learning. Thêm instrumentation vào Python apps dùng built-in socket library:
import time
# measure time taken for function
start = time.process_time()
train_my_model()
training_time = time.process_time() - start
# send value to statsd
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 8125
MESSAGE = b"model.training.time:" + bytes(str(training_time), 'utf-8') + b"|t"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
Có thể đạt kết quả tương tự trong Java với java.net library:
byte[] buffer = "mybatch.exception.counter:1|c".getBytes();
InetAddress address = InetAddress.getByName("127.0.0.1");
DatagramPacket packet = new DatagramPacket(
buffer, buffer.length, address, 8125 );
DatagramSocket datagramSocket = new DatagramSocket();
datagramSocket.send(packet);
PHP là ví dụ khác của language cực phổ biến. Gửi UDP packets với socket_sendto:
$msg = "mywebsite.active_users:$ACTIVE_USERS|g";
$len = strlen($msg);
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 8125);
socket_close($sock);
StatsD Clients
Cho đến nay, dùng built-in networking capabilities mỗi language. Nhưng còn nhiều hơn. Nhiều languages và products include third-party StatsD clients hoặc addons. Bất kỳ StatsD-compliant client nào nên hoạt động, ít nhất cho supported data types. Tìm list clients tại StatsD project wiki.
Xem Host Data Trong AppSignal
Host Metrics dashboard hiển thị resource utilization của machine:
AppSignal thêm entry cho mỗi machine chạy standalone agent.
Dashboard hiển thị load và CPU averages disk, network, memory, và swap usage:
Tạo Dashboards
AppSignal không tự generate dashboards cho StatsD values bạn gửi—bạn cần tạo custom dashboards.
Đầu tiên, click Add dashboard dưới dashboard menu:
Đặt tên cho dashboard:
Click Add graph hiển thị graph builder:
Đặt tên graph, click Add metric:
Chọn metric bạn quan tâm từ menu.
Tùy chọn, dùng tags để filter:
Tiếp, click Back to overview. Có thể thử khác graph types và value units tìm cái phù hợp data bạn muốn represent.
Timing data trông đẹp hơn với area graphs vì mean và percentiles hiển thị rõ hơn.
Line graphs tốt cho counters và gauges.
Khi hài lòng kết quả, click Create graph.
Lưu ý bạn cũng có thể add dashboard cho bất kỳ automatically instrumented hoặc measured metrics khác nếu bạn set AppSignal làm performance monitoring tool (APM) cho Node.js, Ruby (on Rails) APM hoặc Elixir APM.
Kết Luận
Đã học cách dùng standalone server của AppSignal giám sát machines và satellite code. Với built-in StatsD server, bạn record arbitrary performance data và instrument bất kỳ process nào.
Check các links sau để học thêm về standalone agent:
- StatsD reference.
- How to send custom metrics.
- Creating dashboards in AppSignal.
- Identifying and Resolving a Kafka Issue the Standalone Agent.