Skip to content

Commit 96b6146

Browse files
author
Houssem Dellai
committed
configured json log collection
1 parent 5fa7893 commit 96b6146

13 files changed

Lines changed: 189 additions & 29 deletions

.infracost/pricing.gob

174 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Path":"d:\\projects\\azure-monitoring-course\\110_vm_monitoring_ama_vnet_flow_logs","Version":"2.0","Modules":[]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Path":"d:\\projects\\azure-monitoring-course\\100_vm_monitoring_ama","Version":"2.0","Modules":[]}

100_vm_monitoring_ama/.terraform.lock.hcl

Lines changed: 33 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

100_vm_monitoring_ama/dcr-linux.tf

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ resource "azurerm_monitor_data_collection_rule" "dcr_linux" {
44
location = azurerm_resource_group.rg.location
55
kind = "Linux"
66

7+
identity {
8+
type = "SystemAssigned"
9+
}
10+
711
destinations {
812
log_analytics {
913
workspace_resource_id = azurerm_log_analytics_workspace.law.id
@@ -26,6 +30,29 @@ resource "azurerm_monitor_data_collection_rule" "dcr_linux" {
2630
# }
2731
}
2832

33+
data_flow {
34+
streams = ["Custom-Json-MyApplication_CL"]
35+
destinations = ["destination-log"]
36+
output_stream = "Custom-MyApplication_CL"
37+
transform_kql = "source"
38+
# transform_kql = <<EOT
39+
# source
40+
# | project TimeGenerated = now(),
41+
# Computer = "",
42+
# FilePath = "",
43+
# Message = "",
44+
# Level = "",
45+
# SourceLine = "",
46+
# ThreadId = 0,
47+
# RawData = "",
48+
# FixedValue = ""
49+
# EOT
50+
# transform_kql = "source | project TimeGenerated = Timestamp, ThreadId, SourceLine, Level, Message, FixedValue"
51+
# transform_kql = "source | project TimeGenerated = now()" # "source | project TimeGenerated = Time, Computer, Message = AdditionalContext"
52+
# transform_kql = "source | project TimeGenerated = now() | project LogMessage = 'RawData'" # "source | project TimeGenerated = Time, Computer, Message = AdditionalContext"
53+
# transform_kql = "source | project d = split(RawData,",") | project TimeGenerated=todatetime(d[0]), Code=toint(d[1]), Severity=tostring(d[2]), Module=tostring(d[3]), Message=tostring(d[4])"
54+
}
55+
2956
data_flow {
3057
streams = ["Microsoft-Syslog"]
3158
destinations = ["destination-log"]
@@ -45,20 +72,16 @@ resource "azurerm_monitor_data_collection_rule" "dcr_linux" {
4572
}
4673

4774
log_file {
48-
name = "datasource-logfile"
49-
format = "text"
50-
streams = ["Custom-MyTableRawData"]
51-
file_patterns = ["C:\\JavaLogs\\*.log"]
52-
settings {
53-
text {
54-
record_start_timestamp_format = "ISO 8601"
55-
}
56-
}
75+
name = "Custom-Json-MyApplication_CL"
76+
format = "json" # "text"
77+
streams = ["Custom-Json-MyApplication_CL"]
78+
file_patterns = ["/var/log/myapplication.log"]
5779
}
5880

5981
performance_counter {
6082
name = "CustomPerfCounters"
6183
streams = ["Microsoft-Perf"]
84+
sampling_frequency_in_seconds = 30
6285
counter_specifiers = [
6386
"Processor(*)\\% Processor Time",
6487
"Processor(*)\\% Idle Time",
@@ -74,7 +97,42 @@ resource "azurerm_monitor_data_collection_rule" "dcr_linux" {
7497
"System(*)\\Unique Users",
7598
"System(*)\\CPUs"
7699
]
77-
sampling_frequency_in_seconds = 30
100+
}
101+
}
102+
103+
stream_declaration {
104+
stream_name = "Custom-Json-MyApplication_CL"
105+
column {
106+
name = "TimeGenerated"
107+
type = "datetime"
108+
}
109+
column {
110+
name = "Computer"
111+
type = "string"
112+
}
113+
column {
114+
name = "FilePath"
115+
type = "string"
116+
}
117+
column {
118+
name = "Level"
119+
type = "string"
120+
}
121+
column {
122+
name = "LogMessage"
123+
type = "string"
124+
}
125+
column {
126+
name = "MachineName"
127+
type = "string"
128+
}
129+
column {
130+
name = "MachineIP"
131+
type = "string"
132+
}
133+
column {
134+
name = "FixedValue"
135+
type = "string"
78136
}
79137
}
80138
}

100_vm_monitoring_ama/dcr-vm-insights.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ resource "azurerm_monitor_data_collection_rule" "dcr_vm_insights" {
44
location = azurerm_resource_group.rg.location
55
kind = "Linux"
66

7+
identity {
8+
type = "SystemAssigned"
9+
}
10+
711
destinations {
812
log_analytics {
913
workspace_resource_id = azurerm_log_analytics_workspace.law.id

100_vm_monitoring_ama/dcr-windows.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ resource "azurerm_monitor_data_collection_rule" "dcr_windows" {
44
location = azurerm_resource_group.rg.location
55
kind = "Windows"
66

7+
identity {
8+
type = "SystemAssigned"
9+
}
10+
711
destinations {
812
log_analytics {
913
workspace_resource_id = azurerm_log_analytics_workspace.law.id
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
sudo bash -c '
4+
i=0
5+
while true; do
6+
echo "{
7+
\"TimeGenerated\":\"$(date)\",
8+
\"Level\":\"Info\",
9+
\"LogMessage\":\"This is demo log $i\",
10+
\"MachineName\":\"$(hostname)\",
11+
\"MachineIP\":\"$(hostname -i)\"
12+
}" >> /var/log/myapplication.log
13+
i=$((i + 1))
14+
sleep 1
15+
done
16+
'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
resource "azapi_resource" "table" {
3+
type = "Microsoft.OperationalInsights/workspaces/tables@2025-02-01"
4+
parent_id = azurerm_log_analytics_workspace.law.id
5+
name = "MyApplication_CL"
6+
body = {
7+
properties = {
8+
plan = "Analytics"
9+
retentionInDays = 30
10+
schema = {
11+
name = "MyApplication_CL"
12+
columns = [
13+
{
14+
name = "TimeGenerated"
15+
type = "datetime"
16+
},
17+
{
18+
name = "Computer"
19+
type = "string"
20+
},
21+
{
22+
name = "FilePath"
23+
type = "string"
24+
},
25+
{
26+
name = "Level"
27+
type = "string"
28+
},
29+
{
30+
name = "LogMessage"
31+
type = "string"
32+
},
33+
{
34+
name = "MachineName"
35+
type = "string"
36+
},
37+
{
38+
name = "MachineIP"
39+
type = "string"
40+
},
41+
{
42+
name = "FixedValue"
43+
type = "string"
44+
}
45+
]
46+
}
47+
totalRetentionInDays = 30
48+
}
49+
}
50+
}

100_vm_monitoring_ama/log_analytics.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "azurerm_log_analytics_workspace" "law" {
2-
name = "log-analytics"
2+
name = "log-analytics-${var.prefix}"
33
resource_group_name = azurerm_resource_group.rg.name
44
location = azurerm_resource_group.rg.location
55
sku = "PerGB2018" # PerGB2018, Free, PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation

0 commit comments

Comments
 (0)