* limitations under the License.
*/
+#include <stdio.h>
+
#include "procfs.h"
+#include "log.h"
+
+#define LOADAVG_FILEPATH "/proc/loadavg"
-int procfs_read_system_load_average(struct procfs_load_average_info *avg)
+int procfs_read_system_load_average(struct procfs_load_average_info *info)
{
- return -1;
+ float a1, a5, a15;
+
+ FILE *loadavg_fp = fopen(LOADAVG_FILEPATH, "r");
+ if (!loadavg_fp) {
+ ERR("failed to open " LOADAVG_FILEPATH);
+ return -1;
+ }
+
+ if (fscanf(loadavg_fp, "%f %f %f", &a1, &a5, &a15) != 3) {
+ ERR("failed to read " LOADAVG_FILEPATH);
+ fclose(loadavg_fp);
+ return -1;
+ }
+
+ info->one_min_avg = a1;
+ info->five_min_avg = a5;
+ info->fifteen_min_avg = a15;
+
+ fclose(loadavg_fp);
+
+ return 0;
}
int profcs_read_system_cpu_usage(struct procfs_system_cpu_usage_info *usage)