Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. # This only works with the following docker logging drivers currently: journald, json-file, and CRI-O log files
  2. global(processInternalMessages="on")
  3. global(parser.permitSlashInProgramName="on")
  4. global(workDirectory="/var/spool/rsyslog") # default location for work (spool) files
  5. # Raise limits within /etc/systemd/journald.conf on the host(s) - ie., RateLimitIntervalSec=30s + RateLimitBurst=1000000
  6. module(load="imjournal" ignorepreviousmessages="on" ratelimit.interval="60" ratelimit.burst="2000000" persiststateinterval="10000" statefile="/var/spool/rsyslog/imjournal.state")
  7. module(load="mmutf8fix")
  8. module(load="mmkubernetes"
  9. tls.cacert="/run/secrets/kubernetes.io/serviceaccount/ca.crt"
  10. tokenfile="/run/secrets/kubernetes.io/serviceaccount/token"
  11. annotation_match=["."])
  12. # Extracts k8s metadata
  13. action(type="mmkubernetes")
  14. # Compose k8s namespace and pod name into an app-name only when they are available
  15. template(name="k8s_app" type="list") {
  16. property(name="!kubernetes!namespace_name")
  17. constant(value="/")
  18. property(name="!kubernetes!pod_name")
  19. }
  20. set $!custom_appname = exec_template("k8s_app");
  21. # Otherwise use the default app-name for journal entries not regarding k8s
  22. template(name="appname" type="list") {
  23. property(name="APP-NAME")
  24. }
  25. if $!custom_appname == "/" then {
  26. set $!custom_appname = exec_template("appname");
  27. }
  28. if $!custom_appname startswith "rsyslogd-" then {
  29. set $!custom_appname = "rsyslogd";
  30. }
  31. # Use the hostname for journal entries not regarding k8s
  32. template(name="hostname" type="list") {
  33. property(name="!_HOSTNAME")
  34. }
  35. set $!custom_hostname = exec_template("hostname");
  36. # When empty it's because message does not come from journald but directly from rsyslogd
  37. if $!custom_hostname == "" then {
  38. set $!custom_hostname = "FROM-RSYSLOGD";
  39. }
  40. # Create structured data containing k8s metadata
  41. template(name="k8s_cid" type="list") {
  42. property(name="!docker!container_id" position.from="1" position.to="12")
  43. }
  44. set $!custom_cid = exec_template("k8s_cid");
  45. template(name="k8s_nid" type="list") {
  46. property(name="!kubernetes!namespace_id" position.from="1" position.to="12")
  47. }
  48. set $!custom_nid = exec_template("k8s_nid");
  49. template(name="k8s_pid" type="list") {
  50. property(name="!kubernetes!pod_id" position.from="1" position.to="12")
  51. }
  52. set $!custom_pid = exec_template("k8s_pid");
  53. template(name="k8s_component" type="list") {
  54. property(name="!kubernetes!labels!component" position.from="1" position.to="32")
  55. }
  56. set $!custom_component = exec_template("k8s_component");
  57. template(name="k8s_crevision" type="list") {
  58. property(name="!kubernetes!labels!controller-revision-hash" position.from="1" position.to="32")
  59. }
  60. set $!custom_crevision = exec_template("k8s_crevision");
  61. set $!custom_ids = "";
  62. if $!custom_cid != "" then {
  63. set $!custom_ids = 'container="' & $!custom_cid & '"';
  64. }
  65. if $!custom_nid != "" then {
  66. set $!custom_ids = $!custom_ids & ' namespace="' & $!custom_nid & '"';
  67. }
  68. if $!custom_pid != "" then {
  69. set $!custom_ids = $!custom_ids & ' pod="' & $!custom_pid & '"';
  70. }
  71. if $!custom_ids != "" then {
  72. set $!custom_ids = "[id " & $!custom_ids & "]";
  73. }
  74. set $!custom_labels = "";
  75. if $!custom_component != "" then {
  76. set $!custom_labels = 'component="' & $!custom_component & '"';
  77. }
  78. if $!custom_crevision != "" then {
  79. set $!custom_labels = $!custom_labels & ' controller-revision-hash="' & $!custom_crevision & '"';
  80. }
  81. if $!custom_labels != "" then {
  82. set $!custom_labels = "[label " & $!custom_labels & "]";
  83. }
  84. template(name="c_sddata" type="list") {
  85. property(name="!custom_ids" compressspace="on")
  86. property(name="!custom_labels" compressspace="on")
  87. }
  88. template(name="sddata" type="list") {
  89. property(name="STRUCTURED-DATA")
  90. }
  91. if $!custom_labels == "" and $!custom_ids == "" then {
  92. set $!custom_sddata = exec_template("sddata");
  93. } else {
  94. set $!custom_sddata = exec_template("c_sddata");
  95. }
  96. # Compose RFC5424 message
  97. template(name="rfc5424" type="list") {
  98. constant(value="<")
  99. property(name="PRI")
  100. constant(value=">1 ")
  101. property(name="TIMESTAMP" dateFormat="rfc3339" date.inUTC="on")
  102. constant(value=" ")
  103. property(name="!custom_hostname" position.from="1" position.to="255" caseConversion="lower")
  104. constant(value=" ")
  105. property(name="!custom_appname" position.from="1" position.to="48" caseConversion="lower")
  106. constant(value=" ")
  107. property(name="PROCID" position.from="1" position.to="128")
  108. constant(value=" ")
  109. property(name="MSGID" position.from="1" position.to="32")
  110. constant(value=" ")
  111. property(name="!custom_sddata")
  112. constant(value=" ")
  113. property(name="msg" droplastlf="on")
  114. constant(value="\n")
  115. }
  116. action(type="mmutf8fix")
  117. action(type="omfwd"
  118. target="127.0.0.1"
  119. port="6514"
  120. protocol="tcp"
  121. tcp_framing="octet-counted"
  122. template="rfc5424"
  123. queue.type="LinkedList"
  124. queue.size="5000000"
  125. queue.filename="forwarding"
  126. queue.maxdiskspace="1g")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement