first upload

This commit is contained in:
2025-11-20 16:05:18 +08:00
commit caffb757c8
7 changed files with 1159 additions and 0 deletions

56
status.c Executable file
View File

@@ -0,0 +1,56 @@
// /home/romkazvo/www/cgi-bin/status.c
// Отрисовка статистики
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
long get_nginx_memory() {
long total_kb = 0;
char command[] = "ps -o rss= -C nginx 2>/dev/null";
FILE *ps = popen(command, "r");
if (!ps) return 0;
char line[64];
while (fgets(line, sizeof(line), ps)) {
long kb;
if (sscanf(line, "%ld", &kb) == 1) {
total_kb += kb;
}
}
pclose(ps);
return total_kb;
}
int get_process_memory(const char *process_name, long *memory_kb) {
char command[256];
snprintf(command, sizeof(command), "ps -o rss= -C %s 2>/dev/null | head -1", process_name);
FILE *ps = popen(command, "r");
if (!ps) return 0;
int result = fscanf(ps, "%ld", memory_kb);
pclose(ps);
return result == 1;
}
int main() {
printf("Content-type: text/plain; charset=utf-8\n\n");
// Получаем память процессов
long busybox_kb = 0, nginx_kb = 0;
get_process_memory("busybox", &busybox_kb);
nginx_kb = get_nginx_memory();
// Выводим в одну строку
printf("BusyBox: %ld KB | Nginx: %ld MB | Всего: %.1f MB",
busybox_kb,
nginx_kb / 1024,
(busybox_kb + nginx_kb) / 1024.0);
return 0;
}