[{"data":1,"prerenderedAt":780},["ShallowReactive",2],{"$fDznwb49SwZpSXacgj9s2l7Snlzj4GpZWIbzct2nWu94":3},{"slug":4,"title":5,"description":6,"source":7,"document":8,"toc":767,"editUrl":774,"prev":775,"next":777},"fundamentals\u002Fhealth-checks","Health checks","Expose liveness and custom health indicators with ferrite-health.","---\ntitle: Health checks\ndescription: Expose liveness and custom health indicators with ferrite-health.\n---\n\n# Health checks\n\n`ferrite-health` gives you a `\u002Fhealth` endpoint that aggregates **indicators** — small checks your infrastructure and load balancers can probe. Indicators run in parallel, and the endpoint reports aggregate status.\n\n## Enable it\n\n```rust\n#[module(imports = [HealthModule])]\npub struct AppModule;\n```\n\n```bash\ncurl http:\u002F\u002Flocalhost:3000\u002Fhealth\n```\n\n```json\n{\n  \"status\": \"UP\",\n  \"indicators\": {\n    \"app\": { \"status\": \"UP\" }\n  }\n}\n```\n\nThe default `LivenessIndicator` reports the app as up.\n\n## Custom indicators\n\nImplement `HealthIndicator`:\n\n```rust\nuse ferrite_health::{HealthIndicator, Health, HealthResult, submit_indicator};\nuse ferrite_framework::async_trait;\n\npub struct CacheHealthIndicator {\n    pub key: String,\n}\n\n#[async_trait]\nimpl HealthIndicator for CacheHealthIndicator {\n    fn name(&self) -> &'static str {\n        \"cache\"\n    }\n\n    async fn check(&self) -> HealthResult {\n        match self.client.ping().await {\n            Ok(_) => Health::up().finish(),\n            Err(err) => Health::down()\n                .with_details(serde_json::json!({ \"error\": err.to_string() }))\n                .finish(),\n        }\n    }\n}\n```\n\nRegister it with `submit_indicator!` (the type must be `Default`):\n\n```rust\nsubmit_indicator!(CacheHealthIndicator);\n```\n\nThe aggregate body nests each indicator under its `name`:\n\n```json\n{\n  \"status\": \"DOWN\",\n  \"indicators\": {\n    \"app\": { \"status\": \"UP\" },\n    \"cache\": { \"status\": \"DOWN\", \"details\": { \"error\": \"connection refused\" } }\n  }\n}\n```\n\n## The `Health` builder\n\n```rust\nHealth::up().finish();            \u002F\u002F HealthResult { UP, details: null }\nHealth::down().with_details(json).finish();\nHealth::out_of_service().finish();\nHealth::unknown().finish();\n```\n\nStatuses serialize as `\"UP\"`, `\"DOWN\"`, `\"OUT_OF_SERVICE\"`, `\"UNKNOWN\"`.\n\n## Behavior\n\n- Indicators run **in parallel** (`join_all`), so slow checks don't serialize.\n- The aggregate is `DOWN` if any indicator is down.\n- `HealthService` is an `#[injectable]`; inject it if you need to report health from tests or dashboards.\n\n## Next steps\n\n- [OpenAPI & Swagger](\u002Fdocs\u002Ffundamentals\u002Fopenapi-swagger).\n- [Testing](\u002Fdocs\u002Ffundamentals\u002Ftesting).",{"frontmatter":9,"meta":10,"nodes":31},{"title":5,"description":6},{"toc":11},{"title":12,"searchDepth":13,"depth":14,"links":15},"On This Page",2,3,[16,19,22,25,28],{"id":17,"depth":13,"text":18},"enable-it","Enable it",{"id":20,"depth":13,"text":21},"custom-indicators","Custom indicators",{"id":23,"depth":13,"text":24},"the-health-builder","The Health builder",{"id":26,"depth":13,"text":27},"behavior","Behavior",{"id":29,"depth":13,"text":30},"next-steps","Next steps",[32,36,53,56,102,117,179,186,188,195,503,514,530,536,614,620,703,716,718,750,752],[33,34,5],"h1",{"id":35},"health-checks",[37,38,39,43,44,47,48,52],"p",{},[40,41,42],"code",{},"ferrite-health"," gives you a ",[40,45,46],{},"\u002Fhealth"," endpoint that aggregates ",[49,50,51],"strong",{},"indicators"," — small checks your infrastructure and load balancers can probe. Indicators run in parallel, and the endpoint reports aggregate status.",[54,55,18],"h2",{"id":17},[57,58,61],"pre",{"language":59,"class":60},"rust","shiki shiki-themes github-light github-dark dark:github-dark",[40,62,64,87,88],{"class":63},"language-rust",[65,66,69,73,77,80,84],"span",{"class":67,"style":68},"line","display: inline",[65,70,72],{"style":71},"color:#24292E;--shiki-dark:#E1E4E8","#[module(imports ",[65,74,76],{"style":75},"color:#D73A49;--shiki-dark:#F97583","=",[65,78,79],{"style":71}," [",[65,81,83],{"style":82},"color:#6F42C1;--shiki-dark:#B392F0","HealthModule",[65,85,86],{"style":71},"])]","\n",[65,89,90,93,96,99],{"class":67,"style":68},[65,91,92],{"style":75},"pub",[65,94,95],{"style":75}," struct",[65,97,98],{"style":82}," AppModule",[65,100,101],{"style":71},";",[57,103,105],{"language":104,"class":60},"bash",[40,106,108],{"class":107},"language-bash",[65,109,110,113],{"class":67,"style":68},[65,111,112],{"style":82},"curl",[65,114,116],{"style":115},"color:#032F62;--shiki-dark:#9ECBFF"," http:\u002F\u002Flocalhost:3000\u002Fhealth",[57,118,120],{"language":119,"class":60},"json",[40,121,123,87,128,87,143,87,151,87,169,87,174],{"class":122},"language-json",[65,124,125],{"class":67,"style":68},[65,126,127],{"style":71},"{",[65,129,130,134,137,140],{"class":67,"style":68},[65,131,133],{"style":132},"color:#005CC5;--shiki-dark:#79B8FF","  \"status\"",[65,135,136],{"style":71},": ",[65,138,139],{"style":115},"\"UP\"",[65,141,142],{"style":71},",",[65,144,145,148],{"class":67,"style":68},[65,146,147],{"style":132},"  \"indicators\"",[65,149,150],{"style":71},": {",[65,152,153,156,159,162,164,166],{"class":67,"style":68},[65,154,155],{"style":132},"    \"app\"",[65,157,158],{"style":71},": { ",[65,160,161],{"style":132},"\"status\"",[65,163,136],{"style":71},[65,165,139],{"style":115},[65,167,168],{"style":71}," }",[65,170,171],{"class":67,"style":68},[65,172,173],{"style":71},"  }",[65,175,176],{"class":67,"style":68},[65,177,178],{"style":71},"}",[37,180,181,182,185],{},"The default ",[40,183,184],{},"LivenessIndicator"," reports the app as up.",[54,187,21],{"id":20},[37,189,190,191,194],{},"Implement ",[40,192,193],{},"HealthIndicator",":",[57,196,197],{"language":59,"class":60},[40,198,199,87,228,87,240,87,242,87,254,87,269,87,273,87,275,87,280,87,295,87,332,87,337,87,342,87,344,87,370,87,397,87,426,87,445,87,482,87,490,87,495,87,499],{"class":63},[65,200,201,204,207,210,212,214,217,220,222,225],{"class":67,"style":68},[65,202,203],{"style":75},"use",[65,205,206],{"style":82}," ferrite_health",[65,208,209],{"style":75},"::",[65,211,127],{"style":71},[65,213,193],{"style":82},[65,215,216],{"style":71},", ",[65,218,219],{"style":82},"Health",[65,221,216],{"style":71},[65,223,224],{"style":82},"HealthResult",[65,226,227],{"style":71},", submit_indicator};",[65,229,230,232,235,237],{"class":67,"style":68},[65,231,203],{"style":75},[65,233,234],{"style":82}," ferrite_framework",[65,236,209],{"style":75},[65,238,239],{"style":71},"async_trait;",[65,241],{"class":67,"style":68},[65,243,244,246,248,251],{"class":67,"style":68},[65,245,92],{"style":75},[65,247,95],{"style":75},[65,249,250],{"style":82}," CacheHealthIndicator",[65,252,253],{"style":71}," {",[65,255,256,259,262,264,267],{"class":67,"style":68},[65,257,258],{"style":75},"    pub",[65,260,261],{"style":71}," key",[65,263,194],{"style":75},[65,265,266],{"style":82}," String",[65,268,142],{"style":71},[65,270,271],{"class":67,"style":68},[65,272,178],{"style":71},[65,274],{"class":67,"style":68},[65,276,277],{"class":67,"style":68},[65,278,279],{"style":71},"#[async_trait]",[65,281,282,285,288,291,293],{"class":67,"style":68},[65,283,284],{"style":75},"impl",[65,286,287],{"style":82}," HealthIndicator",[65,289,290],{"style":75}," for",[65,292,250],{"style":82},[65,294,253],{"style":71},[65,296,297,300,303,306,309,312,315,318,321,324,327,330],{"class":67,"style":68},[65,298,299],{"style":75},"    fn",[65,301,302],{"style":82}," name",[65,304,305],{"style":71},"(",[65,307,308],{"style":75},"&",[65,310,311],{"style":132},"self",[65,313,314],{"style":71},") ",[65,316,317],{"style":75},"->",[65,319,320],{"style":75}," &",[65,322,323],{"style":71},"'",[65,325,326],{"style":82},"static",[65,328,329],{"style":82}," str",[65,331,253],{"style":71},[65,333,334],{"class":67,"style":68},[65,335,336],{"style":115},"        \"cache\"",[65,338,339],{"class":67,"style":68},[65,340,341],{"style":71},"    }",[65,343],{"class":67,"style":68},[65,345,346,349,352,355,357,359,361,363,365,368],{"class":67,"style":68},[65,347,348],{"style":75},"    async",[65,350,351],{"style":75}," fn",[65,353,354],{"style":82}," check",[65,356,305],{"style":71},[65,358,308],{"style":75},[65,360,311],{"style":132},[65,362,314],{"style":71},[65,364,317],{"style":75},[65,366,367],{"style":82}," HealthResult",[65,369,253],{"style":71},[65,371,372,375,378,381,384,386,389,392,395],{"class":67,"style":68},[65,373,374],{"style":75},"        match",[65,376,377],{"style":132}," self",[65,379,380],{"style":75},".",[65,382,383],{"style":71},"client",[65,385,380],{"style":75},[65,387,388],{"style":82},"ping",[65,390,391],{"style":71},"()",[65,393,394],{"style":75},".await",[65,396,253],{"style":71},[65,398,399,402,405,408,411,413,416,418,420,423],{"class":67,"style":68},[65,400,401],{"style":82},"            Ok",[65,403,404],{"style":71},"(_) ",[65,406,407],{"style":75},"=>",[65,409,410],{"style":82}," Health",[65,412,209],{"style":75},[65,414,415],{"style":82},"up",[65,417,391],{"style":71},[65,419,380],{"style":75},[65,421,422],{"style":82},"finish",[65,424,425],{"style":71},"(),",[65,427,428,431,434,436,438,440,443],{"class":67,"style":68},[65,429,430],{"style":82},"            Err",[65,432,433],{"style":71},"(err) ",[65,435,407],{"style":75},[65,437,410],{"style":82},[65,439,209],{"style":75},[65,441,442],{"style":82},"down",[65,444,391],{"style":71},[65,446,447,450,453,455,458,460,463,466,469,471,474,476,479],{"class":67,"style":68},[65,448,449],{"style":75},"                .",[65,451,452],{"style":82},"with_details",[65,454,305],{"style":71},[65,456,457],{"style":82},"serde_json",[65,459,209],{"style":75},[65,461,462],{"style":82},"json!",[65,464,465],{"style":71},"({ ",[65,467,468],{"style":115},"\"error\"",[65,470,194],{"style":75},[65,472,473],{"style":71}," err",[65,475,380],{"style":75},[65,477,478],{"style":82},"to_string",[65,480,481],{"style":71},"() }))",[65,483,484,486,488],{"class":67,"style":68},[65,485,449],{"style":75},[65,487,422],{"style":82},[65,489,425],{"style":71},[65,491,492],{"class":67,"style":68},[65,493,494],{"style":71},"        }",[65,496,497],{"class":67,"style":68},[65,498,341],{"style":71},[65,500,501],{"class":67,"style":68},[65,502,178],{"style":71},[37,504,505,506,509,510,513],{},"Register it with ",[40,507,508],{},"submit_indicator!"," (the type must be ",[40,511,512],{},"Default","):",[57,515,516],{"language":59,"class":60},[40,517,518],{"class":63},[65,519,520,522,524,527],{"class":67,"style":68},[65,521,508],{"style":82},[65,523,305],{"style":71},[65,525,526],{"style":82},"CacheHealthIndicator",[65,528,529],{"style":71},");",[37,531,532,533,194],{},"The aggregate body nests each indicator under its ",[40,534,535],{},"name",[57,537,538],{"language":119,"class":60},[40,539,540,87,544,87,555,87,561,87,576,87,606,87,610],{"class":122},[65,541,542],{"class":67,"style":68},[65,543,127],{"style":71},[65,545,546,548,550,553],{"class":67,"style":68},[65,547,133],{"style":132},[65,549,136],{"style":71},[65,551,552],{"style":115},"\"DOWN\"",[65,554,142],{"style":71},[65,556,557,559],{"class":67,"style":68},[65,558,147],{"style":132},[65,560,150],{"style":71},[65,562,563,565,567,569,571,573],{"class":67,"style":68},[65,564,155],{"style":132},[65,566,158],{"style":71},[65,568,161],{"style":132},[65,570,136],{"style":71},[65,572,139],{"style":115},[65,574,575],{"style":71}," },",[65,577,578,581,583,585,587,589,591,594,596,598,600,603],{"class":67,"style":68},[65,579,580],{"style":132},"    \"cache\"",[65,582,158],{"style":71},[65,584,161],{"style":132},[65,586,136],{"style":71},[65,588,552],{"style":115},[65,590,216],{"style":71},[65,592,593],{"style":132},"\"details\"",[65,595,158],{"style":71},[65,597,468],{"style":132},[65,599,136],{"style":71},[65,601,602],{"style":115},"\"connection refused\"",[65,604,605],{"style":71}," } }",[65,607,608],{"class":67,"style":68},[65,609,173],{"style":71},[65,611,612],{"class":67,"style":68},[65,613,178],{"style":71},[54,615,616,617,619],{"id":23},"The ",[40,618,219],{}," builder",[57,621,622],{"language":59,"class":60},[40,623,624,87,645,87,669,87,686],{"class":63},[65,625,626,628,630,632,634,636,638,641],{"class":67,"style":68},[65,627,219],{"style":82},[65,629,209],{"style":75},[65,631,415],{"style":82},[65,633,391],{"style":71},[65,635,380],{"style":75},[65,637,422],{"style":82},[65,639,640],{"style":71},"();            ",[65,642,644],{"style":643},"color:#6A737D;--shiki-dark:#6A737D","\u002F\u002F HealthResult { UP, details: null }",[65,646,647,649,651,653,655,657,659,662,664,666],{"class":67,"style":68},[65,648,219],{"style":82},[65,650,209],{"style":75},[65,652,442],{"style":82},[65,654,391],{"style":71},[65,656,380],{"style":75},[65,658,452],{"style":82},[65,660,661],{"style":71},"(json)",[65,663,380],{"style":75},[65,665,422],{"style":82},[65,667,668],{"style":71},"();",[65,670,671,673,675,678,680,682,684],{"class":67,"style":68},[65,672,219],{"style":82},[65,674,209],{"style":75},[65,676,677],{"style":82},"out_of_service",[65,679,391],{"style":71},[65,681,380],{"style":75},[65,683,422],{"style":82},[65,685,668],{"style":71},[65,687,688,690,692,695,697,699,701],{"class":67,"style":68},[65,689,219],{"style":82},[65,691,209],{"style":75},[65,693,694],{"style":82},"unknown",[65,696,391],{"style":71},[65,698,380],{"style":75},[65,700,422],{"style":82},[65,702,668],{"style":71},[37,704,705,706,216,708,216,710,216,713,380],{},"Statuses serialize as ",[40,707,139],{},[40,709,552],{},[40,711,712],{},"\"OUT_OF_SERVICE\"",[40,714,715],{},"\"UNKNOWN\"",[54,717,27],{"id":26},[719,720,721,733,740],"ul",{},[722,723,724,725,728,729,732],"li",{},"Indicators run ",[49,726,727],{},"in parallel"," (",[40,730,731],{},"join_all","), so slow checks don't serialize.",[722,734,735,736,739],{},"The aggregate is ",[40,737,738],{},"DOWN"," if any indicator is down.",[722,741,742,745,746,749],{},[40,743,744],{},"HealthService"," is an ",[40,747,748],{},"#[injectable]","; inject it if you need to report health from tests or dashboards.",[54,751,30],{"id":29},[719,753,754,761],{},[722,755,756,380],{},[757,758,760],"a",{"href":759},"\u002Fdocs\u002Ffundamentals\u002Fopenapi-swagger","OpenAPI & Swagger",[722,762,763,380],{},[757,764,766],{"href":765},"\u002Fdocs\u002Ffundamentals\u002Ftesting","Testing",{"title":12,"searchDepth":13,"depth":14,"links":768},[769,770,771,772,773],{"id":17,"depth":13,"text":18},{"id":20,"depth":13,"text":21},{"id":23,"depth":13,"text":24},{"id":26,"depth":13,"text":27},{"id":29,"depth":13,"text":30},"https:\u002F\u002Fgithub.com\u002Fj4flmao\u002Fferrite_rs\u002Fedit\u002Fmain\u002Fdocs\u002Fcontent\u002Ffundamentals\u002Fhealth-checks.md",{"title":760,"slug":776},"fundamentals\u002Fopenapi-swagger",{"title":778,"slug":779},"Database (ORM)","techniques\u002Fdatabase",1789565440220]