Now another table. Its data format is as follows:
{
"_id": ObjectId ("53b224e0a1ae72328a57702c"),
"title": "secj0118e",
"Criteria": "No corresponding error code found",
"Actual": "1",
"Effect": "may cause serious problems",
"Suggestion": "Ask experts for advice",
"Severity": "Normal",
"Status": "Notok",
"Rtype": "Formloginexte",
"Comment": "[8/2/12 17:28:21:231 gmt+08:00] 0000001e formloginexte E secj0118e:authentication Error during Authenticatio N for user rpt ",
"Category": "Logs",
"Time": "0008-02-12 17:28:21"
}
{
"_id": ObjectId ("53b224e0a1ae72328a577052"),
"title": "",
"Criteria": "No corresponding error code found",
"Actual": "1",
"Effect": "may cause serious problems",
"Suggestion": "Ask experts for advice",
"Severity": "Normal",
"Status": "Notok",
"Rtype": "Servlet",
"Comment": "[8/2/12 19:04:41:891 CST] 0000000b servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper Init Uncaught.init.exception.thrown.by.servlet ",
"Category": "Logs",
"Time": "0008-02-12 19:04:41"
}
{
"_id": ObjectId ("53B224E0A1AE72328A576FDC"),
"title": "System resource settings [processes]",
"Criteria": "Unlimited",
"Actual": "Unlimited",
"Effect": "If a limits limit is made to the user resource, it may cause the application to fail or the system performance to degrade." ",
"Suggestion": "Suggest modifying the/etc/security/limits, edit the root related Parameters section is-1." ",
"Severity": "None",
"Status": "OK",
"Rtype": "System parameter setting check",
"Comment": "",
"category": "params"
}
1: Single Condition grouping
(1) Now we are grouping according to title and counting the number of each group
Db.runcommand ({mapreduce: "Check_result",
Map:function Map () {
The key in the emit function is unique and is a grouping condition
Emit
This.title,
{Count:1}
);
},
Reduce:function Reduce (key, values) {
total=0;//defines a variable total, values is an array
for (var i in values) {
Total +=values[i].count
}
return {"Count": total};
},
Finalize:function Finalize (key, reduced) {
return reduced;
},
Out: {inline:1}
});
The results are as follows:
{"_id": "", "value": {"Count": 113.0}}
{"_id": "/tmp set T flag bit", "value": {"Count": 21.0}}
{"_id": "asyn0080w", "value": {"Count": 120.0}}
{"_id": "AppServer JVM heap Maximum", "value": {"Count": 6.0}}
{"_id": "AppServer jvm Heap Min", "value": {"Count": 6.0}}
{"_id": "AppServer JVM standard output log switching period", "value": {"Count": 6.0}}
{"_id": "AppServer JVM standard output log rollback type", "value": {"Count": 6.0}}
{"_id": "AppServer JVM standard error log switching period", "value": {"Count": 6.0}}
{"_id": "AppServer JVM standard error log rollback type", "value": {"Count": 6.0}}
{"_id": "AppServer webcontainer thread pool maximum", "value": {"Count": 6.0}}
{"_id": "AppServer webcontainer thread pool min", "value": {"Count": 6.0}}
{"_id": "AppServer generic JVM parameter", "value": {"Count": 6.0}}
{"_id": "AppServer generic JVM parameter-systemgc", "value": {"Count": 6.0}}
{"_id": "Audit Open", "value": {"Count": 21.0}}
{"_id": "cwpki0041w", "value": {"Count": 65.0}}
{"_id": "cwpmc0017w", "value": {"Count": 7.0}}
{"_id": "cwsaa0037w", "value": {"Count": 13.0}}
{"_id": "Could not invoke a operation on object", "value": {"Count": 21.0}}
{"_id": "dcsv0000w", "value": {"Count": 4.0}}
{"_id": "dcsv1115w", "value": {"Count": 137.0}}
2: Multiple conditional groupings
(1) Now we are grouping according to Title,status,severity and counting the number of each group
Db.runcommand ({mapreduce: "Check_result",
Map:function Map () {
The key in the emit function is unique and is a grouping condition
Emit
{"title": This.title, "status": This.status, "serverity": this.severity}
,
{Count:1}
);
},
Reduce:function Reduce (key, values) {
total=0;//defines a variable total, values is an array
for (var i in values) {
Total +=values[i].count
}
return {"Count": total};
},
Finalize:function Finalize (key, reduced) {
return reduced;
},
Out: {inline:1}
});
The output results are formatted as follows:
{"_id": {"title": "", "status": "Notok"}, "value": {"Count": 113.0}}
{"_id": {"title": "/tmp set T flag bit", "status": "Notok"}, "value": {"Count": 21.0}}
{"_id": {"title": "asyn0080w", "status": "Notok"}, "value": {"Count": 120.0}}
{"_id": {"title": "AppServer JVM heap Maximum", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer jvm Heap Min", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer JVM standard output log switching period", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer JVM standard output log rollback type", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer JVM standard error log switching period", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer JVM standard error log rollback type", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer webcontainer thread pool maximum", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer webcontainer thread pool Minimum", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer generic JVM parameter", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "AppServer generic JVM parameter-systemgc", "status": "Notok"}, "value": {"Count": 6.0}}
{"_id": {"title": "Audit Open", "status": "Notok"}, "value": {"Count": 21.0}}
{"_id": {"title": "CWPKI0041W", "status": "Notok"}, "value": {"Count": 65.0}}
{"_id": {"title": "cwpmc0017w", "status": "Notok"}, "value": {"Count": 7.0}}
{"_id": {"title": "cwsaa0037w", "status": "Notok"}, "value": {"Count": 13.0}}
{"_id": {"title": "Could not invoke a operation on object", "status": "Notok"}, "value": {"Count": 21.0}}
{"_id": {"title": "dcsv0000w", "status": "Notok"}, "value": {"Count": 4.0}}
{"_id": {"title": "dcsv1115w", "status": "Notok"}, "value": {"Count": 137.0}}