primeiro
This commit is contained in:
commit
8ecead97ee
30
battery
Executable file
30
battery
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
STATUS=$(sysctl -nh hw.acpi.battery.state)
|
||||
LOAD=$(sysctl -nh hw.acpi.battery.life)
|
||||
|
||||
if [ $STATUS = 2 ]
|
||||
then
|
||||
# cargando
|
||||
echo $LOAD%
|
||||
elif [ $STATUS = 1 ]
|
||||
then
|
||||
#descargando
|
||||
if [ $LOAD -lt 6 ]
|
||||
then
|
||||
echo $LOAD%
|
||||
elif [ $LOAD -lt 26 ]
|
||||
then
|
||||
echo $LOAD%
|
||||
elif [ $LOAD -lt 56 ]
|
||||
then
|
||||
echo $LOAD%
|
||||
elif [ $LOAD -lt 81 ]
|
||||
then
|
||||
echo $LOAD%
|
||||
else
|
||||
echo $LOAD%
|
||||
fi
|
||||
else
|
||||
echo $LOAD%
|
||||
fi
|
154
cpu-usage.c
Normal file
154
cpu-usage.c
Normal file
@ -0,0 +1,154 @@
|
||||
// 181110 created
|
||||
// 200603 rewritten sh version to C to use less CPU when used in tint2 taskbar
|
||||
// - in sync with information shown in top(1)
|
||||
// - uses sysctl kern.cp_time (one statistics for all CPU cores)
|
||||
// - utilization must be calculated by hand every N time slices - TMP file used for storing old values between calculations
|
||||
// - this program is called from tint2 panel every 1 second
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h> // strtol()
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <unistd.h> // sleep()
|
||||
|
||||
#define DEBUG 0
|
||||
#define ANSI_COLOR_YELLOW "\x1b[33m"
|
||||
#define ANSI_COLOR_RESET "\x1b[0m"
|
||||
#define dprintf(fmt, ...) \
|
||||
do { if (DEBUG) printf(ANSI_COLOR_YELLOW "DBG INFO %s:%d %s(): " \
|
||||
ANSI_COLOR_RESET fmt, __FILE__, __LINE__, __func__,\
|
||||
##__VA_ARGS__); } while (0)
|
||||
|
||||
/*
|
||||
* kern.cp_time
|
||||
* Aggregated CPU state counters for
|
||||
* - user
|
||||
* - nice
|
||||
* - system
|
||||
* - interrupt
|
||||
* - idle
|
||||
* kern.cp_times - as kern.cp_time but for each core
|
||||
*
|
||||
* CPU utilization = user + nice + system + interrupt
|
||||
*/
|
||||
#define CP_USER 0
|
||||
#define CP_NICE 1
|
||||
#define CP_SYS 2
|
||||
#define CP_INTR 3
|
||||
#define CP_IDLE 4
|
||||
#define CPUSTATES 5
|
||||
#define TMP_FILE "/tmp/cpu_usage"
|
||||
|
||||
bool file_exists(void);
|
||||
void write_old(long str[]);
|
||||
void read_file(void);
|
||||
|
||||
long cur[CPUSTATES];
|
||||
long last[CPUSTATES] = {};
|
||||
|
||||
bool file_exists(void)
|
||||
{
|
||||
if (access(TMP_FILE, F_OK) != -1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void read_file(void)
|
||||
{
|
||||
dprintf("Reading previous state from file\n");
|
||||
|
||||
FILE *fp;
|
||||
fp = fopen(TMP_FILE, "r");
|
||||
|
||||
for (int state = 0; state<CPUSTATES; state++)
|
||||
{
|
||||
char c;
|
||||
char current_line[20] = {0};
|
||||
int i = 0;
|
||||
|
||||
while ((c = fgetc(fp)) != '\n')
|
||||
{
|
||||
current_line[i++] = c;
|
||||
}
|
||||
|
||||
dprintf("current line str: %s\n", current_line);
|
||||
long current_line_int = strtol(current_line, NULL, 10); // NULL - crash on fail
|
||||
dprintf("last[%d] = current_line_int(%ld str:%s)\n", state, current_line_int, current_line);
|
||||
|
||||
last[state] = current_line_int;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void write_old(long str[])
|
||||
{
|
||||
FILE *fp;
|
||||
fp = fopen(TMP_FILE, "w");
|
||||
|
||||
for (int state = 0; state<CPUSTATES; state++)
|
||||
{
|
||||
dprintf("writing to file str[%d] = %ld\n", state, str[state]);
|
||||
fprintf(fp, "%ld\n", str[state]);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
double get_cpu_utilization()
|
||||
{
|
||||
// implementation stolen from: https://stackoverflow.com/questions/5329149/using-system-calls-from-c-how-do-i-get-the-utilization-of-the-cpus
|
||||
size_t len = sizeof(cur);
|
||||
double utilization = 0.0;
|
||||
|
||||
if(sysctlbyname("kern.cp_time", &cur, &len, NULL, 0) != 0)
|
||||
{
|
||||
printf ("Error reading kern.cp_times sysctl\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (file_exists())
|
||||
{
|
||||
read_file();
|
||||
write_old(cur);
|
||||
|
||||
long sum = 0;
|
||||
for (int state = 0; state<CPUSTATES; state++)
|
||||
{
|
||||
long tmp = cur[state];
|
||||
dprintf("will write cur[4]: %ld tmp: %ld\n", cur[CP_IDLE], tmp);
|
||||
// write_old2(tmp); /// INFO radi donekle
|
||||
|
||||
cur[state] -= last[state];
|
||||
last[state] = tmp;
|
||||
sum += cur[state];
|
||||
}
|
||||
utilization = 100.0L - (100.0L * cur[CP_IDLE] / (sum ? (double) sum : 1.0L));
|
||||
dprintf("----> calculated utilisation: %.1f cur[CP_IDLE]: %ld last[CP_IDLE]: %ld\n", utilization, cur[CP_IDLE], last[CP_IDLE]);
|
||||
return utilization;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("should create new file\n");
|
||||
write_old(cur);
|
||||
return 0.0; // return 0%, will be calculated on next iteration
|
||||
}
|
||||
|
||||
return utilization;
|
||||
}
|
||||
|
||||
#ifndef NO_MAIN
|
||||
int main()
|
||||
{
|
||||
double utilization = get_cpu_utilization();
|
||||
printf("龍%.1f%%\n", utilization);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif // NO_MAIN
|
59
ram.c
Normal file
59
ram.c
Normal file
@ -0,0 +1,59 @@
|
||||
// 181227 created sh version
|
||||
// 200601 rewritten in C to use less CPU when used in tint2 taskbar
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h> // exit()
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/vmmeter.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
int64_t get_sysctl(int mib1, int mib2)
|
||||
{
|
||||
int mib[2];
|
||||
int64_t value;
|
||||
|
||||
mib[0] = mib1;
|
||||
mib[1] = mib2;
|
||||
|
||||
size_t len = sizeof(value);
|
||||
if (sysctl(mib, 2, &value, &len, NULL, 0) < 0)
|
||||
{
|
||||
printf("error, mib[%d, %d]\n", mib[0], mib[1]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int64_t phy_mem = get_sysctl(CTL_HW, HW_PHYSMEM);
|
||||
int page_size = get_sysctl(CTL_HW, HW_PAGESIZE);
|
||||
|
||||
struct vmtotal vm_info;
|
||||
int mib[2];
|
||||
mib[0] = CTL_VM;
|
||||
mib[1] = VM_TOTAL;
|
||||
size_t len = sizeof(vm_info);
|
||||
if (sysctl(mib, 2, &vm_info, &len, NULL, 0) == -1)
|
||||
{
|
||||
printf("error on line: %d\n", __LINE__);
|
||||
return(-2);
|
||||
}
|
||||
|
||||
/* uint16_t phy_mb = phy_mem/1024/1024; */
|
||||
/* uint16_t vm_free_mb = vm_info.t_free * page_size / 1024 / 1024; */
|
||||
float phy_gb = phy_mem/1024.0/1024.0/1024.0;
|
||||
float vm_free_gb = vm_info.t_free * page_size / 1024.0 / 1024.0 / 1024.0;
|
||||
/* uint8_t free_percent = (vm_free_mb * 100 / phy_mb); */
|
||||
|
||||
/* printf("RAM: %d%%\n", free_percent); */
|
||||
/* printf("%d GB\n", vm_free_mb); */
|
||||
/* printf("%d GB\n", phy_mb); */
|
||||
printf(" %.1fG/%.1fG\n", phy_gb-vm_free_gb, phy_gb);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
15
status.sh
Executable file
15
status.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/local/bin/bash
|
||||
|
||||
|
||||
while true
|
||||
do
|
||||
# WEATHER=$(/home/serxoz/bin/statusbar/weather)
|
||||
RAM=$(/home/serxoz/bin/statusbar/ram)
|
||||
CPU=$(/home/serxoz/bin/statusbar/cpu)
|
||||
TEMP=$(/home/serxoz/bin/statusbar/temperature-laptop)
|
||||
BAT=$(/home/serxoz/bin/statusbar/battery)
|
||||
DATE=$(date '+ %d/%m/%Y %H:%M%p')
|
||||
|
||||
xsetroot -name "$WEATHER $RAM $CPU $TEMP $BAT $DATE"
|
||||
sleep 2
|
||||
done
|
3
temperature-laptop
Executable file
3
temperature-laptop
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
T=$(sysctl -a | grep temperature | cut -d ' ' -f2 | cut -d 'C' -f1)
|
||||
echo $T°C
|
5
weather
Executable file
5
weather
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
# curl "https://wttr.in/Viveiro?format=3" 2>/dev/null | cut -d\: -f2 | sed 's/ / /g'
|
||||
#curl "https://wttr.in/Viveiro?format=3" 2>/dev/null | cut -d\: -f2 | sed 's/ //g'
|
||||
echo `curl 'https://wttr.in/Viveiro?format=%c%t+%m+%w' | grep -v "Unknown location" 2>/dev/null`
|
Loading…
Reference in New Issue
Block a user