deps/libstatsd/src/statsd.c
static int sendToServer(Statsd* stats, const char* bucket, StatsType type, int64_t delta, double sampleRate){
   //See if we randomly fall under the sample rate
   if (sampleRate > 0 && sampleRate < 1 && (double)((double)stats->random() / RAND_MAX) >= sampleRate){
      return STATSD_SUCCESS;
   }
 
   char data[256];
   ssize_t dataLength = 0;
  
   //If the user has not specified a bucket, we will use the defualt
   //bucket instead.
   if (!bucket){
      bucket = stats->bucket;
   }
   
   dataLength = buildStatString(data, sizeof(data), stats->nameSpace, bucket, type, delta, sampleRate);
   if (dataLength < 0) {
      return -1;
   }

   //Send the packet
   int sent = sendto(stats->socketFd, data, dataLength, 0, (const struct sockaddr*)&stats->destination, sizeof(struct sockaddr_in));

   if (sent == -1) {
      return STATSD_UDP_SEND;
   }

   return STATSD_SUCCESS;
}
/**
   This is a helper function that will do the dirty work of sending
   the stats to the statsd server. 

   @param[in] stats - The stats client object
   @param[in] bucket - The optional bucket name, if this is null then
      the defualt bucket name is used from the stats object.
   @param[in] type - The type of stat being sent
   @param[in] delta - The value to send
   @param[in] sampleRate - The sample rate of this stat. If the value is
      less then or equal to 0, or greater then or equal to 1, it is ignored.

   @return STATSD_SUCCESS on success, STATSD_BAD_STATS_TYPE if the type is 
      not recognized. STATSD_UDP_SEND if the sendto() failed.
*/
This is a helper function that will do the dirty work of sending
the stats to the statsd server.
This is a helper function that will do the dirty work of sending the stats to the statsd server .
static int sendToServer(Statsd* stats, const char* bucket, StatsType type, int64_t delta, double sampleRate){
   if (sampleRate > 0 && sampleRate < 1 && (double)((double)stats->random() / RAND_MAX) >= sampleRate){
      return STATSD_SUCCESS;
   }
   char data[256];
   ssize_t dataLength = 0;
   if (!bucket){
      bucket = stats->bucket;
   }
   dataLength = buildStatString(data, sizeof(data), stats->nameSpace, bucket, type, delta, sampleRate);
   if (dataLength < 0) {
      return -1;
   }
   int sent = sendto(stats->socketFd, data, dataLength, 0, (const struct sockaddr*)&stats->destination, sizeof(struct sockaddr_in));
   if (sent == -1) {
      return STATSD_UDP_SEND;
   }
   return STATSD_SUCCESS;
}
static int sendToServer ( Statsd * stats , const char * bucket , StatsType type , int64_t delta , double sampleRate ) { if ( sampleRate > 0 && sampleRate < 1 && ( double ) ( ( double ) stats -> random ( ) / RAND_MAX ) >= sampleRate ) { return STATSD_SUCCESS ; } char data [ 256 ] ; ssize_t dataLength = 0 ; if ( ! bucket ) { bucket = stats -> bucket ; } dataLength = buildStatString ( data , sizeof ( data ) , stats -> nameSpace , bucket , type , delta , sampleRate ) ; if ( dataLength < 0 ) { return -1 ; } int sent = sendto ( stats -> socketFd , data , dataLength , 0 , ( const struct sockaddr * ) & stats -> destination , sizeof ( struct sockaddr_in ) ) ; if ( sent == -1 ) { return STATSD_UDP_SEND ; } return STATSD_SUCCESS ; }
This is a helper function that will do the dirty work of sending
the stats to the statsd server.
This is a helper function that will do the dirty work of sending the stats to the statsd server .
//See if we randomly fall under the sample rate //If the user has not specified a bucket, we will use the defualt //bucket instead. //Send the packet