@@ -627,6 +627,7 @@ impl Lambda {
627627 . try_into ( )
628628 . unwrap_or_default ( ) ;
629629
630+ // Set all tmp metrics - need tmp_max and tmp_used to calculate tmp_free
630631 if metrics. tmp_used > 0.0 {
631632 let metric = Metric :: new (
632633 constants:: TMP_USED_METRIC . into ( ) ,
@@ -637,8 +638,32 @@ impl Lambda {
637638 if let Err ( e) = aggr_handle. insert_batch ( vec ! [ metric] ) {
638639 error ! ( "Failed to insert tmp_used metric: {}" , e) ;
639640 }
641+
642+ if let Ok ( tmp_max) = statfs:: get_tmp_max ( ) {
643+ let metric = Metric :: new (
644+ constants:: TMP_MAX_METRIC . into ( ) ,
645+ MetricValue :: distribution ( tmp_max) ,
646+ tags. clone ( ) ,
647+ Some ( now) ,
648+ ) ;
649+ if let Err ( e) = aggr_handle. insert_batch ( vec ! [ metric] ) {
650+ error ! ( "Failed to insert tmp_max metric: {}" , e) ;
651+ }
652+
653+ let tmp_free = tmp_max - metrics. tmp_used ;
654+ let metric = Metric :: new (
655+ constants:: TMP_FREE_METRIC . into ( ) ,
656+ MetricValue :: distribution ( tmp_free) ,
657+ tags. clone ( ) ,
658+ Some ( now) ,
659+ ) ;
660+ if let Err ( e) = aggr_handle. insert_batch ( vec ! [ metric] ) {
661+ error ! ( "Failed to insert tmp_free metric: {}" , e) ;
662+ }
663+ }
640664 }
641665
666+ // Set file descriptor use
642667 if metrics. fd_use > 0.0 {
643668 let metric = Metric :: new (
644669 constants:: FD_USE_METRIC . into ( ) ,
@@ -651,6 +676,7 @@ impl Lambda {
651676 }
652677 }
653678
679+ // Set threads use
654680 if metrics. threads_use > 0.0 {
655681 let metric = Metric :: new (
656682 constants:: THREADS_USE_METRIC . into ( ) ,
@@ -675,8 +701,6 @@ impl Lambda {
675701 return ;
676702 }
677703
678- let tmp_max = statfs:: get_tmp_max ( ) . ok ( ) ;
679-
680704 let pids = proc:: get_pid_list ( ) ;
681705 let fd_max = proc:: get_fd_max_data ( & pids) ;
682706 let threads_max = proc:: get_threads_max_data ( & pids) ;
@@ -690,18 +714,6 @@ impl Lambda {
690714
691715 let tags = self . get_dynamic_value_tags ( ) ;
692716
693- if let Some ( tmp_max) = tmp_max {
694- let metric = Metric :: new (
695- constants:: TMP_MAX_METRIC . into ( ) ,
696- MetricValue :: distribution ( tmp_max) ,
697- tags. clone ( ) ,
698- Some ( now) ,
699- ) ;
700- if let Err ( e) = self . aggr_handle . insert_batch ( vec ! [ metric] ) {
701- error ! ( "Failed to insert tmp_max metric: {}" , e) ;
702- }
703- }
704-
705717 let metric = Metric :: new (
706718 constants:: FD_MAX_METRIC . into ( ) ,
707719 MetricValue :: distribution ( fd_max) ,
0 commit comments