!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/netdata/tests/profile/   drwxr-xr-x
Free 13.2 GB of 57.97 GB (22.77%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     statsd-stress.c (3.11 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <pthread.h>

void diep(char *s)
{
    perror(s);
    exit(1);
}

size_t run_threads = 1;
size_t metrics = 1024;

#define SERVER_IP "127.0.0.1"
#define PORT 8125

size_t myrand(size_t max) {
    size_t loops = max / RAND_MAX;
    size_t i;

    size_t ret = rand();
    for(i = 0; i < loops ;i++)
        ret += rand();

    return ret % max;
}

struct thread_data {
    size_t id;
    struct sockaddr_in *si_other;
    int slen;
    size_t counter;
};

static void *report_thread(void *__data) {
    struct thread_data *data = (struct thread_data *)__data;

    size_t last = 0;
    for (;;) {
        size_t i;
        size_t total = 0;
        for(i = 0; i < run_threads ;i++)
            total += data[i].counter;

        printf("%zu metrics/s\n", total-last);
        last = total;

        sleep(1);
        printf("\033[F\033[J");
    }

    return NULL;
}

char *types[] = {"g", "c", "m", "ms", "h", "s", NULL};
// char *types[] = {"g", "c", "C", "h", "ms", NULL}; // brubeck compatible

static void *spam_thread(void *__data) {
    struct thread_data *data = (struct thread_data *)__data;

    int s;
    char packet[1024];

    if ((s = socket(AF_INET, SOCK_DGRAM, 0))==-1)
        diep("socket");

    char **packets = malloc(sizeof(char *) * metrics);
    size_t i, *lengths = malloc(sizeof(size_t) * metrics);
    size_t t;

    for(i = 0, t = 0; i < metrics ;i++, t++) {
        if(!types[t]) t = 0;
        char *type = types[t];

        lengths[i] = sprintf(packet, "stress.%s.t%zu.m%zu:%zu|%s", type, data->id, i, myrand(metrics), type);
        packets[i] = strdup(packet);
        // printf("packet %zu, of length %zu: '%s'\n", i, lengths[i], packets[i]);
    }
    //printf("\n");

    for (;;) {
        for(i = 0; i < metrics ;i++) {
            if (sendto(s, packets[i], lengths[i], 0, (void *)data->si_other, data->slen) < 0) {
                printf("C ==> DROPPED\n");
                return NULL;
            }
            data->counter++;
        }
    }

    free(packets);
    free(lengths);
    close(s);
    return NULL;
}

int main(int argc, char *argv[])
{
    if (argc != 5) {
        fprintf(stderr, "Usage: '%s THREADS METRICS IP PORT'\n", argv[0]);
        exit(-1);
    }

    run_threads = atoi(argv[1]);
    metrics = atoi(argv[2]);
    char *ip = argv[3];
    int port = atoi(argv[4]);

    struct thread_data data[run_threads];
    struct sockaddr_in si_other;
    pthread_t threads[run_threads], report;
    size_t i;

    srand(time(NULL));

    memset(&si_other, 0, sizeof(si_other));
    si_other.sin_family = AF_INET;
    si_other.sin_port = htons(port);
    if (inet_aton(ip, &si_other.sin_addr)==0) {
        fprintf(stderr, "inet_aton() of ip '%s' failed\n", ip);
        exit(1);
    }

    for (i = 0; i < run_threads; ++i) {
        data[i].id       = i;
        data[i].si_other = &si_other;
        data[i].slen     = sizeof(si_other);
        data[i].counter  = 0;
        pthread_create(&threads[i], NULL, spam_thread, &data[i]);
    }

    printf("\n");
    printf("THREADS     : %zu\n", run_threads);
    printf("METRICS     : %zu\n", metrics);
    printf("DESTINATION : %s:%d\n", ip, port);
    printf("\n");
    pthread_create(&report, NULL, report_thread, &data);

    for (i =0; i < run_threads; ++i)
        pthread_join(threads[i], NULL);

    return 0;
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0055 ]--