Download PDF
Download page JSON ログの詳細設定.
JSON ログの詳細設定
ログコレクタは、アプリケーションから JSON ログを収集して、 Cisco Cloud Observabilityに送信して、分析とトラブルシューティングに使用できます。
次の 2 つのメッセージのように、すべての JSON ログメッセージは独自の行にあります。
{"error":"dial tcp 172.21.0.2:5432: getsockopt: connection refused","level":"error","msg":"Could not open database connection","time":"2022-03-25T14:57:15Z"}
{"name":"Peter","age":30,"city":"New York","score":50.05,"grade":null,"birth":"1986-12-14","sale":true}
JSON は自己記述形式であり、ログコレクタは形式固有の解析命令を必要とせずに収集できます。ただし、一部のフィールド名のフラット化、一部のフィールドの削除、または特定の数のフィールドまたは深さまでのみの解析など、JSON ログで追加の解析を行うようにログコレクタを構成できます。このページでは、次の高度な構成オプションについて説明します。
高度な構成オプションの概要
次の表では、JSON ログを解析するための高度な構成オプションについて説明します。レガシーパラメータの詳細については、ログコレクタ設定:高度な YAML レイアウトを参照してください。新しい簡易パラメータの詳細については、「AppDynamics Log Collector Settings」を参照してください。
サンプル構成 1:フィールド名をフラット化する
JSON ログメッセージ
{
"transactionId": "TXN001",
"creditDetails": {
"bankDetails": {
"accountNbr": "SB001002003",
"ifscCode": "SB00007777",
"balance": 25000,
"currency": "INR"
}
},
"debitDetails": {
"bankDetails": {
"accountNbr": "CB001002003",
"ifscCode": "CB00008888",
"balance": 30000,
"currency": "INR"
}
},
"transactionDetails": {
"amount": "10000.00",
"currency": "INR",
"timestamp": "2022-02-16 08:10:32",
"actors": [
"ID001",
"ID0034",
"ID0056",
"ID009"
]
}
}
Configuration
この構成では、属性フィールド名がピリオド(.
)で連結されて、JSON 値を「ネスト解除」またはフラット化します。
- condition:
...
messageParser:
json:
enabled: true
...
flattenSep: "."
config:
- type: container
...
processors:
...
- add_fields:
target: _message_parser
fields:
type: json
flatten_sep: "."
出力
creditDetails.bankDetails.accountNbr=SB001002003
creditDetails.bankDetails.ifscCode=SB00007777
サンプル構成 2:特定のフィールドを削除する
JSON ログメッセージ
{"firstname":"Tom","lastname":"Cruise","occupation":"Actor"}
Configuration
この構成では、フィールド firstname
とフィールド lastname
は無視され、残りのフィールドは取り込まれます。
- condition:
...
messageParser:
json:
enabled: true
...
fieldsToIgnore: ["firstname", "lastname"]
config:
- type: container
...
processors:
...
- add_fields:
target: _message_parser
fields:
type: json
fields_to_ignore: firstname,lastname
fields_to_ignore_sep: ,
出力
"occupation":"Actor"
サンプル構成 3:正規表現に一致するフィールドを削除する
JSON ログメッセージ
{
"institutionname": {
"type": "string",
"description": "institution name",
"label": "name",
"input-type": "text",
"pattern": "^[A-Za-z0-9s]+$"
},
"bio": {
"type": "string",
"label": "bio",
"input-type": "text",
"pattern": "^[A-Za-z0-9s]+$",
"help-box": "tell us about yourself"
}
}
Configuration
この構成では、fields_to_ignore_regex
の正規表現に一致するすべてのフィールド名は、JSON ログ全体に対して解析されません。
- condition:
...
messageParser:
json:
enabled: true
...
fieldsToIgnoreRegex: "*.type"
config:
- type: container
...
processors:
...
- add_fields:
target: _message_parser
fields:
type: json
fields_to_ignore_regex: .*type
出力
institutionname.description=institution name
institutionname.label=text
institutionname.pattern=^[A-Za-z0-9s]+$
bio.label=bio
bio.pattern=^[A-Za-z0-9s]+$
bio.help-box=tell us about yourself
サンプル構成 4:最初の N フィールドのみを取り込む
JSON ログメッセージ
{
"rewardProgramIdentificationCode": "A34324",
"amount": "124.01",
"localTransactionDateTime": "2020-05-21T09:00:00",
"cpsAuthorizationCharacteristicsIndicator": "Y",
"digitalWalletProviderId": "VCIND",
"addValueTaxReturn": "10.00",
"taxAmountConsumption": "10.00",
"nationalNetReimbursementFeeBaseAmount": "20.00",
"addValueTaxAmount": "10.00",
"nationalNetMiscAmount": "10.00",
"countryCodeNationalService": "170",
"nationalChargebackReason": "11",
"emvTransactionIndicator": "1",
"nationalNetMiscAmountType": "A",
"costTransactionIndicator": "0",
"nationalReimbursementFee": "20.00",
"cardAcceptor": {
"address": {
"country": "USA",
"zipCode": "94404",
"county": "San Mateo",
"state": "CA"
},
"idCode": "ABCD1234ABCD123",
"name": "Visa Inc.",
"terminalId": "ABCD1234"
},
"transactionIdentifier": "381228649430056",
"acquirerCountryCode": "840",
"acquiringBin": "408999",
"senderCurrencyCode": "USD",
"retrievalReferenceNumber": "433122895499",
"transactionTypeCode": 22,
"messageReasonCode": 2150,
"systemsTraceAuditNumber": "895499",
"businessApplicationId": "AA",
"senderPrimaryAccountNumber": "4895070000003551",
"settlementServiceIndicator": "9",
"cardProductCode": "15",
"merchantCategoryCode": "6012",
"senderCardExpiryDate": "2021-10",
"dynamicCurrencyConversionIndicator": "Y"
}
Configuration
この構成では、5 つのフィールドのみが解析され、残りのフィールドは解析されません(削除されます)。
- condition:
...
messageParser:
json:
enabled: true
...
maxNumOfFields: 5
config:
- type: container
...
processors:
...
- add_fields:
target: _message_parser
fields:
type: json
max_num_of_fields: 5
出力
rewardProgramIdentificationCode=A34324
amount=124.01
localTransactionDateTime=2022-03-21T09:00:00
cpsAuthorizationCharacteristicsIndicator=Y
digitalWalletProviderId=VCIND
サンプル構成 5:特定の深さまでのみ解析する
JSON ログメッセージ
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": [
"GML",
"XML"
]
},
"GlossSee": "markup",
"GlossArray": [
{
"a": 1
},
{
"a": 2
}
]
}
}
}
}
}
Configuration
この構成では、ネストされた 2 つのオブジェクトの最大深度のみが考慮され、解析されます。
- condition:
...
messageParser:
json:
enabled: true
...
maxDepth: 2
config:
- type: container
...
processors:
...
- add_fields:
target: _message_parser
fields:
type: json
max_depth: 2
出力
glossary.GlossDiv.title=S
glossary.GlossDiv.GlossList={"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup","GlossArray":[{"a":1},{"a":2}]}}
サンプル構成 6:タイムスタンプに特定のフィールドを使用する
JSON ログメッセージ
{
"@timestamp": "2022-03-24T14:51:07.180Z",
"log.level": "TRACE",
"message": "[3302][indices:monitor/stats[n]] received response from [{elastic-cloud-57c5b9fd8d-8lj5q}{J9-xWfXPS-Su2XBRNaDhfw}{gu3jF8xLQniKmRq1vBRdWg}{10.114.51.135}{10.114.51.135:9300}{cdfhilmrstw}{ml.max_jvm_size=3787456512, xpack.installed=true, ml.machine_memory=7569117184}]",
"ecs.version": "1.2.0",
"service.name": "ES_ECS",
"event.dataset": "elasticsearch.server",
"process.thread.name": "elasticsearch[elastic-cloud-57c5b9fd8d-8lj5q][management][T#1]",
"log.logger": "org.elasticsearch.transport.TransportService.tracer",
"elasticsearch.cluster.uuid": "aWAj25TgRGifTQSGVyviIQ",
"elasticsearch.node.id": "J9-xWfXPS-Su2XBRNaDhfw",
"elasticsearch.node.name": "elastic-cloud-57c5b9fd8d-8lj5q",
"elasticsearch.cluster.name": "docker-cluster"
}
Configuration
この構成では、タイムスタンプは、解析した後の生のメッセージから抽出され、OpenTelemetry™ イベントの取り込み時間の代わりに使用されます。
- condition:
...
messageParser:
json:
enabled: true
timestampField: "@timestamp"
timestampPattern: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
config:
- type: container
...
processors:
...
- add_fields:
target: _message_parser
fields:
type: json
timestamp_field: @timestamp
timestamp_pattern: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
OpenTelemetry™ と Kubernetes®(該当する場合)は、The Linux Foundation® の商標です。