
Cập nhật lần cuối: 23/01/2026 17:00
Tài liệu hướng dẫn cài đặt, cấu hình Alloy để thu thập metrics, logs từ máy chủ Windows.
sc query "alloy" | find "STATE" powershell -ExecutionPolicy Bypass -Command "iwr -UseBasicParsing https://s3hn.smartcloud.vn/agent/alloy/windows/install-windows.ps1 | iex"Chỉnh sửa Alloy để tích hợp giám sát Windows Server
Thay các trường trong cấu hình sau, trong đó:
| Trường | Ý nghĩa | Giá trị mẫu |
| url | Endpoint của dịch vụ APM trên giao diện Console | https://metrics-0qcs3dsvvva.apm.vnptplatform.vn/api/v1/push |
| Authorization | Token của dịch vụ APM trên giao diện Console | a5130b91-ff9b-41ef-8722-9d923a574123 |
| enabled_collectors | Danh sách các đối số muốn bật thu thập metrics | "cpu", "cs", "logical_disk", "net", "os", "service", "system", "time" |
Sửa cấu hình thu thập metrics:
logging {
level = "warn"
format = "logfmt"
}
prometheus.remote_write "metrics_integrations_windows" {
endpoint {
url = "<endpoint dịch vụ APM>"
headers = {
"Authorization" = "<token dịch vụ APM>",
}
}
}
prometheus.exporter.windows "metrics_integrations_windows" {
enabled_collectors = [<danh sách các đối số muốn bật>]
}
discovery.relabel "metrics_integrations_windows" {
targets = prometheus.exporter.windows.metrics_integrations_windows.targets
rule {
target_label = "job"
replacement = "integrations/windows_exporter"
}
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "metrics_integrations_windows" {
targets = discovery.relabel.metrics_integrations_windows.output
forward_to = [prometheus.relabel.metrics_integrations_windows.receiver]
job_name = "integrations/windows_exporter"
scrape_interval = "15s"
scrape_timeout = "10s"
}
prometheus.relabel "metrics_integrations_windows" {
forward_to = [prometheus.remote_write.metrics_integrations_windows.receiver]
rule {
source_labels = ["volume"]
regex = "HarddiskVolume.*"
action = "drop"
}
}
Thay các trường trong cấu hình sau, trong đó:
| Trường | Ý nghĩa | Giá trị mẫu |
| url | Endpoint của dịch vụ APM trên giao diện Console | https://metrics-0qcs3dsvvva.apm.vnptplatform.vn/api/v1/push |
| Authorization | Token của dịch vụ APM trên giao diện Console | a5130b91-ff9b-41ef-8722-9d923a574123 |
Sửa cấu hình thu thập logs:
logging {
level = "warn"
format = "logfmt"
}
loki.write "logs_integrations_windows" {
endpoint {
url ="<endpoint dịch vụ APM>"
headers = {
"Authorization" = "<token dịch vụ APM>",
}
}
}
loki.process "logs_integrations_windows_exporter_application" {
forward_to = [loki.write.logs_integrations_windows.receiver]
stage.json {
expressions = {
level = "levelText",
source = "source",
}
}
stage.labels {
values = {
level = "",
source = "",
}
}
}
loki.relabel "logs_integrations_windows_exporter_application" {
forward_to = [loki.process.logs_integrations_windows_exporter_application.receiver]
rule {
source_labels = ["computer"]
target_label = "agent_hostname"
}
}
loki.source.windowsevent "logs_integrations_windows_exporter_application" {
locale = 1033
eventlog_name = "Application"
bookmark_path = "./bookmarks-app.xml"
poll_interval = "5s"
use_incoming_timestamp = true
forward_to = [loki.relabel.logs_integrations_windows_exporter_application.receiver]
labels = {
instance = constants.hostname,
job = "integrations/windows_exporter",
}
}
loki.process "logs_integrations_windows_exporter_system" {
forward_to = [loki.write.logs_integrations_windows.receiver]
stage.json {
expressions = {
level = "levelText",
source = "source",
}
}
stage.labels {
values = {
level = "",
source = "",
}
}
}
loki.relabel "logs_integrations_windows_exporter_system" {
forward_to = [loki.process.logs_integrations_windows_exporter_system.receiver]
rule {
source_labels = ["computer"]
target_label = "agent_hostname"
}
}
loki.source.windowsevent "logs_integrations_windows_exporter_system" {
locale = 1033
eventlog_name = "System"
bookmark_path = "./bookmarks-sys.xml"
poll_interval = "5s"
use_incoming_timestamp = true
forward_to = [loki.relabel.logs_integrations_windows_exporter_system.receiver]
labels = {
instance = constants.hostname,
job = "integrations/windows_exporter",
}
}
Lưu ý
Khi cần bổ sung một Windows Event Log mới, hãy cấu hình block theo hướng dẫn sau:
loki.relabel "logs_integrations_windows_exporter_<log_name>" {
forward_to = [loki.write.logs_integrations_windows.receiver]
rule {
source_labels = ["computer"]
target_label = "agent_hostname"
}
}
loki.source.windowsevent "logs_integrations_windows_exporter_<log_name>" {
locale = 1033
eventlog_name = "<EventLogName>"
bookmark_path = "./bookmarks-<log_name>.xml"
poll_interval = "5s"
use_incoming_timestamp = true
forward_to = [loki.relabel.logs_integrations_windows_exporter_<log_name>.receiver]
labels = {
instance = constants.hostname
job = "integrations/windows_exporter"
}
}
Thay các trường trong cấu hình sau, trong đó:
| Trường | Ý nghĩa | Giá trị mẫu |
| url | Endpoint của dịch vụ APM trên giao diện Console | https://metrics-0qcs3dsvvva.apm.vnptplatform.vn/api/v1/push |
| Authorization | Token của dịch vụ APM trên giao diện Console | a5130b91-ff9b-41ef-8722-9d923a574123 |
| enabled_collectors | Danh sách các đối số muốn bật thu thập metrics | "cpu", "cs", "logical_disk", "net", "os", "service", "system", "time" |
Sửa cấu hình thu thập metrics, logs:
logging {
level = "warn"
format = "logfmt"
}
prometheus.remote_write "metrics_integrations_windows" {
endpoint {
url = "<endpoint dịch vụ APM>"
headers = {
"Authorization" = "<token dịch vụ APM>",
}
}
}
loki.write "logs_integrations_windows" {
endpoint {
url ="<endpoint dịch vụ APM>"
headers = {
"Authorization" = "<token dịch vụ APM>",
}
}
}
prometheus.exporter.windows "metrics_integrations_windows" {
enabled_collectors = [<danh sách các đối số muốn bật>]
}
discovery.relabel "metrics_integrations_windows" {
targets = prometheus.exporter.windows.metrics_integrations_windows.targets
rule {
target_label = "job"
replacement = "integrations/windows_exporter"
}
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "metrics_integrations_windows" {
targets = discovery.relabel.metrics_integrations_windows.output
forward_to = [prometheus.relabel.metrics_integrations_windows.receiver]
job_name = "integrations/windows_exporter"
scrape_interval = "15s"
scrape_timeout = "10s"
}
prometheus.relabel "metrics_integrations_windows" {
forward_to = [prometheus.remote_write.metrics_integrations_windows.receiver]
rule {
source_labels = ["volume"]
regex = "HarddiskVolume.*"
action = "drop"
}
}
loki.process "logs_integrations_windows_exporter_application" {
forward_to = [loki.write.logs_integrations_windows.receiver]
stage.json {
expressions = {
level = "levelText",
source = "source",
}
}
stage.labels {
values = {
level = "",
source = "",
}
}
}
loki.relabel "logs_integrations_windows_exporter_application" {
forward_to = [loki.process.logs_integrations_windows_exporter_application.receiver]
rule {
source_labels = ["computer"]
target_label = "agent_hostname"
}
}
loki.source.windowsevent "logs_integrations_windows_exporter_application" {
locale = 1033
eventlog_name = "Application"
bookmark_path = "./bookmarks-app.xml"
poll_interval = "0s"
use_incoming_timestamp = true
forward_to = [loki.relabel.logs_integrations_windows_exporter_application.receiver]
labels = {
instance = constants.hostname,
job = "integrations/windows_exporter",
}
}
loki.process "logs_integrations_windows_exporter_system" {
forward_to = [loki.write.logs_integrations_windows.receiver]
stage.json {
expressions = {
level = "levelText",
source = "source",
}
}
stage.labels {
values = {
level = "",
source = "",
}
}
}
loki.relabel "logs_integrations_windows_exporter_system" {
forward_to = [loki.process.logs_integrations_windows_exporter_system.receiver]
rule {
source_labels = ["computer"]
target_label = "agent_hostname"
}
}
loki.source.windowsevent "logs_integrations_windows_exporter_system" {
locale = 1033
eventlog_name = "System"
bookmark_path = "./bookmarks-sys.xml"
poll_interval = "0s"
use_incoming_timestamp = true
forward_to = [loki.relabel.logs_integrations_windows_exporter_system.receiver]
labels = {
instance = constants.hostname,
job = "integrations/windows_exporter",
}
}
Mở Command Prompt chạy với quyền administrator:
sc start alloyKiểm tra hệ thống đã chạy thành công hay chưa:
sc query "alloy" | find "STATE" Trạng thái alloy thành công sẽ nhận được:
Tham khảo hướng dẫn tích hợp dashboard, kiểm tra metric trên giao diện dashboard
Một số dashboard mẫu khi tích hợp thành công: