Skip to content

Instantly share code, notes, and snippets.

@ilosamart
Last active April 13, 2020 23:32
Show Gist options
  • Select an option

  • Save ilosamart/5dc5903a24802f16d6c163cee2917b59 to your computer and use it in GitHub Desktop.

Select an option

Save ilosamart/5dc5903a24802f16d6c163cee2917b59 to your computer and use it in GitHub Desktop.

Revisions

  1. ilosamart revised this gist Jul 6, 2017. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions django-settings.py
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    '''
    """
    ... some code
    '''
    """
    import socket


    HOSTNAME=socket.gethostname()

    '''
    """
    ... some more code
    '''
    """

    LOGGING = {
    'version': 1,
  2. ilosamart revised this gist Jul 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion django-settings.py
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    'graypy': {
    'level': 'WARNING',
    'class': 'graypy.GELFHandler',
    'host': '172.17.2.244',
    'host': 'XYZ',
    'port': 13201,
    'localname': 'django-blog-test-app@'+HOSTNAME,
    },
  3. ilosamart revised this gist Jul 6, 2017. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions django-settings.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    '''
    ... some code
    '''
    import socket


    HOSTNAME=socket.gethostname()

    '''
    ... some more code
    '''

    LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
    'graypy': {
    'level': 'WARNING',
    'class': 'graypy.GELFHandler',
    'host': '172.17.2.244',
    'port': 13201,
    'localname': 'django-blog-test-app@'+HOSTNAME,
    },
    },
    'loggers': {
    'django': {
    'handlers': ['graypy'],
    'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
    'propagate': True,
    },
    },
    }
  4. ilosamart revised this gist Jul 5, 2017. 1 changed file with 45 additions and 1 deletion.
    46 changes: 45 additions & 1 deletion nginx-graylog-logformat.conf
    Original file line number Diff line number Diff line change
    @@ -1 +1,45 @@
    log_format graylog2_format '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" <msec=$msec|connection=$connection|connection_requests=$connection_requests|millis=$request_time>';
    log_format json_logs '{ '
    '"timestamp": "$time_iso8601",'

    '"vhost": "$http_host",'
    '"server_port": "$server_port",'
    '"server_pid": "$pid",'

    '"source_ip": "$remote_addr",'
    '"client_port": "$remote_port",'
    '"client_user": "$remote_user",'

    '"http_method": "$request_method",'
    '"http_request": "$request",'
    '"http_request_path": "$request_uri",'
    '"http_request_uri_normalized": "$uri",'
    '"http_request_args": "$args",'
    '"http_request_protocol": "$server_protocol",'
    '"http_request_length": "$request_length",'
    '"duration_sec_with_milli": "$request_time",'

    '"ssl_protocol": "$ssl_protocol",'
    '"ssl_session_reused": "$ssl_session_reused",'

    '"http_header_cf_ip": "$http_cf_connecting_ip",'
    '"http_header_cf_country": "$http_cf_ipcountry",'
    '"http_header_cf_ray": "$http_cf_ray",'

    '"request_size_byte": "$bytes_sent",'
    '"http_response_body_size": "$body_bytes_sent",'

    '"upstream_server": "$upstream_addr",'
    '"upstream_connect_time": "$upstream_connect_time",'
    '"upstream_header_time": "$upstream_header_time",'
    '"upstream_response_time": "$upstream_response_time",'
    '"upstream_response_length": "$upstream_response_length",'
    '"upstream_status": "$upstream_status",'

    '"http_content_length": "$content_length",'
    '"http_content_type": "$content_type",'

    '"http_status": "$status",'
    '"http_referer": "$http_referer",'
    '"user_agent": "$http_user_agent"'
    ' }';

  5. ilosamart revised this gist Jul 4, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gunicorn-syslog-enable.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    GRAYLOG_ENABLE="--log-syslog --log-syslog-to udp://XYZ:TCP_PORT"
    GUNICORN_ARGS="-t 300 -D -b 127.0.0.1:8001 -w 9 --log-syslog ${GRAYLOG_ENABLE} ..."
  6. ilosamart revised this gist Jul 4, 2017. 2 changed files with 4 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions httpd-graylog-sendlog.inc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    CustomLog "|nc -u 172.17.2.244 12201" graylog2_access
    ErrorLog logs/intra-hml.mp.rs.gov.br-error.log
    2 changes: 2 additions & 0 deletions nginx-graylog-sendlog.inc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    access_log syslog:server=172.17.2.244:5514,severity=notice json_logs;
    error_log syslog:server=172.17.2.244:12302 warn;
  7. ilosamart created this gist Jul 4, 2017.
    2 changes: 2 additions & 0 deletions httpd-graylog-logformat.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    # Configures graylog format (GELF)
    LogFormat "{ \"version\": \"1.1\", \"host\": \"%V\", \"short_message\": \"%r\", \"timestamp\": %{%s}t, \"level\": 6, \"_user_agent\": \"%{User-Agent}i\", \"_source_ip\": \"%a\", \"_duration_usec\": %D, \"_duration_sec\": %T, \"_request_size_byte\": %O, \"_http_status\": %s, \"_http_request_path\": \"%U\", \"_http_request\": \"%U%q\", \"_http_method\": \"%m\", \"_http_referer\": \"%{Referer}i\" }" graylog2_access
    1 change: 1 addition & 0 deletions nginx-graylog-logformat.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    log_format graylog2_format '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" <msec=$msec|connection=$connection|connection_requests=$connection_requests|millis=$request_time>';
    38 changes: 38 additions & 0 deletions nginx-syslog-json-extractor.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    {
    "extractors": [
    {
    "title": "Nginx fields",
    "extractor_type": "json",
    "converters": [],
    "order": 1,
    "cursor_strategy": "cut",
    "source_field": "json_message",
    "target_field": "",
    "extractor_config": {
    "list_separator": ", ",
    "kv_separator": "=",
    "key_prefix": "",
    "key_separator": "_",
    "replace_key_whitespace": false,
    "key_whitespace_replacement": "_"
    },
    "condition_type": "none",
    "condition_value": ""
    },
    {
    "title": "Nginx to JSON",
    "extractor_type": "regex",
    "converters": [],
    "order": 0,
    "cursor_strategy": "copy",
    "source_field": "message",
    "target_field": "json_message",
    "extractor_config": {
    "regex_value": "^.*nginx: (\\{.*\\})$"
    },
    "condition_type": "string",
    "condition_value": "nginx"
    }
    ],
    "version": "2.2.0-SNAPSHOT"
    }