+ int perc = 0;
+ struct statvfs fs;
+
+ if (statvfs(mountpoint, &fs) < 0) {
+ warn("Could not get filesystem info");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ perc = 100 * (1.0f - ((float)fs.f_bfree / (float)fs.f_blocks));
+
+ return smprintf("%d%%", perc);
+}
+
+static char *
+disk_total(const char *mountpoint)
+{
+ struct statvfs fs;
+
+ if (statvfs(mountpoint, &fs) < 0) {
+ warn("Could not get filesystem info");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ return smprintf("%f", (float)fs.f_bsize * (float)fs.f_blocks / 1024 / 1024 / 1024);
+}
+
+static char *
+disk_used(const char *mountpoint)
+{
+ struct statvfs fs;
+
+ if (statvfs(mountpoint, &fs) < 0) {
+ warn("Could not get filesystem info");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ return smprintf("%f", (float)fs.f_bsize * ((float)fs.f_blocks - (float)fs.f_bfree) / 1024 / 1024 / 1024);
+}
+
+static char *
+entropy(void)
+{
+ int entropy = 0;
+ FILE *fp = fopen("/proc/sys/kernel/random/entropy_avail", "r");
+
+ if (fp == NULL) {
+ warn("Could not open entropy file");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ fscanf(fp, "%d", &entropy);
+ fclose(fp);
+
+ return smprintf("%d", entropy);
+}
+
+static char *
+gid(void)
+{
+ return smprintf("%d", getgid());
+}
+
+static char *
+hostname(void)
+{
+ char hostname[HOST_NAME_MAX];
+ FILE *fp = fopen("/proc/sys/kernel/hostname", "r");
+
+ if (fp == NULL) {
+ warn("Could not open hostname file");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ fgets(hostname, sizeof(hostname), fp);
+ /* FIXME: needs improvement */
+ memset(&hostname[strlen(hostname)-1], '\0',
+ sizeof(hostname) - strlen(hostname));
+ fclose(fp);
+
+ return smprintf("%s", hostname);
+}
+
+static char *
+ip(const char *interface)
+{
+ struct ifaddrs *ifaddr, *ifa;
+ int s;
+ char host[NI_MAXHOST];
+
+ if (getifaddrs(&ifaddr) == -1) {
+ warn("Error getting IP address");
+ return smprintf(UNKNOWN_STR);
+ }
+
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST,
+ NULL, 0, NI_NUMERICHOST);
+
+ if ((strcmp(ifa->ifa_name, interface) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
+ if (s != 0) {
+ warnx("Error getting IP address.");
+ return smprintf(UNKNOWN_STR);
+ }
+ return smprintf("%s", host);
+ }
+ }
+
+ freeifaddrs(ifaddr);
+
+ return smprintf(UNKNOWN_STR);
+}