
    Vh                         d dl mZmZmZ eZdZdZd dlm	Z	m
Z
 	 d dlmZmZ dZd Zd	 Zd
 Zedk(  r e        yy# e$ r dZY  w xY w)    )absolute_importdivisionprint_functiona  
module: statsd
short_description: Send metrics to StatsD
version_added: 2.1.0
description:
  - The C(statsd) module sends metrics to StatsD.
  - For more information, see U(https://statsd-metrics.readthedocs.io/en/latest/).
  - Supported metric types are V(counter) and V(gauge). Currently unupported metric types are V(timer), V(set), and V(gaugedelta).
author: "Mark Mercado (@mamercad)"
requirements:
  - statsd
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  state:
    type: str
    description:
      - State of the check, only V(present) makes sense.
    choices: ["present"]
    default: present
  host:
    type: str
    default: localhost
    description:
      - StatsD host (hostname or IP) to send metrics to.
  port:
    type: int
    default: 8125
    description:
      - The port on O(host) which StatsD is listening on.
  protocol:
    type: str
    default: udp
    choices: ["udp", "tcp"]
    description:
      - The transport protocol to send metrics over.
  timeout:
    type: float
    default: 1.0
    description:
      - Sender timeout, only applicable if O(protocol) is V(tcp).
  metric:
    type: str
    required: true
    description:
      - The name of the metric.
  metric_type:
    type: str
    required: true
    choices: ["counter", "gauge"]
    description:
      - The type of metric.
  metric_prefix:
    type: str
    description:
      - The prefix to add to the metric.
    default: ''
  value:
    type: int
    required: true
    description:
      - The value of the metric.
  delta:
    type: bool
    default: false
    description:
      - If the metric is of type V(gauge), change the value by O(delta).
ak  
- name: Increment the metric my_counter by 1
  community.general.statsd:
    host: localhost
    port: 9125
    protocol: tcp
    metric: my_counter
    metric_type: counter
    value: 1

- name: Set the gauge my_gauge to 7
  community.general.statsd:
    host: localhost
    port: 9125
    protocol: tcp
    metric: my_gauge
    metric_type: gauge
    value: 7
)AnsibleModulemissing_required_lib)StatsClientTCPStatsClientTFc                      t        di | S N )r   client_paramss    l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/statsd.pyudp_statsd_clientr   r   s    '''    c                      t        di | S r   )r	   r   s    r   tcp_statsd_clientr   v   s    *M**r   c                  \   t        t        t        dddg      t        dd      t        dd      t        dddd	g      t        d
d      t        dd      t        ddddg      t        dd      t        dd      t        dd      
      d      } t        s| j                  t	        d             | j
                  j                  d      }| j
                  j                  d      }| j
                  j                  d      }| j
                  j                  d      }| j
                  j                  d      }| j
                  j                  d      }| j
                  j                  d      }| j
                  j                  d      }| j
                  j                  d       }	|dk(  rt        |||d!d"      }
n|d	k(  rt        ||||d#      }
|r|d$|n|}|dk(  r|d%|	d&n|}	 |dk(  r
j                  ||       n|dk(  r
j                  |||	'       |d	k(  r
j                          	 | j                  d)|d*|d+t        |      d,d-       y # t        $ r(}| j                  d(t        |      z         Y d }~id }~ww xY w# |d	k(  r
j                          w w xY w).Nstrpresent)typedefaultchoices	localhost)r   r   inti  udptcpfloatg      ?T)r   requiredcountergauge)r   r   r    boolF)
statehostportprotocoltimeoutmetricmetric_typemetric_prefixvaluedelta)argument_specsupports_check_modestatsd)msgr%   r&   r'   r(   r)   r*   r+   r,   r-   i   )r%   r&   prefix
maxudpsizeipv6)r%   r&   r(   r2   r4   /z (delta=))r-   zFailed sending to StatsD %szSent  z -> z
 to StatsD)r1   changed)r   dict
HAS_STATSD	fail_jsonr   paramsgetr   r   incrr!   	Exceptionr   close	exit_json)moduler%   r&   r'   r(   r)   r*   r+   r,   r-   clientmetric_namemetric_display_valueexcs                 r   mainrG   z   sn   E9ykJ5+65$/ueeU^Lgs3UT2%$G@TUE26ED1FE2
 "F  1(;<==V$D==V$D}}  ,Hmm	*G]]x(F--##M2KMM%%o6MMMg&EMMg&E5"4Z]dij	U	"4Q^ejk7D]F3&K?Jg?UeU;[`)#KK&G#LLeL4 uLLN
kSVWkSlmw{|  G:SXEFFG uLLN s*   11I 	J(JJ JJ J+__main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   r   r0   r   r	   r:   ImportErrorr   r   rG   __name__r   r   r   <module>rP      sr    A @HT* M2J
(+4}n zF G  Js   
; AA